mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-22 07:20:05 +00:00
added special character support to strings
This commit is contained in:
parent
0745fd10a9
commit
9ccb258a93
26
src/clex.c
26
src/clex.c
@ -191,10 +191,28 @@ void skipWhitespace(CLexState *state) {
|
||||
CToken parseString(CLexState *state) {
|
||||
makeBuffer(state); // buffer mode
|
||||
while (peek(state) != '"' && !isEnd(state)) {
|
||||
if (peek(state) == '\n') // strings can't stretch across lines
|
||||
return makeError(state, "Unterminated string!");
|
||||
saveBuffer(state); // save the character!
|
||||
next(state); // consume
|
||||
switch (peek(state)) {
|
||||
case '\n': // strings can't stretch across lines
|
||||
return makeError(state, "Unterminated string!");
|
||||
case '\\': { // special character
|
||||
next(state); // consume the '\' character
|
||||
|
||||
switch (peek(state)) {
|
||||
case 'r': case 'n': appendBuffer(state, '\n'); break;
|
||||
case 't': appendBuffer(state, '\t'); break;
|
||||
case '\\': appendBuffer(state, '\\'); break;
|
||||
default:
|
||||
return makeError(state, "Unknown special character!"); // TODO: maybe a more descriptive error?
|
||||
}
|
||||
|
||||
next(state); // consume special character
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
saveBuffer(state); // save the character!
|
||||
next(state); // consume
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isEnd(state))
|
||||
|
Loading…
Reference in New Issue
Block a user