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:
1 parent
6828ec9852
commit
afec2544f1
4 files changed
+29
-28
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user