{ .in = "%{literal('\\\\x20')}", .out = "'\\x20'", .ret = 0 },
/* Bad hex / oct */
{ .in = "\\xgg", .out = "\\xgg", .ret = 0 },
- { .in = "%{literal('\\xgg')}", .out = "expecting MINUS or NAME or VALUE or NUMBER", .ret = -1 },
+ { .in = "%{literal('\\xgg')}", .out = "Invalid character escape", .ret = -1 },
{ .in = "\\999", .out = "\\999", .ret = 0 },
- { .in = "%{literal('\\999')}", .out = "expecting MINUS or NAME or VALUE or NUMBER", .ret = -1 },
+ { .in = "%{literal('\\999')}", .out = "Invalid character escape", .ret = -1 },
/* List test */
{ .in = "%{literal('one\ttwo\tthree') | list}", .out="'one,two,three'", .ret = 0 },
/* Escape escape */
{ .in = "\\hello\\world", .out = "\\hello\\world", .ret = 0 },
{ .in = "%{literal('\\'\\\\hello\\\\world\\'')}", .out = "'\\'\\hello\\world\\''", .ret = 0 },
{ .in = "%{literal(\"\\\"\\\\hello\\\\world\\\"\")}", .out = "'\"\\hello\\world\"'", .ret = 0 },
+ /* Unsupported escape sequence */
+ { .in = "%{literal('\\z')}", .out = "Invalid character escape", .ret = -1 },
};
const struct var_expand_params params = {
yylval->str = str_new(state->pool, 32); \
} STMT_END
+static int scanner_error(void *yyscanner, const char *msg);
%}
%x stringsq
x[0-9a-fA-F]{2} {
unsigned int c;
if (str_to_uint_hex(yytext+1, &c) < 0 || c > 255) {
- YYSTYPE *state = yyget_extra(yyscanner);
- state->error = "Invalid character escape";
- yyterminate();
+ return scanner_error(yyscanner, "Invalid character escape");
}
yy_pop_state(yyscanner); str_append_c(yylval->str, c);
}
[0-9]{1,3} {
unsigned int c;
if (str_to_uint_oct(yytext, &c) < 0 || c > 255) {
- YYSTYPE *state = yyget_extra(yyscanner);
- state->error = "Invalid character escape";
- yyterminate();
+ return scanner_error(yyscanner, "Invalid character escape");
}
yy_pop_state(yyscanner); str_append_c(yylval->str, c);
}
n { yy_pop_state(yyscanner); str_append_c(yylval->str, '\n'); }
["] { yy_pop_state(yyscanner); str_append_c(yylval->str, '"'); }
['] { yy_pop_state(yyscanner); str_append_c(yylval->str, '\''); }
- . { YYSTYPE *state = yyget_extra(yyscanner); state->error = "Invalid character escape"; }
+ . { return scanner_error(yyscanner, "Invalid character escape"); }
}
<stringdq>{
%%
extern void var_expand_parser_error(YYLTYPE *loc, YYSTYPE *state, const char *error);
-void var_expand_parser_error(YYLTYPE *loc, YYSTYPE *state, const char *error)
+void var_expand_parser_error(YYLTYPE *loc ATTR_UNUSED, YYSTYPE *state, const char *error)
{
state->failed = TRUE;
state->error = p_strdup(state->pool, error);
}
+static int scanner_error(void *scanner, const char *msg)
+{
+ YYSTYPE *state = yyget_extra(scanner);
+ struct yyguts_t *yyg = (struct yyguts_t *)scanner;
+ var_expand_parser_error(yylloc, state, msg);
+ return VAR_EXPAND_PARSER_error;
+}
+
void *yyalloc(size_t bytes, void* yyscanner)
{
YYSTYPE *state = yyget_extra(yyscanner);