Class: LLIP::Token
- Inherits:
-
Object
- Object
- LLIP::Token
- Defined in:
- lib/llip/token.rb
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
The position of the first char in the token.
-
#line ⇒ Object
readonly
The line at which this token was matched.
-
#name ⇒ Object
readonly
The name of the Regexp that generated this token.
-
#value ⇒ Object
(also: #to_s, #to_str)
readonly
The matched String.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #=~(regexp) ⇒ Object
-
#initialize(name = :nil, value = nil, line = -1,, char = -1)) ⇒ Token
constructor
A new instance of Token.
- #nil? ⇒ Boolean
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
#char ⇒ Object (readonly)
The position of the first char in the token
14 15 16 |
# File 'lib/llip/token.rb', line 14 def char @char end |
#line ⇒ Object (readonly)
The line at which this token was matched
11 12 13 |
# File 'lib/llip/token.rb', line 11 def line @line end |
#name ⇒ Object (readonly)
The name of the Regexp that generated this token
5 6 7 |
# File 'lib/llip/token.rb', line 5 def name @name end |
#value ⇒ Object (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
26 27 28 |
# File 'lib/llip/token.rb', line 26 def nil? value.nil? end |