Class: LLIP::Token

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :nil, value = nil, line = -1,, char = -1)) ⇒ Token

Returns a new instance of Token.



19
20
21
22
23
24
# File 'lib/llip/token.rb', line 19

def initialize(name=:nil,value=nil,line=-1,char = -1)
  @name = name
  @value = value
  @line = line
  @char = char
end

Instance Attribute Details

#charObject (readonly)

The position of the first char in the token



14
15
16
# File 'lib/llip/token.rb', line 14

def char
  @char
end

#lineObject (readonly)

The line at which this token was matched



11
12
13
# File 'lib/llip/token.rb', line 11

def line
  @line
end

#nameObject (readonly)

The name of the Regexp that generated this token



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

def name
  @name
end

#valueObject (readonly) Also known as: to_s, to_str

The matched String



8
9
10
# File 'lib/llip/token.rb', line 8

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  if other.respond_to? :name
    other.name == @name
  elsif other.respond_to? :to_str
    @value == other.to_str
  elsif other.respond_to? :to_sym	
    return true if other == :everything
    other.to_sym == @name
  else
    nil
  end
end

#=~(regexp) ⇒ Object



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

def =~(regexp)
  @value =~ regexp
end

#nil?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/llip/token.rb', line 26

def nil?
  value.nil?
end