Class: Scribble::Parsing::Reporter::Cause

Inherits:
Struct
  • Object
show all
Defined in:
lib/scribble/parsing/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#positionObject

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



4
5
6
# File 'lib/scribble/parsing/reporter.rb', line 4

def position
  @position
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



4
5
6
# File 'lib/scribble/parsing/reporter.rb', line 4

def source
  @source
end

Instance Method Details

#characterObject



21
22
23
# File 'lib/scribble/parsing/reporter.rb', line 21

def character
  source.instance_variable_get(:@str).string[position]
end

#columnObject



29
30
31
# File 'lib/scribble/parsing/reporter.rb', line 29

def column
  source.line_and_column(position).last
end

#expectedObject



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

#explanationObject



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

#lineObject



25
26
27
# File 'lib/scribble/parsing/reporter.rb', line 25

def line
  source.line_and_column(position).first
end

#raiseObject



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

#stringsObject



5
6
7
# File 'lib/scribble/parsing/reporter.rb', line 5

def strings
  @strings ||= []
end

#unexpectedObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/scribble/parsing/reporter.rb', line 41

def unterminated_string?
  strings.all? { |string| ["\\", "'"].include? string }
end