| variable endrawinput \ pointer to the end of the input (the char after the last) |
variable endrawinput \ pointer to the end of the input (the char after the last) |
| variable cookedinput \ pointer to the next char to be parsed |
variable cookedinput \ pointer to the next char to be parsed |
| variable line \ line number of char pointed to by input |
variable line \ line number of char pointed to by input |
| 1 line ! |
variable line-start \ pointer to start of current line (for error messages) |
| |
0 line ! |
| 2variable filename \ filename of original input file |
2variable filename \ filename of original input file |
| 0 0 filename 2! |
0 0 filename 2! |
| 2variable f-comment |
2variable f-comment |
| endif |
endif |
| drop ; |
drop ; |
| |
|
| |
: print-error-line ( -- ) |
| |
\ print the current line and position |
| |
line-start @ endrawinput @ over - 2dup nl-char scan drop nip ( start end ) |
| |
over - type cr |
| |
line-start @ rawinput @ over - typewhite ." ^" cr ; |
| |
|
| : ?nextchar ( f -- ) |
: ?nextchar ( f -- ) |
| ?not? if |
?not? if |
| |
outfile-id >r try |
| |
stderr to outfile-id |
| filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:" |
filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:" |
| getinput . cr |
getinput . cr |
| rawinput @ endrawinput @ over - 100 min type cr |
print-error-line |
| |
0 |
| |
recover endtry |
| |
r> to outfile-id throw |
| abort |
abort |
| endif |
endif |
| rawinput @ endrawinput @ <> if |
rawinput @ endrawinput @ <> if |
| 1 chars cookedinput +! |
1 chars cookedinput +! |
| nl-char = if |
nl-char = if |
| checksyncline |
checksyncline |
| |
rawinput @ line-start ! |
| endif |
endif |
| rawinput @ c@ cookedinput @ c! |
rawinput @ c@ cookedinput @ c! |
| endif ; |
endif ; |
| : primfilter ( file-id xt -- ) |
: primfilter ( file-id xt -- ) |
| \ fileid is for the input file, xt ( -- ) is for the output word |
\ fileid is for the input file, xt ( -- ) is for the output word |
| output ! |
output ! |
| here dup rawinput ! cookedinput ! |
here dup rawinput ! dup line-start ! cookedinput ! |
| here unused rot read-file throw |
here unused rot read-file throw |
| dup here + endrawinput ! |
dup here + endrawinput ! |
| allot |
allot |