Show offending lookahead chars when pretty-printing trees w/ errors

This commit is contained in:
Max Brunsfeld 2014-05-26 21:50:01 -07:00
parent 844f73c193
commit 2988cc5aa2
5 changed files with 31 additions and 16 deletions

View file

@ -3,7 +3,7 @@ recovers from errors at the top level
=====================================================
x * * y
---
(ERROR)
(ERROR '*')
=====================================================
recovers from errors inside parenthesized expressions
@ -12,4 +12,4 @@ x + (y * + z) * 5
---
(expression (sum
(variable)
(product (group (ERROR)) (number))))
(product (group (ERROR '+')) (number))))

View file

@ -3,7 +3,7 @@ recovers from errors in function calls
==========================================
stuff(|||);
---
(program (expression_statement (function_call (identifier) (ERROR))))
(program (expression_statement (function_call (identifier) (ERROR '|'))))
==========================================
recovers from errors in if statements
@ -16,8 +16,8 @@ moreStuff();
---
(program
(expression_statement (function_call (identifier)))
(if_statement (ERROR)
(statement_block (expression_statement (ERROR))))
(if_statement (ERROR '*')
(statement_block (expression_statement (ERROR '*'))))
(expression_statement (function_call (identifier))))
==========================================
@ -33,8 +33,8 @@ moreStuff();
(expression_statement (function_call (identifier)))
(for_statement
(var_declaration (assignment (identifier) (number)))
(expression_statement (ERROR))
(ERROR)
(statement_block (expression_statement (ERROR))))
(expression_statement (ERROR '*'))
(ERROR '*')
(statement_block (expression_statement (ERROR '*'))))
(expression_statement (function_call (identifier))))

View file

@ -3,14 +3,14 @@ recovers from top-level errors
==========================================
[}
---
(ERROR)
(ERROR '}')
==========================================
recovers from unexpected tokens
==========================================
barf
---
(ERROR)
(ERROR 'b')
==========================================
recovers from errors inside arrays
@ -19,7 +19,7 @@ recovers from errors inside arrays
---
(value (array
(number)
(ERROR)
(ERROR <EOF>)
(number)))
==========================================
@ -27,7 +27,7 @@ recovers from errors inside objects
==========================================
{ "key1": 1, oops }
---
(value (object (string) (number) (ERROR)))
(value (object (string) (number) (ERROR 'o')))
==========================================
recovers from errors inside nested objects
@ -35,6 +35,6 @@ recovers from errors inside nested objects
{ "key1": { "key2": 1, 2 }, [, "key3": 3 }
---
(value (object
(string) (object (string) (number) (ERROR))
(ERROR)
(string) (object (string) (number) (ERROR '2'))
(ERROR '[')
(string) (number)))