Class: Graphlyte::Lexing::Token

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/graphlyte/lexing/token.rb

Overview

A lexical token

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, lexeme, location, value: nil) ⇒ Token

Returns a new instance of Token.



15
16
17
18
19
20
# File 'lib/graphlyte/lexing/token.rb', line 15

def initialize(type, lexeme, location, value: nil)
  @type = type
  @lexeme = lexeme
  @value = value
  @location = location
end

Instance Attribute Details

#lexemeObject (readonly)

Returns the value of attribute lexeme.



11
12
13
# File 'lib/graphlyte/lexing/token.rb', line 11

def lexeme
  @lexeme
end

#locationObject (readonly)

Returns the value of attribute location.



11
12
13
# File 'lib/graphlyte/lexing/token.rb', line 11

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/graphlyte/lexing/token.rb', line 11

def type
  @type
end

Instance Method Details

#punctuator?(value) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/graphlyte/lexing/token.rb', line 26

def punctuator?(value)
  @type == :PUNCTUATOR && @lexeme == value
end

#valueObject



22
23
24
# File 'lib/graphlyte/lexing/token.rb', line 22

def value
  @value || @lexeme
end