Class: Token

Inherits:
Object
  • Object
show all
Defined in:
lib/crokus/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/crokus/token.rb', line 5

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

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



3
4
5
# File 'lib/crokus/token.rb', line 3

def kind
  @kind
end

#posObject

Returns the value of attribute pos.



3
4
5
# File 'lib/crokus/token.rb', line 3

def pos
  @pos
end

#valObject Also known as: str

Returns the value of attribute val.



3
4
5
# File 'lib/crokus/token.rb', line 3

def val
  @val
end

Class Method Details

.create(str) ⇒ Object



27
28
29
# File 'lib/crokus/token.rb', line 27

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

Instance Method Details

#accept(visitor, arg = nil) ⇒ Object



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

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

#inspectObject



35
36
37
# File 'lib/crokus/token.rb', line 35

def inspect
  "(#{kind},#{val},#{pos})"
end

#is?(kind) ⇒ Boolean

Returns:

  • (Boolean)


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

def is? 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

#to_sObject



31
32
33
# File 'lib/crokus/token.rb', line 31

def to_s
  val
end