class Token

This class generates a token object with three parameters:

Author

Massimiliano Dal Mas (max.codeware@gmail.com)

License

Distributed under MIT license

Constants

OPERATORS
VARIABLE

Public Class Methods

new(to_token,pos,sugg = "") click to toggle source

Creates a new token object

  • argument: token value to name

  • argument: token position

  • argument: 'suggestion' (string) to force a specific attribute. “” default

# File lib/linmeric/Token.rb, line 25
def initialize(to_token,pos,sugg = "")
  @My_pos = pos
  if OPERATORS.include? to_token then    
    @My_att = "OPERATOR" unless [">","=","+","-"].include? to_token
    @My_att = "EQUAL_OP" if to_token == "="
    @My_att = "TO_FILE_OP" if to_token == ">"
    @My_att = "SUM_OPERATOR" if '+-'.include? to_token
  elsif sugg != ""
    @My_att = sugg
  elsif to_token == "~"
    @My_att = "EQUALS_TO"
  elsif to_token.include? ":" then
    @My_att = "KEYWORD"
  elsif to_token.match(VARIABLE).to_s.size == to_token.size then
    @My_att = "VARIABLE"
  elsif to_token.number? then
    @My_att = "NUMBER"
  elsif to_token == "(" then
    @My_att = "L_BRACE"
  elsif to_token == ")" then
    @My_att = "R_BRACE"
  elsif to_token == '"' then
    @My_att = "QUOTES"
  else
    @My_att = "GENERAL_STRING"
  end
  @My_self = (to_token.include? ':') ? (to_token.downcase) : (to_token)
end

Public Instance Methods

attribute() click to toggle source
  • returns: token attribute

# File lib/linmeric/Token.rb, line 55
def attribute
  return @My_att
end
me() click to toggle source
  • returns: token value

# File lib/linmeric/Token.rb, line 65
def me
  return @My_self
end
position() click to toggle source
  • returns: token position

# File lib/linmeric/Token.rb, line 60
def position
  return @My_pos
end