mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-06-08 21:29:30 +00:00
Fixed bug in string escape parsing & added escape sequences
This commit is contained in:
parent
ff70ba739a
commit
0082eb3096
15
doc/c02.txt
15
doc/c02.txt
|
@ -173,7 +173,20 @@ A string is a consecutive series of characters terminated by an ASCII null
|
|||
character (a byte with the value 0).
|
||||
|
||||
A string literal is written as up to 255 printable characters. prefixed and
|
||||
suffixed with " characters.
|
||||
suffixed with " characters.
|
||||
|
||||
The " character and a subset of ASCII control characters can be specified
|
||||
in a string literal by using escape sequences prefixed with the \ symbol:
|
||||
|
||||
\b $08 Backspace
|
||||
\e $08 Escape
|
||||
\f $0C Form Feed
|
||||
\n $0A Line Feed
|
||||
\r $0D Carriage Return
|
||||
\t $09 Tab
|
||||
\v $0B Vertical Tab
|
||||
\" $22 Double Quotation Mark
|
||||
\\ $5C Backslash
|
||||
|
||||
SYMBOLS
|
||||
|
||||
|
|
11
src/parse.c
11
src/parse.c
|
@ -139,7 +139,14 @@ void getwrd(void) {
|
|||
char escape(char c) {
|
||||
DEBUG("Escaping character '%c'\n", c)
|
||||
switch (c) {
|
||||
case 'r': return 0x0d;
|
||||
case 'a': return 0x07; //Alert (Beep/Bell)
|
||||
case 'b': return 0x08; //Backspace
|
||||
case 'e': return 0x08; //Escape
|
||||
case 'f': return 0x0C; //Form Feed
|
||||
case 'n': return 0x0A; //Newline (Line Feed)
|
||||
case 'r': return 0x0D; //Return (Carriage Return)
|
||||
case 't': return 0x09; //Tab (Horizontal)
|
||||
case 'v': return 0x0B; //Vertical Tab
|
||||
default: return c;
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +158,7 @@ void getstr(void) {
|
|||
DEBUG("Parsing string\n", 0)
|
||||
strdel = getnxt(); //Get String Delimiter
|
||||
CCMNT(strdel);
|
||||
while(match(strdel) == escnxt) {
|
||||
while(!match(strdel) || escnxt) {
|
||||
CCMNT(nxtchr);
|
||||
if (escnxt) {
|
||||
word[wrdlen++] = escape(getnxt());
|
||||
|
|
Loading…
Reference in New Issue
Block a user