Let the parser rather than the lexer handle invalid characters.
This commit is contained in:
1 parent
cc8761dbde
commit
b90ae078b8
1 file changed
+12
-19
@@ -5,12 +5,11 @@
|
|||||||
#include "jv_alloc.h"
|
#include "jv_alloc.h"
|
||||||
#define YYMALLOC jv_mem_alloc
|
#define YYMALLOC jv_mem_alloc
|
||||||
#define YYFREE jv_mem_free
|
#define YYFREE jv_mem_free
|
||||||
|
|
||||||
struct lexer_param;
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
%code requires {
|
%code requires {
|
||||||
#include "locfile.h"
|
#include "locfile.h"
|
||||||
|
struct lexer_param;
|
||||||
|
|
||||||
#define YYLTYPE location
|
#define YYLTYPE location
|
||||||
#define YYLLOC_DEFAULT(Loc, Rhs, N) \
|
#define YYLLOC_DEFAULT(Loc, Rhs, N) \
|
||||||
do { \
|
do { \
|
||||||
@@ -112,25 +111,19 @@ void yyerror(YYLTYPE* loc, block* answer, int* errors,
|
|||||||
int yylex(YYSTYPE* yylval, YYLTYPE* yylloc, block* answer, int* errors,
|
int yylex(YYSTYPE* yylval, YYLTYPE* yylloc, block* answer, int* errors,
|
||||||
struct locfile* locations, struct lexer_param* lexer_param_ptr) {
|
struct locfile* locations, struct lexer_param* lexer_param_ptr) {
|
||||||
yyscan_t lexer = lexer_param_ptr->lexer;
|
yyscan_t lexer = lexer_param_ptr->lexer;
|
||||||
while (1) {
|
int tok = jq_yylex(yylval, yylloc, lexer);
|
||||||
int tok = jq_yylex(yylval, yylloc, lexer);
|
if ((tok == LITERAL || tok == QQSTRING_TEXT) && !jv_is_valid(yylval->literal)) {
|
||||||
if (tok == INVALID_CHARACTER) {
|
jv msg = jv_invalid_get_msg(jv_copy(yylval->literal));
|
||||||
FAIL(*yylloc, "Invalid character");
|
if (jv_get_kind(msg) == JV_KIND_STRING) {
|
||||||
|
FAIL(*yylloc, jv_string_value(msg));
|
||||||
} else {
|
} else {
|
||||||
if ((tok == LITERAL || tok == QQSTRING_TEXT) && !jv_is_valid(yylval->literal)) {
|
FAIL(*yylloc, "Invalid literal");
|
||||||
jv msg = jv_invalid_get_msg(jv_copy(yylval->literal));
|
|
||||||
if (jv_get_kind(msg) == JV_KIND_STRING) {
|
|
||||||
FAIL(*yylloc, jv_string_value(msg));
|
|
||||||
} else {
|
|
||||||
FAIL(*yylloc, "Invalid literal");
|
|
||||||
}
|
|
||||||
jv_free(msg);
|
|
||||||
jv_free(yylval->literal);
|
|
||||||
yylval->literal = jv_null();
|
|
||||||
}
|
|
||||||
return tok;
|
|
||||||
}
|
}
|
||||||
|
jv_free(msg);
|
||||||
|
jv_free(yylval->literal);
|
||||||
|
yylval->literal = jv_null();
|
||||||
}
|
}
|
||||||
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static block gen_dictpair(block k, block v) {
|
static block gen_dictpair(block k, block v) {
|
||||||
|
|||||||
Reference in new issue
Block a user