activefacts-cql 1.9.6 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,253 +0,0 @@
1
- #
2
- # ActiveFacts CQL Parser.
3
- # Various lexical rules for CQL.
4
- #
5
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
6
- #
7
- module ActiveFacts
8
- module CQL
9
- grammar LexicalRules
10
-
11
- rule range
12
- (numeric_range / string_range)
13
- {
14
- def node_type; :literal; end
15
- }
16
- end
17
-
18
- rule numeric_range
19
- number s tail:( '..' s end:number? s )?
20
- {
21
- def value
22
- if !tail.empty?
23
- last = tail.end.value unless tail.end.empty?
24
- [ number.value, last ]
25
- else
26
- number.value
27
- end
28
- end
29
- }
30
- / '..' s number s
31
- {
32
- def value
33
- [ nil, number.value ]
34
- end
35
- }
36
- end
37
-
38
- rule string_range
39
- string s tail:( '..' s end:string? s )?
40
- {
41
- # Ranges require the original text of the string, not the content:
42
- def value
43
- first = string.text_value
44
- if !tail.empty?
45
- last = tail.end.text_value unless tail.end.empty?
46
- [ first, last ]
47
- else
48
- first
49
- end
50
- end
51
- }
52
- / '..' s string s
53
- {
54
- def value
55
- [ nil, string.value ]
56
- end
57
- }
58
- end
59
-
60
- rule url
61
- # url_scheme ':' (user ( ':' !(port '/') password )? '@' )? hostname ( ':' port )? '/' path query? fragment?
62
- ( !(white / ';') .)+
63
- {
64
- def node_type; :literal; end
65
- }
66
- end
67
-
68
- rule literal
69
- ( boolean_literal
70
- / string
71
- / number
72
- ) s
73
- {
74
- def value
75
- elements[0].value
76
- end
77
- def node_type; :literal; end
78
- }
79
- end
80
-
81
- rule boolean_literal
82
- ( true { def value; true; end }
83
- / false { def value; false; end }
84
- ) !alphanumeric
85
- {
86
- def value; elements[0].value end
87
- }
88
- end
89
-
90
- rule string
91
- "'" (string_char)* "'"
92
- {
93
- def value
94
- text_value
95
- eval(text_value.sub(/\A'(.*)'\Z/,'"\1"'))
96
- end
97
- }
98
- end
99
-
100
- rule number
101
- ( real /
102
- fractional_real /
103
- hexnumber /
104
- octalnumber
105
- ) !alphanumeric
106
- {
107
- def value
108
- eval(text_value)
109
- end
110
- def node_type; :literal; end
111
- }
112
- end
113
-
114
- # All purely lexical rules from here down, no-one looks at the structure, just the text_value:
115
-
116
- rule string_char
117
- ( '\\' [befntr\\']
118
- / '\\' [0-7] [0-7] [0-7]
119
- / '\\' [\r]* [\n] [\r]*
120
- / '\\0'
121
- / '\\x' [0-9A-Fa-f] [0-9A-Fa-f]
122
- / '\\u' [0-9A-Fa-f] [0-9A-Fa-f] [0-9A-Fa-f] [0-9A-Fa-f]
123
- / (![\'\\\0-\x07\x0A-\x1F] .)
124
- )
125
- end
126
-
127
- rule real
128
- [-+]? [1-9] [0-9]* fraction? exponent?
129
- end
130
-
131
- rule fractional_real
132
- [-+]? '0' fraction exponent?
133
- end
134
-
135
- rule fraction
136
- radix_point [0-9]+
137
- end
138
-
139
- rule exponent
140
- ( [Ee] [-+]? [0-9]+ )
141
- end
142
-
143
- rule hexnumber
144
- '0x' [0-9A-Fa-f]+
145
- end
146
-
147
- rule octalnumber
148
- '0' [0-7]*
149
- end
150
-
151
- rule mul_op
152
- '/' / '%' / '*'
153
- end
154
-
155
- rule id
156
- alpha alphanumeric*
157
- { def value; text_value; end }
158
- end
159
-
160
- rule alpha
161
- [[:alpha:]_]
162
- end
163
-
164
- rule alphanumeric
165
- alpha / [0-9]
166
- end
167
-
168
- rule s # Optional space
169
- S?
170
- end
171
-
172
- rule S # Mandatory space
173
- (white / comment_to_eol / comment_c_style)+
174
- end
175
-
176
- rule white
177
- [ \t\n\r]+
178
- end
179
-
180
- rule comment_to_eol
181
- '//' (!"\n" .)*
182
- {
183
- def node_type; :comment; end
184
- }
185
- end
186
-
187
- rule comment_c_style
188
- '/*' (!'*/' . )* '*/'
189
- {
190
- def node_type; :comment; end
191
- }
192
- end
193
-
194
- rule regular_expression
195
- '/' !'/' regular_expression_contents '/'
196
- {
197
- def contents
198
- regular_expression_contents.text_value
199
- end
200
- }
201
- end
202
-
203
- rule regular_expression_contents
204
- regular_expression_alternate ( '|' regular_expression_alternate )*
205
- end
206
-
207
- rule regular_expression_alternate
208
- regular_expression_sequence
209
- end
210
-
211
- rule regular_expression_sequence
212
- regular_expression_atom*
213
- end
214
-
215
- rule regular_expression_atom
216
- (
217
- '[' character_classes ']'
218
- / regular_expression_group
219
- / ![*+?()|/] string_char
220
- ) regular_expression_multiplicity?
221
- end
222
-
223
- rule character_classes
224
- character_class+
225
- end
226
-
227
- rule character_class
228
- !']' string_char '-' !']' string_char
229
- / '-'
230
- / !']' string_char
231
- end
232
-
233
- rule regular_expression_multiplicity
234
- '*' / '+' / '?'
235
- end
236
-
237
- rule regular_expression_group
238
- '('
239
- regular_expression_group_extension?
240
- regular_expression_contents
241
- ')'
242
- end
243
-
244
- rule regular_expression_group_extension
245
- '?' (
246
- '<' ( !'>' .)+ '>' # A tag for a regular expression group
247
- # REVISIT: Add more group extensions as needed
248
- )
249
- end
250
-
251
- end
252
- end
253
- end
@@ -1,209 +0,0 @@
1
- #
2
- # ActiveFacts CQL Parser.
3
- # Parse rules relating to ObjectType definitions.
4
- #
5
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
6
- #
7
- module ActiveFacts
8
- module CQL
9
- grammar ObjectTypes
10
- rule object_type
11
- value_type
12
- / entity_type
13
- / fact_type
14
- end
15
-
16
- rule entity_type
17
- s each?
18
- s term_definition_name
19
- m1:mapping_pragmas
20
- c:context_note?
21
- sup:(basetype / subtype)
22
- &{|s|
23
- # There's an implicit type when we use an identification mode, register it:
24
- mode = s[6].identification_mode
25
- if mode
26
- input.context.object_type(s[3].value+mode, "identification mode type")
27
- input.context.object_type(s[3].value+' '+mode, "identification mode type")
28
- end
29
- true
30
- }
31
- m2:mapping_pragmas
32
- c2:context_note?
33
- ec:entity_clauses?
34
- ';'
35
- {
36
- def ast
37
- name = term_definition_name.value
38
- clauses_ast = ec.empty? ? [] : ec.ast
39
- pragmas = m1.value+m2.value
40
- pragmas << 'independent' if sup.independent
41
- context_note = !c.empty? ? c.ast : (!c2.empty? ? c2.ast : nil)
42
- Compiler::EntityType.new name, sup.supers, sup.ast, pragmas, clauses_ast, context_note
43
- end
44
- }
45
- end
46
-
47
- rule basetype
48
- basetype_expression
49
- {
50
- def ast; identification.ast; end
51
- def supers; []; end
52
- def identification_mode; identification.mode; end
53
- def independent; !i.empty?; end
54
- }
55
- end
56
-
57
- rule subtype
58
- subtype_expression
59
- {
60
- def ast; ident.empty? ? nil : ident.ast; end
61
- def supers; supertype_list.value; end
62
- def identification_mode; ident.empty? ? nil : ident.mode; end
63
- def independent; !i.empty?; end
64
- }
65
- end
66
-
67
- rule supertype_list
68
- primary:term s alternate_supertypes:( (','/'and' !alpha) s !identified_by name:term s )*
69
- {
70
- def value
71
- [primary.value, *alternate_supertypes.elements.map { |sup| sup.name.value } ]
72
- end
73
- }
74
- end
75
-
76
- rule identification
77
- # REVISIT: Consider distinguishing "-Id" from just "Id", and not prepending the entity type name if no "-"
78
- identified_by its s i:(term/implicit_value_type_name) value_type_parameters
79
- r:(value_constraint enforcement)? # Reference Mode; value_constraint may be needed for the ValueType
80
- {
81
- def ast
82
- if r.empty?
83
- value_constraint = nil
84
- else
85
- value_constraint = Compiler::ValueConstraint.new(r.value_constraint.ast, r.enforcement.ast)
86
- end
87
- Compiler::ReferenceMode.new(i.value, value_constraint, value_type_parameters.values)
88
- end
89
-
90
- def mode
91
- i.value
92
- end
93
- }
94
- /
95
- identified_by role_list # REVISIT: We'd like to be able to use implicit_value_type_names here too.
96
- &{|s|
97
- role_list = s[-1]
98
- forwards = role_list.ast.
99
- map do |role|
100
- next nil if role.is_a?(Compiler::Clause) # Can't forward-reference unaries
101
- next nil if role.leading_adjective or role.trailing_adjective
102
- role.term
103
- end.
104
- compact
105
- input.context.allowed_forward_terms(forwards)
106
- true
107
- }
108
- {
109
- def ast
110
- role_list.ast
111
- end
112
-
113
- def mode
114
- nil
115
- end
116
- }
117
- end
118
-
119
- # Identified by roles... also used for constraints, beware
120
- rule role_list
121
- a:any? s
122
- head:term_or_unary s
123
- tail:(
124
- ( and S / ',' s )
125
- any? s
126
- term_or_unary s
127
- )*
128
- {
129
- def ast
130
- [head.ast, *tail.elements.map{|e| e.term_or_unary.ast}]
131
- end
132
- }
133
- end
134
-
135
- rule unary_text
136
- (s !any !non_phrase !term id)*
137
- {
138
- def node_type; :linking; end
139
- }
140
- end
141
-
142
- rule term_or_unary
143
- pre_text:unary_text s term post_text:unary_text s ss:subscript?
144
- {
145
- def ast
146
- t = term.ast
147
- t.role_name = ss.value if !ss.empty?
148
- if pre_text.elements.size == 0 && post_text.elements.size == 0
149
- t
150
- else
151
- pre_words = pre_text.elements.map{|w| w.id.text_value}
152
- post_words = post_text.elements.map{|w| w.id.text_value}
153
- Compiler::Clause.new(pre_words + [t] + post_words, [], nil)
154
- end
155
- end
156
- }
157
- /
158
- s !non_phrase id s &non_phrase s ss:subscript?
159
- { # A forward-referenced entity type
160
- # REVISIT: A change in this rule might allow forward-referencing a multi-word term
161
- def ast
162
- Compiler::Reference.new(id.text_value, nil, nil, nil, nil, ss.empty? ? nil : ss.value)
163
- end
164
- }
165
- end
166
-
167
- rule mapping_pragmas
168
- '[' s h:mapping_pragma t:(s ',' s mapping_pragma)* s ']' s
169
- {
170
- def value
171
- t.elements.inject([h.value*' ']) do |a, e|
172
- a << e.mapping_pragma.value*' '
173
- end
174
- end
175
- }
176
- /
177
- s
178
- { def value; []; end }
179
- end
180
-
181
- # Each mapping_pragma returns an array of words
182
- rule mapping_pragma
183
- was s names:(id s)+
184
- { # Old or previous name of an object type:
185
- def value
186
- [ was.text_value ] + names.elements.map{|n|n.text_value}
187
- end
188
- }
189
- /
190
- head:id tail:(s id)*
191
- { # A sequence of one or more words denoting a pragma:
192
- def value
193
- ([head]+tail.elements.map(&:id)).map(&:text_value)
194
- end
195
- }
196
- end
197
-
198
- rule entity_clauses
199
- (':' / where) s query_clauses
200
- {
201
- def ast
202
- query_clauses.ast
203
- end
204
- }
205
- end
206
-
207
- end
208
- end
209
- end