module Temill::ParserHack

Override parser and scanner actions since we need the range of each expr in Ruby programs

Public Instance Methods

after_reduce(val, _values, result) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source

wrap the value of each token to ParserResult

Calls superclass method
# File lib/temill/parser.rb, line 39
def next_token
  sym,val = super
  lineno = lexer.lineno
  [sym, ParserResult.new(val, lineno..lineno, sym)]
end