Class: GenericParser

Inherits:
Object
  • Object
show all
Defined in:
lib/vertigo/generic_parser.rb

Direct Known Subclasses

Vertigo::Parser

Instance Method Summary collapse

Instance Method Details

#acceptItObject



3
4
5
6
7
# 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) ⇒ Object



13
14
15
16
17
18
19
# 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) ⇒ Object



32
33
34
# File 'lib/vertigo/generic_parser.rb', line 32

def lookahead n
  showNext(k=n)
end

#maybe(kind) ⇒ Object



21
22
23
24
25
26
# File 'lib/vertigo/generic_parser.rb', line 21

def maybe kind
  if showNext.kind==kind
    return acceptIt
  end
  nil
end

#more?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/vertigo/generic_parser.rb', line 28

def more?
  !tokens.empty?
end

#next_tokens(n = 5) ⇒ Object



40
41
42
# 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

#niyObject



36
37
38
# File 'lib/vertigo/generic_parser.rb', line 36

def niy
  raise "NIY"
end

#showNext(k = 1) ⇒ Object



9
10
11
# File 'lib/vertigo/generic_parser.rb', line 9

def showNext k=1
  tokens[k-1]
end