Class: Vertigo::Token

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tab) ⇒ Token

Returns a new instance of Token.



5
6
7
# File 'lib/vertigo/token.rb', line 5

def initialize tab
  @kind,@val,@pos=*tab
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



4
5
6
# File 'lib/vertigo/token.rb', line 4

def kind
  @kind
end

#posObject

Returns the value of attribute pos.



4
5
6
# File 'lib/vertigo/token.rb', line 4

def pos
  @pos
end

#valObject

Returns the value of attribute val.



4
5
6
# File 'lib/vertigo/token.rb', line 4

def val
  @val
end

Class Method Details

.create(kind, str) ⇒ Object



47
48
49
# File 'lib/vertigo/token.rb', line 47

def self.create kind,str
  Token.new [kind,str,[0,0]]
end

Instance Method Details

#accept(visitor, args = nil) ⇒ Object



43
44
45
# File 'lib/vertigo/token.rb', line 43

def accept visitor,args=nil
  visitor.visitToken(self)
end

#cloneObject



59
60
61
# File 'lib/vertigo/token.rb', line 59

def clone
  Token.new([@kind,@val,@pos])
end

#is_a?(kind) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vertigo/token.rb', line 9

def is_a? kind
  case kind
  when Symbol
    return @kind==kind
  when Array
    for sym in kind
      return true if @kind==sym
    end
    return false
  else
    raise "wrong type during lookahead"
  end
end

#is_not_a?(kind) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vertigo/token.rb', line 28

def is_not_a? kind
  case kind
  when Symbol
    return @kind!=kind
  when Array
    ret=true
    for sym in kind
      ret=false if @kind==sym
    end
    return ret
  else
    raise "wrong type during lookahead"
  end
end

#lineObject



63
64
65
# File 'lib/vertigo/token.rb', line 63

def line
  pos.first
end

#not_a?(kind) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/vertigo/token.rb', line 23

def not_a? kind
  result=self.is_a? kind
  !result
end

#strObject

def inspect

"(#{@kind.to_s.ljust(15,' ')},'#{@val}',#{@pos})"

end



55
56
57
# File 'lib/vertigo/token.rb', line 55

def str
  val
end