Class: Lox::Token
- Inherits:
-
Object
- Object
- Lox::Token
- Defined in:
- lib/loxby/helpers/token_type.rb
Overview
A single token. Emitted by ‘Lox::Scanner` and consumed by `Lox::Parser`.
Constant Summary collapse
- TOKENS =
List of all token types.
Lox.config.token_types.tokens
- SINGLE_TOKENS =
Map of single-character token types.
Lox.config.token_types.single_tokens
Instance Attribute Summary collapse
-
#lexeme ⇒ Object
readonly
Returns the value of attribute lexeme.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#literal ⇒ Object
readonly
Returns the value of attribute literal.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, lexeme, literal, line) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type, lexeme, literal, line) ⇒ Token
Returns a new instance of Token.
18 19 20 21 22 23 |
# File 'lib/loxby/helpers/token_type.rb', line 18 def initialize(type, lexeme, literal, line) @type = type @lexeme = lexeme @literal = literal @line = line end |
Instance Attribute Details
#lexeme ⇒ Object (readonly)
Returns the value of attribute lexeme.
16 17 18 |
# File 'lib/loxby/helpers/token_type.rb', line 16 def lexeme @lexeme end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
16 17 18 |
# File 'lib/loxby/helpers/token_type.rb', line 16 def line @line end |
#literal ⇒ Object (readonly)
Returns the value of attribute literal.
16 17 18 |
# File 'lib/loxby/helpers/token_type.rb', line 16 def literal @literal end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/loxby/helpers/token_type.rb', line 16 def type @type end |
Instance Method Details
#inspect ⇒ Object
26 |
# File 'lib/loxby/helpers/token_type.rb', line 26 def inspect = "#<Lox::Token #{self}>" |
#to_s ⇒ Object
25 |
# File 'lib/loxby/helpers/token_type.rb', line 25 def to_s = "#{type} #{lexeme} #{literal}" |