Module: Temill::ParserHack
- Included in:
- Ruby23Parser
- Defined in:
- lib/temill/parser.rb
Overview
Override parser and scanner actions since we need the range of each expr in Ruby programs
Instance Method Summary collapse
- #after_reduce(val, _values, result) ⇒ Object
- #before_reduce(val, *rest) ⇒ Object
- #debug_print_state_stack ⇒ Object
-
#next_token ⇒ Object
wrap the value of each token to ParserResult.
Instance Method Details
#after_reduce(val, _values, result) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/temill/parser.rb', line 20 def after_reduce(val, _values, result) min = max = nil #debug_print_state_stack val.each{| v | if v.kind_of?(ParserResult) and v.sym != :tNL min = [min, v.line_range.min].compact.min max = [max, v.line_range.max].compact.max end } if result.kind_of?(Sexp) result.line_range = min..max end # sym is not specified, but OK as long as it is used to check whether # the symbol is newline or not. ParserResult.new(result, min..max, nil) end |
#before_reduce(val, *rest) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/temill/parser.rb', line 9 def before_reduce(val, *rest) #ap val val.map{| v | if v.kind_of?(ParserResult) v.value else v end } end |
#debug_print_state_stack ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/temill/parser.rb', line 45 def debug_print_state_stack if @racc_tstack pp @racc_tstack.zip(@racc_vstack).map{| tok,v | [token_to_str(tok), v] } end end |
#next_token ⇒ Object
wrap the value of each token to ParserResult
39 40 41 42 43 |
# File 'lib/temill/parser.rb', line 39 def next_token sym,val = super lineno = lexer.lineno [sym, ParserResult.new(val, lineno..lineno, sym)] end |