Class: Baba::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/baba/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, lexeme, literal, line) ⇒ Token

Returns a new instance of Token.



5
6
7
8
9
10
# File 'lib/baba/token.rb', line 5

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.



3
4
5
# File 'lib/baba/token.rb', line 3

def lexeme
  @lexeme
end

#lineObject (readonly)

Returns the value of attribute line.



3
4
5
# File 'lib/baba/token.rb', line 3

def line
  @line
end

#literalObject (readonly)

Returns the value of attribute literal.



3
4
5
# File 'lib/baba/token.rb', line 3

def literal
  @literal
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/baba/token.rb', line 3

def type
  @type
end

Instance Method Details

#to_sObject



12
13
14
# File 'lib/baba/token.rb', line 12

def to_s
  return "#{@type} #{@lexeme} #{@literal}"
end