Exception: Ibex::Runtime::ParseError
- Inherits:
-
StandardError
- Object
- StandardError
- Ibex::Runtime::ParseError
- Defined in:
- lib/ibex/runtime/parser.rb,
sig/ibex/runtime/parser.rbs
Overview
Raised by the default parser error handler.
Direct Known Subclasses
Instance Attribute Summary collapse
- #error_id ⇒ String? readonly
- #expected_tokens ⇒ Array[String] readonly
- #location ⇒ runtime_value readonly
- #state ⇒ Integer? readonly
- #suggestions ⇒ Array[String] readonly
- #token_id ⇒ Integer? readonly
- #token_name ⇒ String? readonly
- #token_value ⇒ runtime_value readonly
Instance Method Summary collapse
- #diagnostic_message ⇒ String
-
#initialize(message = nil, token_id: nil, token_name: nil, token_value: nil, expected_tokens: [], location: nil, state: nil, suggestions: [], error_id: nil, detail: nil) ⇒ ParseError
constructor
rubocop:disable Layout/LineLength rubocop:enable Layout/LineLength.
- #location_label ⇒ String
- #location_value(key) ⇒ runtime_value
Constructor Details
#initialize(message = nil, token_id: nil, token_name: nil, token_value: nil, expected_tokens: [], location: nil, state: nil, suggestions: [], error_id: nil, detail: nil) ⇒ ParseError
rubocop:disable Layout/LineLength rubocop:enable Layout/LineLength
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ibex/runtime/parser.rb', line 36 def initialize( = nil, token_id: nil, token_name: nil, token_value: nil, expected_tokens: [], location: nil, state: nil, suggestions: [], error_id: nil, detail: nil ) @token_id = token_id @token_name = token_name @token_value = token_value @expected_tokens = expected_tokens.dup.freeze @location = location @state = state @suggestions = suggestions.dup.freeze @error_id = error_id&.dup&.freeze @detail = detail super( || ) end |
Instance Attribute Details
#error_id ⇒ String? (readonly)
31 32 33 |
# File 'lib/ibex/runtime/parser.rb', line 31 def error_id @error_id end |
#expected_tokens ⇒ Array[String] (readonly)
27 28 29 |
# File 'lib/ibex/runtime/parser.rb', line 27 def expected_tokens @expected_tokens end |
#location ⇒ runtime_value (readonly)
28 29 30 |
# File 'lib/ibex/runtime/parser.rb', line 28 def location @location end |
#state ⇒ Integer? (readonly)
29 30 31 |
# File 'lib/ibex/runtime/parser.rb', line 29 def state @state end |
#suggestions ⇒ Array[String] (readonly)
30 31 32 |
# File 'lib/ibex/runtime/parser.rb', line 30 def suggestions @suggestions end |
#token_id ⇒ Integer? (readonly)
24 25 26 |
# File 'lib/ibex/runtime/parser.rb', line 24 def token_id @token_id end |
#token_name ⇒ String? (readonly)
25 26 27 |
# File 'lib/ibex/runtime/parser.rb', line 25 def token_name @token_name end |
#token_value ⇒ runtime_value (readonly)
26 27 28 |
# File 'lib/ibex/runtime/parser.rb', line 26 def token_value @token_value end |
Instance Method Details
#diagnostic_message ⇒ String
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ibex/runtime/parser.rb', line 71 def expected = @expected_tokens.empty? ? "" : "; expected #{@expected_tokens.join(', ')}" default = "unexpected #{@token_name || @token_id}#{expected} (#{@token_value.inspect})" identifier = @error_id ? "[#{@error_id}] " : "" = "#{location_label}: #{identifier}#{@detail || default}" source_line = location_value(:source_line) column = location_value(:column) += "\n#{source_line}\n#{' ' * [column.to_i - 1, 0].max}^" if source_line += "\ndid you mean #{@suggestions.join(' or ')}?" unless @suggestions.empty? end |
#location_label ⇒ String
61 62 63 64 65 66 |
# File 'lib/ibex/runtime/parser.rb', line 61 def location_label file = location_value(:file) || "(input)" line = location_value(:line) || 1 column = location_value(:column) || 1 "#{file}:#{line}:#{column}" end |
#location_value(key) ⇒ runtime_value
84 85 86 87 88 89 90 |
# File 'lib/ibex/runtime/parser.rb', line 84 def location_value(key) return nil unless @location return @location.public_send(key) if @location.respond_to?(key) return @location[key] || @location[key.to_s] if @location.is_a?(Hash) nil end |