Class: Treetop::Runtime::SyntaxNode

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/edn-util.rb

Instance Method Summary collapse

Instance Method Details

#app_parser_level1_diagnostics(e, node) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/parser/edn-util.rb', line 42

def app_parser_level1_diagnostics(e, node)
  outbytes = 0
  if $options.level                                # do manual level-shifting
    input = node.input
    ol1pos = l1pos = node.interval.begin
    while outbytes <= e.position
      outbytes += 1
      ol1pos = l1pos
      c1 = input[l1pos]
      if c1 == "\\"           # escapable-s
        c2 = input[l1pos += 1]
        if c2 == "u"          # hexchar-s
          c3 = input[l1pos += 1]
          if c3 == "{"
            l1pos = input.index("}", l1pos)
          else
            if (input[l1pos, 4].to_i(16) & 0xFC00) == 0xD800 # high-surrogate
              l1pos += 6                                     # low-surrogate
            end
            l1pos += 3        # non-surrogate
          end
        end
      end
      l1pos += 1
    end
    intv = ol1pos...l1pos
  else
    intv = node.interval.end...(node.interval.end+1) # default: closing '
    node.elements.each_with_index do |el, i|
      outbytes += el.ast.size
      if outbytes > e.position
        intv = el.interval
        break
      end
    end
  end
  failure_index = intv.begin
  failure_line = node.input.line_of(failure_index)
  failure_column = node.input.column_of(failure_index)
  reason = "** Line #{failure_line}, column #{failure_column}:\n"
  if line = node.input.lines.to_a[failure_line - 1]
    reason << line
    reason << "\n#{'~' * (failure_column - 1)}#{'^' * intv.size}"
  end
  warn reason
end

#astObject



33
34
35
# File 'lib/parser/edn-util.rb', line 33

def ast
  fail "undefined_ast #{inspect}"
end

#ast1Object

devhack



36
37
38
# File 'lib/parser/edn-util.rb', line 36

def ast1                      # devhack
  "#{inspect[10..20]}--#{text_value[0..15]}"
end

#hex_valueObject



39
40
41
# File 'lib/parser/edn-util.rb', line 39

def hex_value
  text_value.to_i(16)
end