More error handling in the parser.
Add a special case in the lexer to detect unterminated strings. Add some error recovery in the parser for more copious error spam.
This commit is contained in:
1 parent
ac3f8bcc52
commit
0ce437ea97
2 files changed
+21
-7
No files matched your search
@@ -39,6 +39,12 @@
|
||||
yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;
|
||||
}
|
||||
|
||||
\"(\\.|[^\\\"])* {
|
||||
yylval->literal = jv_invalid_with_msg(jv_string("Unterminated string"));
|
||||
return LITERAL;
|
||||
}
|
||||
|
||||
|
||||
[[:alnum:]]+ { yylval->literal = jv_string(yytext); return IDENT;}
|
||||
|
||||
[ \n\t]+ {}
|
||||
|
||||
+15
-7
@@ -3,7 +3,6 @@
|
||||
#include <string.h>
|
||||
#include "compile.h"
|
||||
%}
|
||||
|
||||
%code requires {
|
||||
#include "locfile.h"
|
||||
#define YYLTYPE location
|
||||
@@ -170,6 +169,10 @@ Term "as" '$' IDENT '|' Exp {
|
||||
"if" Exp "then" Exp ElseBody {
|
||||
$$ = gen_cond($2, $4, $5);
|
||||
} |
|
||||
"if" Exp error {
|
||||
FAIL(@$, "Possibly unterminated 'if' statment");
|
||||
$$ = $2;
|
||||
} |
|
||||
|
||||
Exp '=' Exp {
|
||||
block assign = gen_op_simple(DUP);
|
||||
@@ -188,7 +191,6 @@ Exp "and" Exp {
|
||||
$$ = gen_and($1, $3);
|
||||
} |
|
||||
|
||||
|
||||
"not" Exp {
|
||||
$$ = gen_not($2);
|
||||
} |
|
||||
@@ -236,6 +238,8 @@ Term {
|
||||
$$ = $1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ElseBody:
|
||||
"elif" Exp "then" Exp ElseBody {
|
||||
$$ = gen_cond($2, $4, $5);
|
||||
@@ -304,16 +308,19 @@ IDENT '(' Exp ')' {
|
||||
block_join($3, gen_op_simple(RET))),
|
||||
gen_noop(), OP_IS_CALL_PSEUDO)));
|
||||
jv_free($1);
|
||||
}
|
||||
} |
|
||||
'(' error ')' { $$ = gen_noop(); } |
|
||||
'[' error ']' { $$ = gen_noop(); } |
|
||||
Term '[' error ']' { $$ = $1; } |
|
||||
'{' error '}' { $$ = gen_noop(); }
|
||||
|
||||
MkDict:
|
||||
{
|
||||
$$=gen_noop();
|
||||
}
|
||||
|
|
||||
MkDictPair
|
||||
{ $$ = $1; }
|
||||
} |
|
||||
MkDictPair { $$ = $1; }
|
||||
| MkDictPair ',' MkDict { $$=block_join($1, $3); }
|
||||
| error ',' MkDict { $$ = $3; }
|
||||
|
||||
MkDictPair
|
||||
: IDENT ':' ExpD {
|
||||
@@ -332,6 +339,7 @@ MkDictPair
|
||||
| '(' Exp ')' ':' ExpD {
|
||||
$$ = gen_dictpair($2, $5);
|
||||
}
|
||||
| '(' error ')' ':' ExpD { $$ = $5; }
|
||||
%%
|
||||
|
||||
int compile(const char* str, block* answer) {
|
||||
|
||||
Reference in new issue
Block a user