parser.y in lrama-0.5.7 vs parser.y in lrama-0.5.8

- old
+ new

@@ -1,6 +1,7 @@ class Lrama::Parser + token C_DECLARATION CHARACTER IDENT_COLON IDENTIFIER INTEGER STRING TAG rule input: prologue_declarations bison_declarations "%%" grammar epilogue_opt prologue_declarations: # empty | prologue_declarations prologue_declaration @@ -296,11 +297,11 @@ @code_after_prec = false } | rhs symbol named_ref_opt { token = val[1] - val[1].alias = val[2] + token.alias = val[2] result = val[0].append(token) } | rhs "{" { if @prec_seen @@ -385,12 +386,13 @@ ---- inner include Lrama::Report::Duration -def initialize(text) +def initialize(text, path) @text = text + @path = path end def parse report_duration(:parse) do @lexer = Lrama::Lexer.new(@text) @@ -409,8 +411,12 @@ def next_token @lexer.next_token end def on_error(error_token_id, error_value, value_stack) - raise ParseError, sprintf("\n%d:%d: parse error on value %s (%s)", - @lexer.line, @lexer.column, error_value.inspect, token_to_str(error_token_id) || '?') + source = @text.split("\n")[error_value.line - 1] + raise ParseError, <<~ERROR + #{@path}:#{@lexer.line}:#{@lexer.column}: parse error on value #{error_value.inspect} (#{token_to_str(error_token_id) || '?'}) + #{source} + #{' ' * @lexer.column}^ + ERROR end