Class: Token
- Inherits:
-
Object
show all
- Defined in:
- lib/tokens/token.rb
Direct Known Subclasses
Character, Comment, EscapeCharacter, Newline, QuoteCharacter, QuotedString, RegularExpression, Slash, Space, Tab, Word
Defined Under Namespace
Classes: Position
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(line = nil, character = nil, value = nil) ⇒ Token
Returns a new instance of Token.
6
7
8
9
10
11
12
13
|
# File 'lib/tokens/token.rb', line 6
def initialize(line=nil, character=nil, value=nil)
@subtokens = []
p = Position.new
p.line = line
p.character = character
@position = p
end
|
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
4
5
6
|
# File 'lib/tokens/token.rb', line 4
def position
@position
end
|
#subtokens ⇒ Object
Returns the value of attribute subtokens.
3
4
5
|
# File 'lib/tokens/token.rb', line 3
def subtokens
@subtokens
end
|
#value ⇒ Object
Returns the value of attribute value.
2
3
4
|
# File 'lib/tokens/token.rb', line 2
def value
@value
end
|
Class Method Details
.match(other) ⇒ Object
42
43
44
|
# File 'lib/tokens/token.rb', line 42
def match(other)
other == @symbol
end
|
.symbol ⇒ Object
46
47
48
|
# File 'lib/tokens/token.rb', line 46
def symbol
@symbol
end
|
Instance Method Details
#<<(subtoken) ⇒ Object
25
26
27
|
# File 'lib/tokens/token.rb', line 25
def <<(subtoken)
@subtokens << subtoken
end
|
#==(other) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/tokens/token.rb', line 15
def ==(other)
if(false && other.is_a?(Token))
return @id == other.id
elsif(other.is_a?(String))
return @value == other
else
super
end
end
|
#inspect ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/tokens/token.rb', line 62
def inspect
ins = ["<"]
ins << self.class.to_s
ins << ":'"
ins << symbol
ins << "':["
unless subtokens.nil? or subtokens.empty?
ins << subtokens.map{|d| d.symbol}.join
end
ins << "]>"
ins.join
end
|
#symbol ⇒ Object
33
34
35
|
# File 'lib/tokens/token.rb', line 33
def symbol
@symbol || self.class.symbol
end
|
#symbol=(sym) ⇒ Object
37
38
39
|
# File 'lib/tokens/token.rb', line 37
def symbol=(sym)
@symbol = sym
end
|
#to_s ⇒ Object
56
57
58
59
60
|
# File 'lib/tokens/token.rb', line 56
def to_s
ret = [symbol]
ret += subtokens.map{|t| t.symbol} unless subtokens.nil?
ret.join
end
|
#unshift(subtoken) ⇒ Object
29
30
31
|
# File 'lib/tokens/token.rb', line 29
def unshift(subtoken)
@subtokens.unshift subtoken
end
|