Class: Lrama::Lexer::Token

Inherits:
Struct
  • Object
show all
Defined in:
lib/lrama/lexer/token.rb,
lib/lrama/lexer/token/type.rb

Defined Under Namespace

Classes: Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aliasObject

Returns the value of attribute alias

Returns:

  • (Object)

    the current value of alias



3
4
5
# File 'lib/lrama/lexer/token/type.rb', line 3

def alias
  @alias
end

#columnObject

Returns the value of attribute column.



7
8
9
# File 'lib/lrama/lexer/token.rb', line 7

def column
  @column
end

#lineObject

Returns the value of attribute line.



7
8
9
# File 'lib/lrama/lexer/token.rb', line 7

def line
  @line
end

#referencesObject

For User_code



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

def references
  @references
end

#referredObject

Returns the value of attribute referred.



7
8
9
# File 'lib/lrama/lexer/token.rb', line 7

def referred
  @referred
end

#s_valueObject

Returns the value of attribute s_value

Returns:

  • (Object)

    the current value of s_value



3
4
5
# File 'lib/lrama/lexer/token/type.rb', line 3

def s_value
  @s_value
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/lrama/lexer/token/type.rb', line 3

def type
  @type
end

Class Method Details

.define_type(name) ⇒ Object



49
50
51
52
53
54
# File 'lib/lrama/lexer/token.rb', line 49

def self.define_type(name)
  type = Type.new(id: @i, name: name.to_s)
  const_set(name, type)
  @types << type
  @i += 1
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  self.class == other.class && self.type == other.type && self.s_value == other.s_value
end

#numberize_references(lhs, rhs) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lrama/lexer/token.rb', line 23

def numberize_references(lhs, rhs)
  self.references.map! {|ref|
    ref_name = ref[1]
    if ref_name.is_a?(::String) && ref_name != '$'
      value =
        if lhs.referred_by?(ref_name)
          '$'
        else
          index = rhs.find_index {|token| token.referred_by?(ref_name) }

          if index
            index + 1
          else
            raise "'#{ref_name}' is invalid name."
          end
        end
      [ref[0], value, ref[2], ref[3], ref[4]]
    else
      ref
    end
  }
end

#referred_by?(string) ⇒ Boolean

Returns:

  • (Boolean)


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

def referred_by?(string)
  [self.s_value, self.alias].include?(string)
end

#to_sObject



11
12
13
# File 'lib/lrama/lexer/token.rb', line 11

def to_s
  "#{super} line: #{line}, column: #{column}"
end