mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 08:10: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) {
|
CToken parseString(CLexState *state) {
|
||||||
makeBuffer(state); // buffer mode
|
makeBuffer(state); // buffer mode
|
||||||
while (peek(state) != '"' && !isEnd(state)) {
|
while (peek(state) != '"' && !isEnd(state)) {
|
||||||
if (peek(state) == '\n') // strings can't stretch across lines
|
switch (peek(state)) {
|
||||||
return makeError(state, "Unterminated string!");
|
case '\n': // strings can't stretch across lines
|
||||||
saveBuffer(state); // save the character!
|
return makeError(state, "Unterminated string!");
|
||||||
next(state); // consume
|
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))
|
if (isEnd(state))
|
||||||
|
Loading…
Reference in New Issue
Block a user