class GenericParser

Public Instance Methods

acceptIt() click to toggle source
# File lib/vertigo/generic_parser.rb, line 3
def acceptIt
  tok=tokens.shift
  puts "consuming #{tok.val} (#{tok.kind})" if @verbose
  tok
end
expect(kind) click to toggle source
# File lib/vertigo/generic_parser.rb, line 13
def expect kind
  if (actual=showNext.kind)!=kind
    abort "ERROR at #{showNext.pos}. Expecting #{kind}. Got #{actual}"
  else
    return acceptIt()
  end
end
lookahead(n) click to toggle source
# File lib/vertigo/generic_parser.rb, line 32
def lookahead n
  showNext(k=n)
end
maybe(kind) click to toggle source
# File lib/vertigo/generic_parser.rb, line 21
def maybe kind
  if showNext.kind==kind
    return acceptIt
  end
  nil
end
more?() click to toggle source
# File lib/vertigo/generic_parser.rb, line 28
def more?
  !tokens.empty?
end
next_tokens(n=5) click to toggle source
# File lib/vertigo/generic_parser.rb, line 40
def  next_tokens n=5
  @tokens[0..n].map{|tok| [tok.kind,tok.val].to_s}.join(',')
end
niy() click to toggle source
# File lib/vertigo/generic_parser.rb, line 36
def niy
  raise "NIY"
end
showNext(k=1) click to toggle source
# File lib/vertigo/generic_parser.rb, line 9
def showNext k=1
  tokens[k-1]
end