Class: Ripper::Lexer
Overview
:nodoc: internal use only
Defined Under Namespace
Constant Summary
Constants inherited from Ripper
EVENTS, PARSER_EVENTS, SCANNER_EVENTS
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #lex ⇒ Object
- #parse ⇒ Object
-
#scan ⇒ Object
parse the code and returns elements including errors.
- #tokenize ⇒ Object
Methods inherited from Ripper
lex, parse, sexp, sexp_raw, slice, token_match, tokenize
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors
96 97 98 |
# File 'lib/ripper/lexer.rb', line 96 def errors @errors end |
Instance Method Details
#lex ⇒ Object
102 103 104 |
# File 'lib/ripper/lexer.rb', line 102 def lex parse().sort_by(&:pos).map(&:to_a) end |
#parse ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/ripper/lexer.rb', line 121 def parse @errors = [] @buf = [] @stack = [] super @buf.flatten! @buf end |
#scan ⇒ Object
parse the code and returns elements including errors.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ripper/lexer.rb', line 107 def scan result = (parse() + errors + @stack.flatten).uniq.sort_by {|e| [*e.pos, (e. ? -1 : 0)]} result.each_with_index do |e, i| if e.event == :on_parse_error and e.tok.empty? and (pre = result[i-1]) and pre.pos[0] == e.pos[0] and (pre.pos[1] + pre.tok.size) == e.pos[1] e.tok = pre.tok e.pos[1] = pre.pos[1] result[i-1] = e result[i] = pre end end result end |
#tokenize ⇒ Object
98 99 100 |
# File 'lib/ripper/lexer.rb', line 98 def tokenize parse().sort_by(&:pos).map(&:tok) end |