mirror of
https://github.com/nineties/planckforth
synced 2024-12-25 21:58:22 +01:00
Support escaped character in '..'
This commit is contained in:
parent
f0cc87b375
commit
d0bc652c5d
2 changed files with 25 additions and 18 deletions
40
bootstrap.fs
40
bootstrap.fs
|
@ -1165,6 +1165,23 @@ decimal \ set default to decimal
|
|||
then
|
||||
;
|
||||
|
||||
\ Return ascii-code of corresponding escaped char
|
||||
\ e.g '\n' escaped-char -> 10
|
||||
: escaped-char ( n -- n )
|
||||
case
|
||||
'0' of 0 endof
|
||||
'a' of 7 endof
|
||||
'b' of 8 endof
|
||||
't' of 9 endof
|
||||
'n' of 10 endof
|
||||
'v' of 11 endof
|
||||
'f' of 12 endof
|
||||
'r' of 13 endof
|
||||
'\\' of '\\' endof
|
||||
drop -1
|
||||
endcase
|
||||
;
|
||||
|
||||
\ Parse string as number.
|
||||
\ This function interprets prefixes that specifies number base.
|
||||
: >number ( c-addr -- n f )
|
||||
|
@ -1205,7 +1222,11 @@ decimal \ set default to decimal
|
|||
dup c@ unless
|
||||
drop 0 false exit
|
||||
then
|
||||
dup c@ swap 1+
|
||||
dup c@ '\\' = if
|
||||
1+ dup c@ escaped-char swap 1+
|
||||
else
|
||||
dup c@ swap 1+
|
||||
then
|
||||
c@ case
|
||||
0 of true exit endof
|
||||
'\'' of true exit endof
|
||||
|
@ -1315,23 +1336,6 @@ create s-buffer s-buffer-size allot
|
|||
\ because we can't write string literal yet.
|
||||
char 0 char B - constant STRING-OVERFLOW-ERROR \ -18
|
||||
|
||||
\ Return ascii-code of corresponding escaped char
|
||||
\ e.g '\n' escaped-char -> 10
|
||||
: escaped-char ( n -- n )
|
||||
case
|
||||
'0' of 0 endof
|
||||
'a' of 7 endof
|
||||
'b' of 8 endof
|
||||
't' of 9 endof
|
||||
'n' of 10 endof
|
||||
'v' of 11 endof
|
||||
'f' of 12 endof
|
||||
'r' of 13 endof
|
||||
'\\' of '\\' endof
|
||||
drop -1
|
||||
endcase
|
||||
;
|
||||
|
||||
\ Parse string delimited by "
|
||||
\ compile mode: the string is stored as operand of 'string' operator.
|
||||
\ immediate mode: the string is stored to temporary buffer.
|
||||
|
|
|
@ -611,6 +611,9 @@ testing char [char] [ ] bl s"
|
|||
T{ bl -> 20 }T
|
||||
T{ char X -> 58 }T
|
||||
T{ char HELLO -> 48 }T
|
||||
T{ '\n' -> 0xa }T
|
||||
T{ '\0' -> 0 }T
|
||||
T{ 'a' -> 61 }T
|
||||
T{ : gc1 [char] X ; -> }T
|
||||
T{ : gc2 [char] HELLO ; -> }T
|
||||
T{ gc1 -> 58 }T
|
||||
|
|
Loading…
Reference in a new issue