version 1.1, 2002/04/27 14:52:30
|
version 1.2, 2002/04/30 20:12:36
|
Line 39 char o c, char p c, char q c, 13
|
Line 39 char o c, char p c, char q c, 13
|
: \-escape ( c-addr1 -- c-addr2 c ) |
: \-escape ( c-addr1 -- c-addr2 c ) |
\ c-addr1 points at a char right after a '\', c-addr2 points right |
\ c-addr1 points at a char right after a '\', c-addr2 points right |
\ after the whole sequence, c is the translated char |
\ after the whole sequence, c is the translated char |
dup c@ dup [char] x = if |
dup c@ |
|
dup [char] x = if |
drop char+ 16 parse-num exit |
drop char+ 16 parse-num exit |
endif |
endif |
dup [char] 0 [char] 8 within if |
dup [char] 0 [char] 8 within if |
drop 8 parse-num exit |
drop 8 parse-num exit |
endif |
endif |
dup [char] a [char] w within if |
dup [char] n = if |
[char] a - chars \-escape-table + c@ |
\ \-escapes were designed to translate to one character, so |
|
\ this is quite ugly: copy all but the last char right away |
|
drop newline 1- |
|
2dup here swap chars dup allot move |
|
chars + c@ |
|
else |
|
dup [char] a [char] w within if |
|
[char] a - chars \-escape-table + c@ |
|
endif |
endif |
endif |
1 chars under+ ; |
1 chars under+ ; |
|
|
Line 54 char o c, char p c, char q c, 13
|
Line 63 char o c, char p c, char q c, 13
|
\G parses string, translating @code{\}-escapes to characters (as in |
\G parses string, translating @code{\}-escapes to characters (as in |
\G C). The resulting string resides at @code{here char+}. The |
\G C). The resulting string resides at @code{here char+}. The |
\G supported @code{\-escapes} are: @code{\a} BEL (alert), @code{\b} |
\G supported @code{\-escapes} are: @code{\a} BEL (alert), @code{\b} |
\G BS, @code{\e} ESC (not in C99), @code{\f} FF, @code{\n} LF (or |
\G BS, @code{\e} ESC (not in C99), @code{\f} FF, @code{\n} newline, |
\G newline?), @code{\r} CR, @code{\t} HT, @code{\v} VT, @code{\"} ", |
\G @code{\r} CR, @code{\t} HT, @code{\v} VT, @code{\"} ", |
\G @code{\}[0-7]+ octal numerical character value, @code{\x}[0-9a-f]+ |
\G @code{\}[0-7]+ octal numerical character value, @code{\x}[0-9a-f]+ |
\G hex numerical character value; a @code{\} before any other |
\G hex numerical character value; a @code{\} before any other |
\G character represents that character (only ', \, ? in C99). |
\G character represents that character (only ', \, ? in C99). |
Line 85 interpret/compile: s\" ( compilation 'cc
|
Line 94 interpret/compile: s\" ( compilation 'cc
|
:noname postpone (.") \"-parse dup c, 1+ chars allot drop ; |
:noname postpone (.") \"-parse dup c, 1+ chars allot drop ; |
interpret/compile: .\" ( compilation 'ccc"' -- ; run-time -- ) \ gforth dot-backslash-quote |
interpret/compile: .\" ( compilation 'ccc"' -- ; run-time -- ) \ gforth dot-backslash-quote |
|
|
0 [if] \ test |
1 [if] \ test |
s" 123" drop 10 parse-num-x 123 <> throw drop .s |
s" 123" drop 10 parse-num-x 123 <> throw drop .s |
s" 123a" drop 10 parse-num 123 <> throw drop .s |
s" 123a" drop 10 parse-num 123 <> throw drop .s |
s" x1fg" drop \-escape 31 <> throw drop .s |
s" x1fg" drop \-escape 31 <> throw drop .s |
Line 93 interpret/compile: .\" ( compilation 'cc
|
Line 102 interpret/compile: .\" ( compilation 'cc
|
s" a" drop \-escape 7 <> throw drop .s |
s" a" drop \-escape 7 <> throw drop .s |
\"-parse " s" " compare 0<> throw .s |
\"-parse " s" " compare 0<> throw .s |
\"-parse \a\b\c\e\f\n\r\t\v\100\x40xabcde" dump |
\"-parse \a\b\c\e\f\n\r\t\v\100\x40xabcde" dump |
s\" \a\bcd\e\fghijklm\nopq\rs\tu\v" \-escape-table over compare 0<> throw |
s\" \a\bcd\e\fghijklm\12opq\rs\tu\v" \-escape-table over compare 0<> throw |
s\" \0101\x041\"\\" name AA"\ compare 0<> throw |
s\" \w\0101\x041\"\\" name wAA"\ compare 0<> throw |
s\" s\\\" \\" ' evaluate catch 0= throw |
s\" s\\\" \\" ' evaluate catch 0= throw |
[endif] |
[endif] |