Exception: EBNF::PEG::Parser::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ebnf/peg/parser.rb

Overview

Raised for errors during parsing.

Examples:

Raising a parser error

raise Error.new(
  "invalid token '%' on line 10",
  rest: '%', lineno: 9, production: :turtleDoc)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, **options) ⇒ Error

Initializes a new lexer error instance.

Parameters:

  • message (String, #to_s)
  • options (Hash{Symbol => Object})

Options Hash (**options):

  • :production (Symbol) — default: nil
  • :rest (String) — default: nil
  • :lineno (Integer) — default: nil


574
575
576
577
578
579
# File 'lib/ebnf/peg/parser.rb', line 574

def initialize(message, **options)
  @production = options[:production]
  @rest       = options[:rest]
  @lineno     = options[:lineno]
  super(message.to_s)
end

Instance Attribute Details

#linenoInteger (readonly)

The line number where the error occurred.

Returns:

  • (Integer)


564
565
566
# File 'lib/ebnf/peg/parser.rb', line 564

def lineno
  @lineno
end

#productionSymbol (readonly)

The current production.

Returns:

  • (Symbol)


552
553
554
# File 'lib/ebnf/peg/parser.rb', line 552

def production
  @production
end

#restString (readonly)

The read head when scanning failed

Returns:

  • (String)


558
559
560
# File 'lib/ebnf/peg/parser.rb', line 558

def rest
  @rest
end