Commit 40d28355 authored by Chris Müller's avatar Chris Müller
Browse files

Add raw string literals to scanner

parent 548d84a6
......@@ -390,10 +390,44 @@ RETURN_TOKEN:
}
static enum org_cherry_tok
lex_raw_string(struct org_cherry_context* context)
{
struct org_cherry_array* buffer = context->buffer;
cy_byte_t* p = org_cherry_utf8_next(context->src);
cy_unicode_t ch = org_cherry_utf8_get(p);
int unicount = 0;
while(ch != '\0') {
if(ch == '~') {
p++;
goto RETURN_TOKEN;
} else if(ch == '\r' || ch == '\n') {
org_cherry_error(context, "Unexpected newline/carriage return found in raw string literal");
goto RETURN_TOKEN;
}
org_cherry_array_append(buffer, p, org_cherry_utf8_codepoints(p));
p = org_cherry_utf8_next(p);
ch = org_cherry_utf8_get(p);
}
RETURN_TOKEN:
context->src = p;
org_cherry_array_append(buffer, "\0", 1);
return TOK_STRING;
}
enum StringState {
STR_EAT,
STR_ESCAPE,
STR_UNICODE,
STR_ESCAPE,
STR_UNICODE,
STR_FINAL
};
......@@ -593,16 +627,20 @@ org_cherry_lex(struct org_cherry_context* context)
continue;
}
return lex_comment(context);
case '0': case '1': case '2': case '3': case '4':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return lex_number(context);
case '\\':
return lex_character(context);
case '"':
return lex_string(context);
case '~':
return lex_raw_string(context);
case '+': case '-': case '*': case '/': case '^':
case '<': case '>': case '=': case '?': case '!':
case ':': case '_': case '%': case '~': case '#':
case ':': case '_': case '%': case '#':
return lex_symbol(context);
default:
if(org_cherry_unicode_isalpha(ch))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment