From 331847573ca52730888975443cfc0a256abb66a8 Mon Sep 17 00:00:00 2001 From: Anthony Howe Date: Sun, 10 Nov 2024 16:26:20 -0500 Subject: [PATCH] GH-66 Fix `( ccc)` and `.( ccc)`; add `\( ccc)` and `.\( ccc)`. --- doc/standard.md | 13 +++++++++-- src/post4.p4 | 59 +++++++++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/doc/standard.md b/doc/standard.md index 15ab037..907c022 100644 --- a/doc/standard.md +++ b/doc/standard.md @@ -33,7 +33,11 @@ Find `name` and place its execution token on the stack. Throw undefined word (- - - - #### ( ccc) ( `ccc` -- ) immediate -Parse and ignore characters up to the closing right parenthesis, which an empty string or span multiple lines. Note as an extension a literal right parenthesis, `)`, can be expressed as a backslash literal `\)`, likewise backslash as `\\`. +Parse and ignore characters up to the closing right parenthesis, which an empty string or span multiple lines. +- - - +#### \\( ccc) +( `ccc` -- ) immediate +Parse and ignore characters up to the closing right parenthesis, which an empty string or span multiple lines. Note a backslash followed by any other character escapes that character, ie. `\\` is a literal backslash, `\)` is a literal closing parenthesis. - - - #### \* @@ -115,7 +119,12 @@ Display `ccc`. - - - #### .( ccc) ( `ccc` -- ) immediate -Parse and display text until an unescaped closing parenthesis. Backslash followed by any other character escapes that character, ie. `\\` is a literal backslash, `\)` is a literal closing parenthesis. +Parse and display text until an unescaped closing parenthesis. + +- - - +#### .\\( ccc) +( `ccc` -- ) immediate +Parse and display text until an unescaped closing parenthesis. Note a backslash followed by any other character escapes that character, ie. `\\` is a literal backslash, `\)` is a literal closing parenthesis. - - - #### / diff --git a/src/post4.p4 b/src/post4.p4 index e36aae5..143e347 100644 --- a/src/post4.p4 +++ b/src/post4.p4 @@ -1012,27 +1012,45 @@ DEFER fsp! THEN ; IMMEDIATE $10 _pp! +\ (S: -- ) +: >in+ 1 >IN +! ; + \ ( -- caddr u ) : source-remaining SOURCE >IN @ /STRING ; $02 _pp! -\ ( delim -- bool ) +\ ( delim escape -- delim escape bool ) \ \ Scan the input buffer character at a time until either the input \ is exhusted, returning true; or an input character matches delim, \ returning false. \ : parse-more + >R BEGIN \ S: delim source-remaining 0= IF \ S: delim caddr - 2DROP TRUE EXIT \ empty input buffer + DROP R> TRUE EXIT \ empty input buffer THEN 1 >IN +! \ S: delim caddr - C@ OVER = IF \ S: delim - DROP FALSE EXIT \ input char matches delim + DUP C@ R@ = IF \ escape next char? + DROP 1 >IN +! \ S: delim ch + ELSE + C@ OVER = IF \ S: delim + R> FALSE EXIT \ input char matches delim + THEN THEN AGAIN ; +\ (S: delim escape xt -- ) +: parse-multiline + >R BEGIN + R@ EXECUTE \ find delim in input buffer + WHILE \ found delim yet? + REFILL \ read more input + whilst THEN \ EOF yet? + rdrop 2DROP +; + \ ... ( comment) ... \ \ (S: ccc -- ) @@ -1045,15 +1063,9 @@ DEFER fsp! \ def 456 \ ) \ -: ( - [CHAR] ) - BEGIN - DUP parse-more \ find delim in input buffer - WHILE \ found delim yet? - REFILL 0= \ read more input; EOF yet? - UNTIL THEN - DROP -; IMMEDIATE +: ( [CHAR] ) -1 ['] parse-more parse-multiline ; IMMEDIATE + +: \( [CHAR] ) [CHAR] \ ['] parse-more parse-multiline ; IMMEDIATE \ ... SPACES ... \ @@ -1324,23 +1336,24 @@ VARIABLE _>pic \ (S: d# w -- ) : D.R >R TUCK DABS <# #S ROT SIGN #> R> OVER - SPACES TYPE ; -\ ( delim -- bool ) +\ ( delim escape -- delim escape bool ) \ \ Scan the input buffer character at a time until either the input \ is exhusted, returning true; or an input character matches delim, \ returning false. \ : emit-more + >R BEGIN \ S: delim source-remaining 0= IF \ S: delim caddr - 2DROP TRUE EXIT \ empty input buffer + DROP R> TRUE EXIT \ empty input buffer THEN 1 >IN +! \ S: delim caddr - DUP C@ [CHAR] \ = IF \ escape next char? + DUP C@ R@ = IF \ escape next char? 1 >IN +! CHAR+ C@ \ S: delim ch ELSE C@ 2DUP = IF \ S: delim ch - 2DROP FALSE EXIT \ input char matches delim + DROP R> FALSE EXIT \ input char matches delim THEN THEN EMIT \ S: delim @@ -1351,15 +1364,9 @@ VARIABLE _>pic \ .( ccc) \ \ (S: ccc -- ) -: .( - [CHAR] ) - BEGIN - DUP emit-more \ find delim in input buffer - WHILE \ found delim yet? - REFILL 0= \ read more input; EOF yet? - UNTIL THEN - DROP -; IMMEDIATE +: .( [CHAR] ) -1 ['] emit-more parse-multiline ; IMMEDIATE + +: .\( [CHAR] ) [CHAR] \ ['] emit-more parse-multiline ; IMMEDIATE \ ... ? ... \