Class: Treetop::Runtime::SyntaxNode
- Inherits:
-
Object
- Object
- Treetop::Runtime::SyntaxNode
- Defined in:
- lib/parser/edn-util.rb
Instance Method Summary collapse
- #app_parser_level1_diagnostics(e, node) ⇒ Object
- #app_parser_level1_raw_diagnostics(e, node) ⇒ Object
- #ast ⇒ Object
-
#ast1 ⇒ Object
devhack.
- #hex_value ⇒ Object
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 # l1 string ol1pos = l1pos = node.interval.begin # start position 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 |
#app_parser_level1_raw_diagnostics(e, node) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/parser/edn-util.rb', line 88 def app_parser_level1_raw_diagnostics(e, node) outbytes = 0 # do manual level-shifting input = node.input # l1 string ol1pos = l1pos = node.interval.begin # start position while outbytes <= e.position ol1pos = l1pos c1 = input[l1pos] if c1 != "\r" # Ignored CR doesn't generate output outbytes += 1 end l1pos += 1 end intv = ol1pos...l1pos 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 |
#ast ⇒ Object
33 34 35 |
# File 'lib/parser/edn-util.rb', line 33 def ast fail "undefined_ast #{inspect}" end |
#ast1 ⇒ Object
devhack
36 37 38 |
# File 'lib/parser/edn-util.rb', line 36 def ast1 # devhack "#{inspect[10..20]}--#{text_value[0..15]}" end |
#hex_value ⇒ Object
39 40 41 |
# File 'lib/parser/edn-util.rb', line 39 def hex_value text_value.to_i(16) end |