Class: Lrama::Lexer::Token
- Inherits:
-
Object
- Object
- Lrama::Lexer::Token
show all
- Defined in:
- lib/lrama/lexer/token.rb,
lib/lrama/lexer/token/tag.rb,
lib/lrama/lexer/token/char.rb,
lib/lrama/lexer/token/ident.rb,
lib/lrama/lexer/token/user_code.rb,
lib/lrama/lexer/token/instantiate_rule.rb
Defined Under Namespace
Classes: Char, Ident, InstantiateRule, Tag, UserCode
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(s_value:, alias_name: nil, location: nil) ⇒ Token
Returns a new instance of Token.
19
20
21
22
23
24
|
# File 'lib/lrama/lexer/token.rb', line 19
def initialize(s_value:, alias_name: nil, location: nil)
s_value.freeze
@s_value = s_value
@alias_name = alias_name
@location = location
end
|
Instance Attribute Details
#alias_name ⇒ Object
15
16
17
|
# File 'lib/lrama/lexer/token.rb', line 15
def alias_name
@alias_name
end
|
#location ⇒ Object
14
15
16
|
# File 'lib/lrama/lexer/token.rb', line 14
def location
@location
end
|
#referred ⇒ Object
16
17
18
|
# File 'lib/lrama/lexer/token.rb', line 16
def referred
@referred
end
|
#s_value ⇒ Object
13
14
15
|
# File 'lib/lrama/lexer/token.rb', line 13
def s_value
@s_value
end
|
Instance Method Details
#==(other) ⇒ Object
37
38
39
|
# File 'lib/lrama/lexer/token.rb', line 37
def ==(other)
self.class == other.class && self.s_value == other.s_value
end
|
#first_column ⇒ Object
Also known as:
column
48
49
50
|
# File 'lib/lrama/lexer/token.rb', line 48
def first_column
location.first_column
end
|
#first_line ⇒ Object
Also known as:
line
42
43
44
|
# File 'lib/lrama/lexer/token.rb', line 42
def first_line
location.first_line
end
|
#invalid_ref(ref, message) ⇒ Object
64
65
66
67
|
# File 'lib/lrama/lexer/token.rb', line 64
def invalid_ref(ref, message)
location = self.location.partial_location(ref.first_column, ref.last_column)
raise location.generate_error_message(message)
end
|
#last_column ⇒ Object
59
60
61
|
# File 'lib/lrama/lexer/token.rb', line 59
def last_column
location.last_column
end
|
#last_line ⇒ Object
54
55
56
|
# File 'lib/lrama/lexer/token.rb', line 54
def last_line
location.last_line
end
|
#referred_by?(string) ⇒ Boolean
32
33
34
|
# File 'lib/lrama/lexer/token.rb', line 32
def referred_by?(string)
[self.s_value, self.alias_name].compact.include?(string)
end
|
#to_s ⇒ Object
27
28
29
|
# File 'lib/lrama/lexer/token.rb', line 27
def to_s
"value: `#{s_value}`, location: #{location}"
end
|