Class: Graphlyte::Lexing::Token
- Inherits:
-
Object
- Object
- Graphlyte::Lexing::Token
- Extended by:
- Forwardable
- Defined in:
- lib/graphlyte/lexing/token.rb
Overview
A lexical token
Instance Attribute Summary collapse
-
#lexeme ⇒ Object
readonly
Returns the value of attribute lexeme.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, lexeme, location, value: nil) ⇒ Token
constructor
A new instance of Token.
- #punctuator?(value) ⇒ Boolean
- #value ⇒ Object
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
#lexeme ⇒ Object (readonly)
Returns the value of attribute lexeme.
11 12 13 |
# File 'lib/graphlyte/lexing/token.rb', line 11 def lexeme @lexeme end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
11 12 13 |
# File 'lib/graphlyte/lexing/token.rb', line 11 def location @location end |
#type ⇒ Object (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
26 27 28 |
# File 'lib/graphlyte/lexing/token.rb', line 26 def punctuator?(value) @type == :PUNCTUATOR && @lexeme == value end |
#value ⇒ Object
22 23 24 |
# File 'lib/graphlyte/lexing/token.rb', line 22 def value @value || @lexeme end |