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.



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

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

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



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

def kind
  @kind
end

#posObject

Returns the value of attribute pos.



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

def pos
  @pos
end

#valObject Also known as: str

Returns the value of attribute val.



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

def val
  @val
end

Class Method Details

.create(str) ⇒ Object



25
26
27
# File 'lib/crokus/token.rb', line 25

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

Instance Method Details

#accept(visitor, arg = nil) ⇒ Object



21
22
23
# File 'lib/crokus/token.rb', line 21

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

#inspectObject



33
34
35
# File 'lib/crokus/token.rb', line 33

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

#is?(kind) ⇒ Boolean

Returns:

  • (Boolean)


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

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



29
30
31
# File 'lib/crokus/token.rb', line 29

def to_s
  val
end