Class: DDQL::TokenType
- Inherits:
-
Object
show all
- Defined in:
- lib/ddql/token_type.rb
Direct Known Subclasses
Factor, Group, Literal, NestedQuery, Operator, Screen, SubQuery, SubQueryAlias, SubQueryCloser, SubQueryExpression, SubQueryFields, SubQueryGrouping, SubQueryType
Defined Under Namespace
Classes: Currency, Factor, Group, InfixOperator, Integer, Literal, NestedQuery, NullOperators, Numeric, Operator, PostfixOperator, PrefixOperator, Query, ScientificNumeric, Screen, SpecialMarker, String, SubQuery, SubQueryAlias, SubQueryCloser, SubQueryExpression, SubQueryFields, SubQueryGrouping, SubQueryType
Constant Summary
collapse
- FACTOR_PATTERN =
/\[[^\]]+\]/
- NESTED_OPEN_PATTERN =
'‹'
- NESTED_CLOSE_PATTERN =
'›'
- NESTED_OPENER =
NestedQuery.new
- NESTED_CLOSER =
new(name: :nested_closer, pattern: Regexp.compile(Regexp.escape TokenType::NESTED_CLOSE_PATTERN))
- LPAREN =
Group.new
- RPAREN =
new(name: :rparen, pattern: /(?=[^%])\)/)
- LBRACE =
new(name: :lbrace, pattern: /{/)
SubQuery.new
- RBRACE =
(name: :rbrace, pattern: /}/)
SubQueryCloser.new
- CURRENCY_LITERAL =
TODO: Not used in DataDesk due to some bug. Should we implement and fix? LCAPTURE = new(name: :lcapture, pattern: /(%/) RCAPTURE = new(name: :rcapture, pattern: /%)/)
Currency.new
- INTEGER_LITERAL =
Integer.new
- SCI_NUM_LITERAL =
ScientificNumeric.new
- NUMERIC_LITERAL =
Numeric.new
- STRING_LITERAL =
String.new
- SCREEN =
Screen.new
- FACTOR =
Factor.new
- SPECIAL_MARKER =
SpecialMarker.new
- PREFIXOPERATOR =
PrefixOperator.new
- INFIXOPERATOR =
InfixOperator.new
- POSTFIXOPERATOR =
PostfixOperator.new
- SUB_Q_ALIAS =
SubQueryAlias.new
- SUB_Q_EXPR =
SubQueryExpression.new
- SUB_Q_FIELDS =
SubQueryFields.new
- SUB_Q_GROUP =
SubQueryGrouping.new
- SUB_Q_TYPE =
SubQueryType.new
- WHITESPACE =
new(name: :whitespace, pattern: /[\s]/).skipping!
- ALL =
[
NESTED_OPENER,
NESTED_CLOSER,
LPAREN,
RPAREN,
LBRACE,
RBRACE,
SUB_Q_EXPR,
SUB_Q_FIELDS,
SUB_Q_TYPE,
SUB_Q_ALIAS,
SUB_Q_GROUP,
CURRENCY_LITERAL,
SCI_NUM_LITERAL,
INTEGER_LITERAL,
NUMERIC_LITERAL,
STRING_LITERAL,
SCREEN,
FACTOR,
SPECIAL_MARKER,
PREFIXOPERATOR,
INFIXOPERATOR,
POSTFIXOPERATOR,
WHITESPACE,
]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name:, pattern:, &block) ⇒ TokenType
Returns a new instance of TokenType.
15
16
17
18
19
20
21
22
|
# File 'lib/ddql/token_type.rb', line 15
def initialize(name:, pattern:, &block)
@label = name.to_s
@name = name
@pattern = pattern
@skipping = false
@data_range = 0..-1
@value_transformer = block
end
|
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
3
4
5
|
# File 'lib/ddql/token_type.rb', line 3
def label
@label
end
|
#name ⇒ Object
Returns the value of attribute name.
3
4
5
|
# File 'lib/ddql/token_type.rb', line 3
def name
@name
end
|
#pattern ⇒ Object
Returns the value of attribute pattern.
3
4
5
|
# File 'lib/ddql/token_type.rb', line 3
def pattern
@pattern
end
|
Class Method Details
.all_types_pattern ⇒ Object
11
12
13
|
# File 'lib/ddql/token_type.rb', line 11
def self.all_types_pattern
@pattern ||= Regexp.compile(ALL.map { |tt| "(?<#{tt.name}>#{tt.pattern})" }.join('|'))
end
|
Instance Method Details
#==(other) ⇒ Object
24
25
26
|
# File 'lib/ddql/token_type.rb', line 24
def ==(other)
name == other.name
end
|
#as_hash(data) ⇒ Object
28
29
30
|
# File 'lib/ddql/token_type.rb', line 28
def as_hash(data)
raise "subclass responsibility name[#{name}] data[#{data}]"
end
|
#comparison?(data) ⇒ Boolean
32
33
34
|
# File 'lib/ddql/token_type.rb', line 32
def comparison?(data)
false
end
|
#data_from(match_data:) ⇒ Object
36
37
38
|
# File 'lib/ddql/token_type.rb', line 36
def data_from(match_data:)
match_data.named_captures[label]
end
|
#expression? ⇒ Boolean
40
41
42
|
# File 'lib/ddql/token_type.rb', line 40
def expression?
false
end
|
#factor? ⇒ Boolean
44
45
46
|
# File 'lib/ddql/token_type.rb', line 44
def factor?
false
end
|
#group? ⇒ Boolean
48
49
50
|
# File 'lib/ddql/token_type.rb', line 48
def group?
false
end
|
#infix? ⇒ Boolean
52
53
54
|
# File 'lib/ddql/token_type.rb', line 52
def infix?
false
end
|
#interpret(data) ⇒ Object
56
57
58
59
60
|
# File 'lib/ddql/token_type.rb', line 56
def interpret(data)
return nil if data.nil?
return data[@data_range] if @value_transformer.nil?
@value_transformer.call(data[@data_range])
end
|
#interpreted_data_from(match_data:) ⇒ Object
62
63
64
65
66
|
# File 'lib/ddql/token_type.rb', line 62
def interpreted_data_from(match_data:)
data = data_from match_data: match_data
return nil if data.nil?
interpret data
end
|
#literal? ⇒ Boolean
68
69
70
|
# File 'lib/ddql/token_type.rb', line 68
def literal?
false
end
|
#match?(match_data:) ⇒ Boolean
72
73
74
|
# File 'lib/ddql/token_type.rb', line 72
def match?(match_data:)
data_from(match_data: match_data).nil? || @skipping ? false : true
end
|
#parse(parser, token, expression: nil) ⇒ Object
76
77
78
|
# File 'lib/ddql/token_type.rb', line 76
def parse(parser, token, expression: nil)
as_hash(token.data)
end
|
#postfix? ⇒ Boolean
80
81
82
|
# File 'lib/ddql/token_type.rb', line 80
def postfix?
false
end
|
#prefix? ⇒ Boolean
84
85
86
|
# File 'lib/ddql/token_type.rb', line 84
def prefix?
false
end
|
#screen? ⇒ Boolean
88
89
90
|
# File 'lib/ddql/token_type.rb', line 88
def screen?
false
end
|
#skipping! ⇒ Object
92
93
94
95
|
# File 'lib/ddql/token_type.rb', line 92
def skipping!
@skipping = true
self
end
|
#supports_post_processing? ⇒ Boolean
97
98
99
|
# File 'lib/ddql/token_type.rb', line 97
def supports_post_processing?
false
end
|
#trimming!(range = (1..-2)) ⇒ Object
101
102
103
104
|
# File 'lib/ddql/token_type.rb', line 101
def trimming!(range=(1..-2))
@data_range = range
self
end
|