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"
This commit is contained in:
Stephen Dolan committed 2012-10-20 00:09:20 +01:00
1 parent 6828ec9852
commit afec2544f1
4 files changed
+29 -28

No files matched your search

+5 -19
View File
@@ -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;
}