Class: DDQL::Token
- Inherits:
-
Object
- Object
- DDQL::Token
- Defined in:
- lib/ddql/token.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#location ⇒ Object
Returns the value of attribute location.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #and? ⇒ Boolean
- #as_hash ⇒ Object
- #comparison? ⇒ Boolean
- #complex_comparison? ⇒ Boolean
- #infix? ⇒ Boolean
-
#initialize(data:, location: nil, type:) ⇒ Token
constructor
A new instance of Token.
- #math? ⇒ Boolean
- #op_data ⇒ Object
- #or? ⇒ Boolean
- #parse(parser, expression: nil) ⇒ Object
- #post_process(parser:, expression:) ⇒ Object
- #postfix? ⇒ Boolean
- #prefix? ⇒ Boolean
- #simple_comparison? ⇒ Boolean
- #supports_post_processing? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
- #type?(token_type) ⇒ Boolean
Constructor Details
#initialize(data:, location: nil, type:) ⇒ Token
Returns a new instance of Token.
10 11 12 13 14 |
# File 'lib/ddql/token.rb', line 10 def initialize(data:, location: nil, type:) @data = data @location = location @type = type end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/ddql/token.rb', line 5 def data @data end |
#location ⇒ Object
Returns the value of attribute location.
6 7 8 |
# File 'lib/ddql/token.rb', line 6 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/ddql/token.rb', line 5 def type @type end |
Instance Method Details
#and? ⇒ Boolean
16 17 18 |
# File 'lib/ddql/token.rb', line 16 def and? data == 'AND' end |
#as_hash ⇒ Object
20 21 22 |
# File 'lib/ddql/token.rb', line 20 def as_hash type.as_hash(data) end |
#comparison? ⇒ Boolean
24 25 26 |
# File 'lib/ddql/token.rb', line 24 def comparison? type.comparison?(data) end |
#complex_comparison? ⇒ Boolean
28 29 30 |
# File 'lib/ddql/token.rb', line 28 def complex_comparison? type.complex_comparison?(data) end |
#infix? ⇒ Boolean
32 33 34 |
# File 'lib/ddql/token.rb', line 32 def infix? type.infix? end |
#math? ⇒ Boolean
36 37 38 |
# File 'lib/ddql/token.rb', line 36 def math? type.math?(data) end |
#op_data ⇒ Object
40 41 42 |
# File 'lib/ddql/token.rb', line 40 def op_data data.squish end |
#or? ⇒ Boolean
44 45 46 |
# File 'lib/ddql/token.rb', line 44 def or? data == 'OR' end |
#parse(parser, expression: nil) ⇒ Object
48 49 50 |
# File 'lib/ddql/token.rb', line 48 def parse(parser, expression: nil) type.parse(parser, self, expression: expression) end |
#post_process(parser:, expression:) ⇒ Object
52 53 54 55 |
# File 'lib/ddql/token.rb', line 52 def post_process(parser:, expression:) raise "#{type} doesn't support post-processing" unless supports_post_processing? type.post_process(parser: parser, expression: expression) end |
#postfix? ⇒ Boolean
57 58 59 |
# File 'lib/ddql/token.rb', line 57 def postfix? type.postfix? end |
#prefix? ⇒ Boolean
61 62 63 |
# File 'lib/ddql/token.rb', line 61 def prefix? type.prefix? end |
#simple_comparison? ⇒ Boolean
65 66 67 |
# File 'lib/ddql/token.rb', line 65 def simple_comparison? type.simple_comparison?(data) end |
#supports_post_processing? ⇒ Boolean
69 70 71 |
# File 'lib/ddql/token.rb', line 69 def supports_post_processing? type.supports_post_processing? end |
#to_h ⇒ Object
73 74 75 |
# File 'lib/ddql/token.rb', line 73 def to_h type.as_hash(data) end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/ddql/token.rb', line 77 def to_s "#{type.name} : #{data}" end |
#type?(token_type) ⇒ Boolean
81 82 83 |
# File 'lib/ddql/token.rb', line 81 def type?(token_type) token_type == type end |