Class: Lox::Token

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#lexemeObject (readonly)

Returns the value of attribute lexeme.



16
17
18
# File 'lib/loxby/helpers/token_type.rb', line 16

def lexeme
  @lexeme
end

#lineObject (readonly)

Returns the value of attribute line.



16
17
18
# File 'lib/loxby/helpers/token_type.rb', line 16

def line
  @line
end

#literalObject (readonly)

Returns the value of attribute literal.



16
17
18
# File 'lib/loxby/helpers/token_type.rb', line 16

def literal
  @literal
end

#typeObject (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

#inspectObject



26
# File 'lib/loxby/helpers/token_type.rb', line 26

def inspect = "#<Lox::Token #{self}>"

#to_sObject



25
# File 'lib/loxby/helpers/token_type.rb', line 25

def to_s = "#{type} #{lexeme} #{literal}"