Skip to content

Commit

Permalink
GH-66 Fix ( ccc) and .( ccc); add \( ccc) and .\( ccc).
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Nov 10, 2024
1 parent 8d3ae2d commit 3318475
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
13 changes: 11 additions & 2 deletions doc/standard.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ Find `name` and place its execution token on the stack. Throw undefined word (-
- - -
#### ( ccc)
( `ccc<paren>` -- ) 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<paren>` -- ) 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.

- - -
#### \*
Expand Down Expand Up @@ -115,7 +119,12 @@ Display `ccc`.
- - -
#### .( ccc)
( `ccc<paren>` -- ) 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<paren>` -- ) 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.

- - -
#### /
Expand Down
59 changes: 33 additions & 26 deletions src/post4.p4
Original file line number Diff line number Diff line change
Expand Up @@ -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<paren> -- )
Expand All @@ -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 ...
\
Expand Down Expand Up @@ -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
Expand All @@ -1351,15 +1364,9 @@ VARIABLE _>pic
\ .( ccc)
\
\ (S: ccc<paren> -- )
: .(
[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

\ ... ? ...
\
Expand Down

0 comments on commit 3318475

Please sign in to comment.