Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve an error message for ParseError #155

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

ydah
Copy link
Member

@ydah ydah commented Oct 24, 2023

This PR is improve an error message for ParseError.
The file name and the source of the error location are now displayed.

When you have a file named parse.y like this:

%{
// Prologue
%}

%expect invalid

%%

program: /* empty */
       ;
        INPUT

When lrama is executed, it displays an error as follows:

❯ lrama parse.y 
parser.y:416:in `on_error': parse.y:5:14: parse error on value #<struct Lrama::Lexer::Token type=#<struct Lrama::Lexer::Token::Type id=19, name="Ident">, s_value="invalid", alias=nil> (IDENTIFIER) (Racc::ParseError)
%expect invalid
              ^
        from racc/parser.rb:286:in `_racc_do_parse_c'
        from racc/parser.rb:286:in `do_parse'
        from parser.y:400:in `block in parse'
        from /Users/yudai.takada/ydah/lrama/lib/lrama/report/duration.rb:14:in `report_duration'
        from parser.y:396:in `parse'
        from /Users/yudai.takada/ydah/lrama/lib/lrama/command.rb:11:in `run'
        from exe/lrama:6:in `<main>'

@yui-knk yui-knk merged commit d0595b0 into ruby:master Oct 24, 2023
14 checks passed
@yui-knk
Copy link
Collaborator

yui-knk commented Oct 24, 2023

Thank you! Great improvement in error message!

@ydah ydah deleted the improve-error-message branch October 24, 2023 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants