Class: TRuby::ParserCombinator::ParseError
- Inherits:
-
Object
- Object
- TRuby::ParserCombinator::ParseError
- Defined in:
- lib/t_ruby/parser_combinator.rb
Overview
Error Reporting
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #context(lines_before: 2, lines_after: 1) ⇒ Object
-
#initialize(message:, position:, input:) ⇒ ParseError
constructor
A new instance of ParseError.
- #to_s ⇒ Object
Constructor Details
#initialize(message:, position:, input:) ⇒ ParseError
Returns a new instance of ParseError.
903 904 905 906 907 908 |
# File 'lib/t_ruby/parser_combinator.rb', line 903 def initialize(message:, position:, input:) @message = @position = position @input = input @line, @column = calculate_line_column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
901 902 903 |
# File 'lib/t_ruby/parser_combinator.rb', line 901 def column @column end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
901 902 903 |
# File 'lib/t_ruby/parser_combinator.rb', line 901 def input @input end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
901 902 903 |
# File 'lib/t_ruby/parser_combinator.rb', line 901 def line @line end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
901 902 903 |
# File 'lib/t_ruby/parser_combinator.rb', line 901 def @message end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
901 902 903 |
# File 'lib/t_ruby/parser_combinator.rb', line 901 def position @position end |
Instance Method Details
#context(lines_before: 2, lines_after: 1) ⇒ Object
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/t_ruby/parser_combinator.rb', line 914 def context(lines_before: 2, lines_after: 1) input_lines = @input.split("\n") start_line = [@line - lines_before - 1, 0].max end_line = [@line + lines_after - 1, input_lines.length - 1].min result = [] (start_line..end_line).each do |i| prefix = i == @line - 1 ? ">>> " : " " result << "#{prefix}#{i + 1}: #{input_lines[i]}" if i == @line - 1 result << " " + " " * (@column + @line.to_s.length + 1) + "^" end end result.join("\n") end |
#to_s ⇒ Object
910 911 912 |
# File 'lib/t_ruby/parser_combinator.rb', line 910 def to_s "Parse error at line #{@line}, column #{@column}: #{@message}" end |