class Calcula::Token

A token that is created by the lexer and can be recognized by the parser.

@author Paul T.

Attributes

id[R]

@return [Symbol] Returns the type of the token

text[R]

@return [String] Returns the string segment from the source

Public Class Methods

new(id, text) click to toggle source

Constructs a new Token that can be used with `Calcula::Parser`

@param id [symbol] The type of the Token @param text [string] The actual text

# File lib/Token.rb, line 16
def initialize(id, text)
  @id = id
  @text = text
end

Public Instance Methods

dup() click to toggle source

Duplicates a token

@return [Calcula::Token] A duplicate of the token

# File lib/Token.rb, line 31
def dup
  Token.new(@id, @text)
end
to_s() click to toggle source

Converts the token into a format of `[:id => :text]`

@return [String] The string representation of the Token in above format

# File lib/Token.rb, line 24
def to_s
  return "[#{@id}=>#{text}]"
end