Class: Nay::Token

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

Overview

Describes the output of the Lexer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, literal = nil) ⇒ Token

Returns a new instance of Token.



8
9
10
11
12
13
# File 'lib/nay/token.rb', line 8

def initialize(type, literal = nil)
  @type    = type.to_sym
  @literal = literal

  freeze
end

Instance Attribute Details

#literalObject (readonly)

Returns the value of attribute literal.



6
7
8
# File 'lib/nay/token.rb', line 6

def literal
  @literal
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/nay/token.rb', line 6

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



19
20
21
# File 'lib/nay/token.rb', line 19

def ==(other)
  other.type == type && other.literal == literal
end

#to_sObject



15
16
17
# File 'lib/nay/token.rb', line 15

def to_s
  "['#{type}', '#{literal}']"
end