diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-10-20 00:09:20 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-10-20 00:09:20 +0100 |
commit | afec2544f1793d11c47356c32ef74ce8c4035263 (patch) | |
tree | 91bbf823e4ae9d1ea212cd2b3c27cab26eef0b47 /lexer.l | |
parent | 6828ec9852583e1b1a84878235e9d61ab99930eb (diff) |
A string interpolation syntax that I don't hate. Also tests.
You can interpolate values into strings using \(this syntax), e.g.
"best \("str" + "ing") ever"
Diffstat (limited to 'lexer.l')
-rw-r--r-- | lexer.l | 24 |
1 files changed, 5 insertions, 19 deletions
@@ -61,45 +61,31 @@ } -\"(\\.|[^\\\"])*\" | -?[0-9.]+([eE][+-]?[0-9]+)? { yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL; } -\"(\\.|[^\\\"])* { - yylval->literal = jv_invalid_with_msg(jv_string("Unterminated string")); - return LITERAL; -} - -"@(" { +"\"" { yy_push_state(IN_QQSTRING, yyscanner); return QQSTRING_START; } <IN_QQSTRING>{ - "%(" { + "\\(" { return enter(QQSTRING_INTERP_START, YY_START, yyscanner); } - "%"[^(] { - return INVALID_CHARACTER; - } - ")" { + "\"" { yy_pop_state(yyscanner); return QQSTRING_END; } - "\\"[)%] { - char text[2] = {yytext[1], 0}; - yylval->literal = jv_string(text); - return QQSTRING_TEXT; - } - (\\[^u)%]|\\u[a-zA-Z0-9]{0,4})+ { + (\\[^u(]|\\u[a-zA-Z0-9]{0,4})+ { /* pass escapes to the json parser */ jv escapes = jv_string_fmt("\"%.*s\"", yyleng, yytext); yylval->literal = jv_parse_sized(jv_string_value(escapes), jv_string_length(jv_copy(escapes))); jv_free(escapes); return QQSTRING_TEXT; } - [^\\)%]+ { + [^\\\"]+ { yylval->literal = jv_string_sized(yytext, yyleng); return QQSTRING_TEXT; } |