Class: Scribble::Parsing::Reporter::Cause
- Inherits:
-
Struct
- Object
- Struct
- Scribble::Parsing::Reporter::Cause
- Defined in:
- lib/scribble/parsing/reporter.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #character ⇒ Object
- #column ⇒ Object
- #expected ⇒ Object
- #explanation ⇒ Object
- #line ⇒ Object
- #raise ⇒ Object
- #strings ⇒ Object
- #unexpected ⇒ Object
- #unterminated_string? ⇒ Boolean
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position
4 5 6 |
# File 'lib/scribble/parsing/reporter.rb', line 4 def position @position end |
#source ⇒ Object
Returns the value of attribute source
4 5 6 |
# File 'lib/scribble/parsing/reporter.rb', line 4 def source @source end |
Instance Method Details
#character ⇒ Object
21 22 23 |
# File 'lib/scribble/parsing/reporter.rb', line 21 def character source.instance_variable_get(:@str).string[position] end |
#column ⇒ Object
29 30 31 |
# File 'lib/scribble/parsing/reporter.rb', line 29 def column source.line_and_column(position).last end |
#expected ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/scribble/parsing/reporter.rb', line 45 def expected strings.map do |string| if string == 'true' then "a value" elsif string == '+' then "an operator" elsif string == '(' then "'('" elsif string == '}}' then "'}}'" elsif string == 'end' then "'end'" end end.compact.uniq.sort end |
#explanation ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/scribble/parsing/reporter.rb', line 33 def explanation if unterminated_string? "; unterminated string" else ", expected #{Support::Utilities.to_sentence expected}" end end |
#line ⇒ Object
25 26 27 |
# File 'lib/scribble/parsing/reporter.rb', line 25 def line source.line_and_column(position).first end |
#raise ⇒ Object
9 10 11 |
# File 'lib/scribble/parsing/reporter.rb', line 9 def raise Kernel.raise Errors::Syntax.new "#{unexpected} at line #{line} column #{column}#{explanation}" end |
#strings ⇒ Object
5 6 7 |
# File 'lib/scribble/parsing/reporter.rb', line 5 def strings @strings ||= [] end |
#unexpected ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/scribble/parsing/reporter.rb', line 13 def unexpected if character "Unexpected '#{character}'" else "Unexpected end of template" end end |
#unterminated_string? ⇒ Boolean
41 42 43 |
# File 'lib/scribble/parsing/reporter.rb', line 41 def unterminated_string? strings.all? { |string| ["\\", "'"].include? string } end |