hoaproject / Compiler

The Hoa\Compiler library.
https://hoa-project.net/
453 stars 47 forks source link

Enhance context output of UnrecognizedToken exception #111

Open ohader opened 3 years ago

ohader commented 3 years ago

Grammar

%pragma     parser.lookahead    0
%skip       space               \s
%token a    a+
%token b    b+
%token c    c+
#root:
    ( <a> | <b> | <c> )*

Source

a
b
c
d

Results

Parsing above scenario leads to expected exception, since lexeme d is not defined in grammar. In thrown UnrecognizedToken


With adjustments

Hoa\Compiler\Exception\UnrecognizedToken: Unrecognized token "d" at line 4 and column 1:
a
b
c
d
↑ in /Users/olly/Development/Packages/fluid-compiler/vendor/hoa/compiler/Llk/Lexer.php on line 1