From 2c4ccd122e6bf151bfdbcb4e729ad316d8ff2b2f Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Mon, 3 Jun 2013 23:08:17 +0100 Subject: [PATCH] Better error handling for .foo case in parser. See #141. --- parser.y | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/parser.y b/parser.y index 461b9c9..c9563a0 100644 --- a/parser.y +++ b/parser.y @@ -227,7 +227,7 @@ Term "as" '$' IDENT '|' Exp { "if" Exp "then" Exp ElseBody { $$ = gen_cond($2, $4, $5); } | -"if" Exp error { +"if" Exp "then" error { FAIL(@$, "Possibly unterminated 'if' statment"); $$ = $2; } | @@ -405,6 +405,15 @@ Term '.' IDENT { '.' IDENT { $$ = gen_index(gen_noop(), gen_const($2)); } | +'.' error { + FAIL(@$, "try .[\"field\"] instead of .field for unusually named fields"); + $$ = gen_noop(); +} | +'.' IDENT error { + jv_free($2); + FAIL(@$, "try .[\"field\"] instead of .field for unusually named fields"); + $$ = gen_noop(); +} | /* FIXME: string literals */ Term '[' Exp ']' { $$ = gen_index($1, $3); -- 2.40.0