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


568
569
570
571
572
573
# File 'lib/ebnf/peg/parser.rb', line 568

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)


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

def lineno
  @lineno
end

#productionSymbol (readonly)

The current production.

Returns:

  • (Symbol)


546
547
548
# File 'lib/ebnf/peg/parser.rb', line 546

def production
  @production
end

#restString (readonly)

The read head when scanning failed

Returns:

  • (String)


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

def rest
  @rest
end