Class: Lrama::Lexer::Token
- Inherits:
-
Struct
- Object
- Struct
- Lrama::Lexer::Token
- Defined in:
- lib/lrama/lexer/token.rb,
lib/lrama/lexer/token/type.rb
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#column ⇒ Object
Returns the value of attribute column.
-
#line ⇒ Object
Returns the value of attribute line.
-
#references ⇒ Object
For User_code.
-
#referred ⇒ Object
Returns the value of attribute referred.
-
#s_value ⇒ Object
Returns the value of attribute s_value.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #numberize_references(lhs, rhs) ⇒ Object
- #referred_by?(string) ⇒ Boolean
- #to_s ⇒ Object
Instance Attribute Details
#alias ⇒ Object
Returns the value of attribute alias
3 4 5 |
# File 'lib/lrama/lexer/token/type.rb', line 3 def alias @alias end |
#column ⇒ Object
Returns the value of attribute column.
7 8 9 |
# File 'lib/lrama/lexer/token.rb', line 7 def column @column end |
#line ⇒ Object
Returns the value of attribute line.
7 8 9 |
# File 'lib/lrama/lexer/token.rb', line 7 def line @line end |
#references ⇒ Object
For User_code
9 10 11 |
# File 'lib/lrama/lexer/token.rb', line 9 def references @references end |
#referred ⇒ Object
Returns the value of attribute referred.
7 8 9 |
# File 'lib/lrama/lexer/token.rb', line 7 def referred @referred end |
#s_value ⇒ Object
Returns the value of attribute s_value
3 4 5 |
# File 'lib/lrama/lexer/token/type.rb', line 3 def s_value @s_value end |
#type ⇒ Object
Returns the value of attribute type
3 4 5 |
# File 'lib/lrama/lexer/token/type.rb', line 3 def type @type end |
Class Method Details
.define_type(name) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/lrama/lexer/token.rb', line 49 def self.define_type(name) type = Type.new(id: @i, name: name.to_s) const_set(name, type) @types << type @i += 1 end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/lrama/lexer/token.rb', line 19 def ==(other) self.class == other.class && self.type == other.type && self.s_value == other.s_value end |
#numberize_references(lhs, rhs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lrama/lexer/token.rb', line 23 def numberize_references(lhs, rhs) self.references.map! {|ref| ref_name = ref[1] if ref_name.is_a?(::String) && ref_name != '$' value = if lhs.referred_by?(ref_name) '$' else index = rhs.find_index {|token| token.referred_by?(ref_name) } if index index + 1 else raise "'#{ref_name}' is invalid name." end end [ref[0], value, ref[2], ref[3], ref[4]] else ref end } end |
#referred_by?(string) ⇒ Boolean
15 16 17 |
# File 'lib/lrama/lexer/token.rb', line 15 def referred_by?(string) [self.s_value, self.alias].include?(string) end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/lrama/lexer/token.rb', line 11 def to_s "#{super} line: #{line}, column: #{column}" end |