Class: Rhetor::Token

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

Overview

Token class represents tokens matched from the input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#lengthInteger (readonly)

the length of the matched substring

Returns:

  • (Integer)

    the current value of length



9
10
11
# File 'lib/rhetor/token.rb', line 9

def length
  @length
end

#nameSymbol (readonly)

the name of the matched rule

Returns:

  • (Symbol)

    the current value of name



9
10
11
# File 'lib/rhetor/token.rb', line 9

def name
  @name
end

#positionInteger (readonly)

the position of the matched substring

Returns:

  • (Integer)

    the current value of position



9
10
11
# File 'lib/rhetor/token.rb', line 9

def position
  @position
end

#valueObject (readonly)

the value of the token

Returns:

  • (Object)

    the current value of value



9
10
11
# File 'lib/rhetor/token.rb', line 9

def value
  @value
end

Instance Method Details

#to_sObject Also known as: inspect



10
11
12
# File 'lib/rhetor/token.rb', line 10

def to_s
  "(#{name}: #{value.inspect} [#{position},#{length}])"
end