Class: Kumi::Parser::Token
- Inherits:
-
Object
- Object
- Kumi::Parser::Token
- Defined in:
- lib/kumi/parser/token.rb
Overview
Token with embedded metadata for smart parsing
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#ast_class ⇒ Object
Direct AST construction hint.
-
#expects_block? ⇒ Boolean
Parser hints embedded in token.
- #identifier? ⇒ Boolean
-
#initialize(type, value, location, metadata = {}) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
-
#keyword? ⇒ Boolean
Semantic predicates embedded in token.
- #left_associative? ⇒ Boolean
- #literal? ⇒ Boolean
- #operator? ⇒ Boolean
-
#precedence ⇒ Object
Operator precedence embedded in token.
- #punctuation? ⇒ Boolean
- #right_associative? ⇒ Boolean
- #starts_expression? ⇒ Boolean
- #terminates_expression? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(type, value, location, metadata = {}) ⇒ Token
Returns a new instance of Token.
9 10 11 12 13 14 |
# File 'lib/kumi/parser/token.rb', line 9 def initialize(type, value, location, = {}) @type = type @value = value @location = location @metadata = end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
7 8 9 |
# File 'lib/kumi/parser/token.rb', line 7 def location @location end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/kumi/parser/token.rb', line 7 def @metadata end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/kumi/parser/token.rb', line 7 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/kumi/parser/token.rb', line 7 def value @value end |
Instance Method Details
#==(other) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/kumi/parser/token.rb', line 76 def ==(other) other.is_a?(Token) && @type == other.type && @value == other.value && @location == other.location end |
#ast_class ⇒ Object
Direct AST construction hint
64 65 66 |
# File 'lib/kumi/parser/token.rb', line 64 def ast_class @metadata[:ast_class] end |
#expects_block? ⇒ Boolean
Parser hints embedded in token
51 52 53 |
# File 'lib/kumi/parser/token.rb', line 51 def expects_block? @metadata[:expects_block] == true end |
#identifier? ⇒ Boolean
29 30 31 |
# File 'lib/kumi/parser/token.rb', line 29 def identifier? @metadata[:category] == :identifier end |
#inspect ⇒ Object
72 73 74 |
# File 'lib/kumi/parser/token.rb', line 72 def inspect to_s end |
#keyword? ⇒ Boolean
Semantic predicates embedded in token
17 18 19 |
# File 'lib/kumi/parser/token.rb', line 17 def keyword? @metadata[:category] == :keyword end |
#left_associative? ⇒ Boolean
42 43 44 |
# File 'lib/kumi/parser/token.rb', line 42 def left_associative? @metadata[:associativity] == :left end |
#literal? ⇒ Boolean
25 26 27 |
# File 'lib/kumi/parser/token.rb', line 25 def literal? @metadata[:category] == :literal end |
#operator? ⇒ Boolean
21 22 23 |
# File 'lib/kumi/parser/token.rb', line 21 def operator? @metadata[:category] == :operator end |
#precedence ⇒ Object
Operator precedence embedded in token
38 39 40 |
# File 'lib/kumi/parser/token.rb', line 38 def precedence @metadata[:precedence] || 0 end |
#punctuation? ⇒ Boolean
33 34 35 |
# File 'lib/kumi/parser/token.rb', line 33 def punctuation? @metadata[:category] == :punctuation end |
#right_associative? ⇒ Boolean
46 47 48 |
# File 'lib/kumi/parser/token.rb', line 46 def right_associative? @metadata[:associativity] == :right end |
#starts_expression? ⇒ Boolean
59 60 61 |
# File 'lib/kumi/parser/token.rb', line 59 def starts_expression? @metadata[:starts_expression] == true end |
#terminates_expression? ⇒ Boolean
55 56 57 |
# File 'lib/kumi/parser/token.rb', line 55 def terminates_expression? @metadata[:terminates_expression] == true end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/kumi/parser/token.rb', line 68 def to_s "#{@type}(#{@value.inspect}) at #{@location}" end |