Exception: Ruby::Rego::ParserError

Inherits:
Error
  • Object
show all
Defined in:
lib/ruby/rego/errors.rb

Overview

Error raised during parsing.

Instance Attribute Summary collapse

Attributes inherited from Error

#location

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#to_h

Constructor Details

#initialize(message, location:, context: nil) ⇒ ParserError

Create a parser error.

Parameters:

  • message (String)

    error message

  • context (String, nil) (defaults to: nil)

    token context

  • location (Location)

    error location



95
96
97
98
99
100
101
# File 'lib/ruby/rego/errors.rb', line 95

def initialize(message, location:, context: nil)
  @line = location.line
  @column = location.column
  @context = context
  composed = context ? "#{message} (context: #{context})" : message
  super(composed, location: location)
end

Instance Attribute Details

#columnInteger (readonly)

Returns:

  • (Integer)


85
86
87
# File 'lib/ruby/rego/errors.rb', line 85

def column
  @column
end

#contextString? (readonly)

Returns:

  • (String, nil)


88
89
90
# File 'lib/ruby/rego/errors.rb', line 88

def context
  @context
end

#lineInteger (readonly)

Returns:

  • (Integer)


82
83
84
# File 'lib/ruby/rego/errors.rb', line 82

def line
  @line
end

Class Method Details

.from_position(message, position:, context: nil) ⇒ ParserError

Build an error from a position hash or location.

Parameters:

  • message (String)

    error message

  • position (Hash, Location)

    source position

  • context (String, nil) (defaults to: nil)

    token context

Returns:



109
110
111
112
# File 'lib/ruby/rego/errors.rb', line 109

def self.from_position(message, position:, context: nil)
  location = Location.from(position)
  new(message, location: location, context: context)
end