Class: CodeLexer::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/code-lexer/token.rb

Constant Summary collapse

SPECIAL_TOKEN_OPEN =
"¬"
SPECIAL_TOKEN_CLOSE =
"¬"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value) ⇒ Token

Returns a new instance of Token.



14
15
16
17
# File 'lib/code-lexer/token.rb', line 14

def initialize(type, value)
    @type = type
    self.value = value
end

Instance Attribute Details

#abstracted_valueObject

Returns the value of attribute abstracted_value.



12
13
14
# File 'lib/code-lexer/token.rb', line 12

def abstracted_value
  @abstracted_value
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/code-lexer/token.rb', line 10

def type
  @type
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.special(token) ⇒ Object



6
7
8
# File 'lib/code-lexer/token.rb', line 6

def self.special(token)
    "#{SPECIAL_TOKEN_OPEN}#{token}#{SPECIAL_TOKEN_CLOSE}"
end

Instance Method Details

#==(oth) ⇒ Object



38
39
40
# File 'lib/code-lexer/token.rb', line 38

def ==(oth)
    @type == oth.type && @value == oth.value && @abstracted_value == oth.abstracted_value
end

#to_sObject



30
31
32
33
34
35
36
# File 'lib/code-lexer/token.rb', line 30

def to_s
    if @abstracted_value != @value
        return "<#@type:#{@value.inspect}:#{@abstracted_value.inspect}>"
    else
        return "<#@type:#{@value.inspect}>"
    end
end