activefacts 1.6.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +3 -80
- data/activefacts.gemspec +36 -0
- data/bin/afgen +4 -2
- data/bin/cql +5 -1
- data/lib/activefacts.rb +3 -12
- data/lib/activefacts/{vocabulary/query_evaluator.rb → query/evaluator.rb} +0 -0
- data/lib/activefacts/version.rb +2 -2
- metadata +48 -296
- data/History.txt +0 -4
- data/LICENSE +0 -19
- data/Manifest.txt +0 -165
- data/README.rdoc +0 -81
- data/css/offline.css +0 -3
- data/css/orm2.css +0 -124
- data/css/print.css +0 -8
- data/css/style-print.css +0 -357
- data/css/style.css +0 -387
- data/download.html +0 -110
- data/examples/CQL/Address.cql +0 -44
- data/examples/CQL/Blog.cql +0 -54
- data/examples/CQL/CompanyDirectorEmployee.cql +0 -56
- data/examples/CQL/Death.cql +0 -17
- data/examples/CQL/Diplomacy.cql +0 -48
- data/examples/CQL/Genealogy.cql +0 -98
- data/examples/CQL/Insurance.cql +0 -320
- data/examples/CQL/Marriage.cql +0 -18
- data/examples/CQL/Metamodel.cql +0 -493
- data/examples/CQL/Monogamy.cql +0 -24
- data/examples/CQL/MultiInheritance.cql +0 -22
- data/examples/CQL/NonRoleId.cql +0 -14
- data/examples/CQL/OddIdentifier.cql +0 -18
- data/examples/CQL/OilSupply.cql +0 -53
- data/examples/CQL/OneToOnes.cql +0 -17
- data/examples/CQL/Orienteering.cql +0 -111
- data/examples/CQL/PersonPlaysGame.cql +0 -18
- data/examples/CQL/RedundantDependency.cql +0 -34
- data/examples/CQL/SchoolActivities.cql +0 -33
- data/examples/CQL/SeparateSubtype.cql +0 -30
- data/examples/CQL/ServiceDirector.cql +0 -276
- data/examples/CQL/SimplestUnary.cql +0 -12
- data/examples/CQL/Supervision.cql +0 -34
- data/examples/CQL/WaiterTips.cql +0 -33
- data/examples/CQL/Warehousing.cql +0 -101
- data/examples/CQL/WindowInRoomInBldg.cql +0 -28
- data/examples/CQL/unit.cql +0 -474
- data/examples/index.html +0 -420
- data/examples/intro.html +0 -327
- data/examples/local.css +0 -24
- data/index.html +0 -111
- data/lib/activefacts/cql.rb +0 -35
- data/lib/activefacts/cql/CQLParser.treetop +0 -158
- data/lib/activefacts/cql/Context.treetop +0 -48
- data/lib/activefacts/cql/Expressions.treetop +0 -67
- data/lib/activefacts/cql/FactTypes.treetop +0 -358
- data/lib/activefacts/cql/Language/English.treetop +0 -315
- data/lib/activefacts/cql/LexicalRules.treetop +0 -253
- data/lib/activefacts/cql/ObjectTypes.treetop +0 -210
- data/lib/activefacts/cql/Rakefile +0 -14
- data/lib/activefacts/cql/Terms.treetop +0 -183
- data/lib/activefacts/cql/ValueTypes.treetop +0 -202
- data/lib/activefacts/cql/compiler.rb +0 -156
- data/lib/activefacts/cql/compiler/clause.rb +0 -1137
- data/lib/activefacts/cql/compiler/constraint.rb +0 -581
- data/lib/activefacts/cql/compiler/entity_type.rb +0 -457
- data/lib/activefacts/cql/compiler/expression.rb +0 -443
- data/lib/activefacts/cql/compiler/fact.rb +0 -390
- data/lib/activefacts/cql/compiler/fact_type.rb +0 -421
- data/lib/activefacts/cql/compiler/query.rb +0 -106
- data/lib/activefacts/cql/compiler/shared.rb +0 -161
- data/lib/activefacts/cql/compiler/value_type.rb +0 -174
- data/lib/activefacts/cql/nodes.rb +0 -49
- data/lib/activefacts/cql/parser.rb +0 -241
- data/lib/activefacts/dependency_analyser.rb +0 -182
- data/lib/activefacts/generate/absorption.rb +0 -70
- data/lib/activefacts/generate/composition.rb +0 -118
- data/lib/activefacts/generate/cql.rb +0 -714
- data/lib/activefacts/generate/dm.rb +0 -279
- data/lib/activefacts/generate/help.rb +0 -64
- data/lib/activefacts/generate/helpers/inject.rb +0 -16
- data/lib/activefacts/generate/helpers/oo.rb +0 -162
- data/lib/activefacts/generate/helpers/ordered.rb +0 -605
- data/lib/activefacts/generate/helpers/rails.rb +0 -57
- data/lib/activefacts/generate/html/glossary.rb +0 -461
- data/lib/activefacts/generate/json.rb +0 -337
- data/lib/activefacts/generate/null.rb +0 -32
- data/lib/activefacts/generate/rails/models.rb +0 -246
- data/lib/activefacts/generate/rails/schema.rb +0 -216
- data/lib/activefacts/generate/records.rb +0 -46
- data/lib/activefacts/generate/ruby.rb +0 -133
- data/lib/activefacts/generate/sql/mysql.rb +0 -280
- data/lib/activefacts/generate/sql/server.rb +0 -273
- data/lib/activefacts/generate/stats.rb +0 -69
- data/lib/activefacts/generate/text.rb +0 -27
- data/lib/activefacts/generate/topics.rb +0 -265
- data/lib/activefacts/generate/traits/datavault.rb +0 -241
- data/lib/activefacts/generate/traits/oo.rb +0 -73
- data/lib/activefacts/generate/traits/ordered.rb +0 -33
- data/lib/activefacts/generate/traits/ruby.rb +0 -210
- data/lib/activefacts/generate/transform/datavault.rb +0 -266
- data/lib/activefacts/generate/transform/surrogate.rb +0 -214
- data/lib/activefacts/generate/version.rb +0 -26
- data/lib/activefacts/input/cql.rb +0 -43
- data/lib/activefacts/input/orm.rb +0 -1636
- data/lib/activefacts/mapping/rails.rb +0 -132
- data/lib/activefacts/persistence.rb +0 -15
- data/lib/activefacts/persistence/columns.rb +0 -446
- data/lib/activefacts/persistence/foreignkey.rb +0 -187
- data/lib/activefacts/persistence/index.rb +0 -240
- data/lib/activefacts/persistence/object_type.rb +0 -198
- data/lib/activefacts/persistence/reference.rb +0 -434
- data/lib/activefacts/persistence/tables.rb +0 -380
- data/lib/activefacts/registry.rb +0 -11
- data/lib/activefacts/support.rb +0 -132
- data/lib/activefacts/vocabulary.rb +0 -9
- data/lib/activefacts/vocabulary/extensions.rb +0 -1348
- data/lib/activefacts/vocabulary/metamodel.rb +0 -570
- data/lib/activefacts/vocabulary/verbaliser.rb +0 -804
- data/script/txt2html +0 -71
- data/spec/absorption_spec.rb +0 -95
- data/spec/cql/comparison_spec.rb +0 -89
- data/spec/cql/context_spec.rb +0 -94
- data/spec/cql/contractions_spec.rb +0 -224
- data/spec/cql/deontic_spec.rb +0 -88
- data/spec/cql/entity_type_spec.rb +0 -320
- data/spec/cql/expressions_spec.rb +0 -66
- data/spec/cql/fact_type_matching_spec.rb +0 -338
- data/spec/cql/french_spec.rb +0 -21
- data/spec/cql/parser/bad_literals_spec.rb +0 -86
- data/spec/cql/parser/constraints_spec.rb +0 -19
- data/spec/cql/parser/entity_types_spec.rb +0 -106
- data/spec/cql/parser/expressions_spec.rb +0 -199
- data/spec/cql/parser/fact_types_spec.rb +0 -44
- data/spec/cql/parser/literals_spec.rb +0 -312
- data/spec/cql/parser/pragmas_spec.rb +0 -89
- data/spec/cql/parser/value_types_spec.rb +0 -42
- data/spec/cql/role_matching_spec.rb +0 -148
- data/spec/cql/samples_spec.rb +0 -244
- data/spec/cql_cql_spec.rb +0 -73
- data/spec/cql_dm_spec.rb +0 -136
- data/spec/cql_mysql_spec.rb +0 -69
- data/spec/cql_parse_spec.rb +0 -34
- data/spec/cql_ruby_spec.rb +0 -73
- data/spec/cql_sql_spec.rb +0 -72
- data/spec/cql_symbol_tables_spec.rb +0 -261
- data/spec/cqldump_spec.rb +0 -170
- data/spec/helpers/array_matcher.rb +0 -23
- data/spec/helpers/ctrl_c_support.rb +0 -52
- data/spec/helpers/diff_matcher.rb +0 -39
- data/spec/helpers/file_matcher.rb +0 -34
- data/spec/helpers/parse_to_ast_matcher.rb +0 -80
- data/spec/helpers/string_matcher.rb +0 -30
- data/spec/helpers/test_parser.rb +0 -15
- data/spec/norma_cql_spec.rb +0 -66
- data/spec/norma_ruby_spec.rb +0 -62
- data/spec/norma_ruby_sql_spec.rb +0 -107
- data/spec/norma_sql_spec.rb +0 -57
- data/spec/norma_tables_spec.rb +0 -95
- data/spec/ruby_api_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -35
- data/spec/transform_surrogate_spec.rb +0 -59
- data/status.html +0 -138
- data/why.html +0 -60
@@ -1,358 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts CQL Parser.
|
3
|
-
# Parse rules relating to FactType definitions.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
|
6
|
-
#
|
7
|
-
module ActiveFacts
|
8
|
-
module CQL
|
9
|
-
grammar FactTypes
|
10
|
-
rule query
|
11
|
-
s query_clauses r:returning_clause? '?'
|
12
|
-
{
|
13
|
-
def ast
|
14
|
-
Compiler::FactType.new nil, [], query_clauses.ast, (r.empty? ? nil : r)
|
15
|
-
end
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
rule named_fact_type
|
20
|
-
s each?
|
21
|
-
s term_definition_name
|
22
|
-
mapping_pragmas is_where
|
23
|
-
anonymous_fact_type
|
24
|
-
{
|
25
|
-
def ast
|
26
|
-
ft = anonymous_fact_type.ast
|
27
|
-
ft.name = term_definition_name.value
|
28
|
-
pragmas = mapping_pragmas.value
|
29
|
-
pragmas << 'independent' if is_where.independent
|
30
|
-
ft.pragmas = pragmas
|
31
|
-
ft
|
32
|
-
end
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
rule anonymous_fact_type
|
37
|
-
query_clauses
|
38
|
-
ctail:( (':' / where) s a:query_clauses s)?
|
39
|
-
returning_clause?
|
40
|
-
s ';'
|
41
|
-
{
|
42
|
-
def ast
|
43
|
-
clauses_ast = query_clauses.ast
|
44
|
-
conditions = !ctail.empty? ? ctail.a.ast : []
|
45
|
-
returning = respond_to?(:returning_clause) ? returning_clause.ast : nil
|
46
|
-
value_derivation = clauses_ast.detect{|r| r.is_equality_comparison}
|
47
|
-
if !value_derivation and
|
48
|
-
conditions.empty? and
|
49
|
-
clauses_ast.detect{|r| r.includes_literals}
|
50
|
-
raise "Fact instances may not contain conditions" unless conditions.empty? && !returning
|
51
|
-
Compiler::Fact.new clauses_ast
|
52
|
-
elsif (clauses_ast.size == 1 &&
|
53
|
-
clauses_ast[0].phrases.size == 1 &&
|
54
|
-
(popname = clauses_ast[0].phrases[0]) &&
|
55
|
-
!popname.is_a?(Compiler::Reference) &&
|
56
|
-
conditions.detect{|r| r.includes_literals}
|
57
|
-
)
|
58
|
-
Compiler::Fact.new conditions, popname
|
59
|
-
else
|
60
|
-
Compiler::FactType.new nil, clauses_ast, conditions, returning
|
61
|
-
end
|
62
|
-
end
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
rule query_clauses
|
67
|
-
qualified_clauses
|
68
|
-
# REVISIT: This creates no precedence between and/or, which could cause confusion.
|
69
|
-
# Should disallow mixed conjuntions - using a sempred?
|
70
|
-
ftail:( conjunction:(',' / and / or ) s qualified_clauses s )*
|
71
|
-
{
|
72
|
-
def ast
|
73
|
-
clauses_ast = qualified_clauses.ast
|
74
|
-
ftail.elements.each{|e|
|
75
|
-
conjunction = e.conjunction.text_value
|
76
|
-
# conjunction = 'and' if conjunction == ',' # ',' means AND, but disallows left-contractions
|
77
|
-
clauses_ast += e.qualified_clauses.ast(conjunction)
|
78
|
-
}
|
79
|
-
clauses_ast
|
80
|
-
end
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
rule returning_clause
|
85
|
-
returning s return (s ',' s return)*
|
86
|
-
end
|
87
|
-
|
88
|
-
rule return
|
89
|
-
ordering_prefix? phrase+
|
90
|
-
end
|
91
|
-
|
92
|
-
rule qualified_clauses
|
93
|
-
s certainty s contracted_clauses s p:post_qualifiers? s c:context_note?
|
94
|
-
{
|
95
|
-
def ast(conjunction = nil)
|
96
|
-
r = contracted_clauses.ast # An array of clause asts
|
97
|
-
r[0].conjunction = conjunction
|
98
|
-
# pre-qualifiers apply to the first clause, post_qualifiers and context_note to the last
|
99
|
-
# REVISIT: This may be incorrect where the last is a nested clause
|
100
|
-
r[0].certainty = certainty.value
|
101
|
-
r[-1].qualifiers += p.list unless p.empty?
|
102
|
-
r[-1].context_note = c.ast unless c.empty?
|
103
|
-
r
|
104
|
-
end
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
|
-
rule certainty
|
109
|
-
negative_prefix { def value; false; end }
|
110
|
-
/
|
111
|
-
maybe { def value; nil; end }
|
112
|
-
/
|
113
|
-
definitely { def value; true; end }
|
114
|
-
/
|
115
|
-
'' { def value; true; end }
|
116
|
-
end
|
117
|
-
|
118
|
-
rule post_qualifiers
|
119
|
-
'[' s q0:post_qualifier tail:( s ',' s q1:post_qualifier )* s ']' s
|
120
|
-
{
|
121
|
-
def list
|
122
|
-
[q0.text_value, *tail.elements.map{|e| e.q1.text_value}]
|
123
|
-
end
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
127
|
-
rule post_qualifier
|
128
|
-
static / transient /
|
129
|
-
intransitive / stronglyintransitive / transitive / acyclic / symmetric / asymmetric / antisymmetric / reflexive / irreflexive
|
130
|
-
end
|
131
|
-
|
132
|
-
rule clauses_list
|
133
|
-
clauses tail:( ',' s clauses )*
|
134
|
-
{
|
135
|
-
def ast
|
136
|
-
[clauses.ast, *tail.elements.map{|e| e.clauses.ast }]
|
137
|
-
end
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
|
-
rule clauses
|
142
|
-
contracted_clauses s tail:( and s contracted_clauses s )*
|
143
|
-
{
|
144
|
-
def ast
|
145
|
-
clauses = contracted_clauses.ast
|
146
|
-
tail.elements.map{|e| clauses += e.contracted_clauses.ast }
|
147
|
-
clauses
|
148
|
-
end
|
149
|
-
}
|
150
|
-
end
|
151
|
-
|
152
|
-
rule contracted_clauses
|
153
|
-
comparison
|
154
|
-
/
|
155
|
-
(
|
156
|
-
contraction # A contraction will terminate this repetition by eating to the end
|
157
|
-
/
|
158
|
-
phrase
|
159
|
-
)+
|
160
|
-
{
|
161
|
-
def ast
|
162
|
-
asts = elements.map{ |r| r.ast }
|
163
|
-
contracted_clauses = []
|
164
|
-
qualifiers = []
|
165
|
-
if asts[-1].is_a?(Array) # A contraction (Array of [role, qualifiers, *clauses])
|
166
|
-
contracted_clauses = asts.pop # Pull off the contracted_clauses
|
167
|
-
contracted_role = contracted_clauses.shift
|
168
|
-
qualifiers = contracted_clauses.shift
|
169
|
-
asts.push(contracted_role) # And replace it by the role removed from the contracted_clauses
|
170
|
-
end
|
171
|
-
clause_ast = Compiler::Clause.new(asts, qualifiers)
|
172
|
-
[clause_ast] + contracted_clauses
|
173
|
-
end
|
174
|
-
}
|
175
|
-
end
|
176
|
-
|
177
|
-
rule contraction
|
178
|
-
reading_contraction /
|
179
|
-
condition_contraction
|
180
|
-
end
|
181
|
-
|
182
|
-
rule reading_contraction
|
183
|
-
role p:post_qualifiers? conjunction:(that/who) s certainty s contracted_clauses s
|
184
|
-
{
|
185
|
-
def ast
|
186
|
-
# contracted_clauses.ast will return an array of Clauses, but the first clause is special. We must:
|
187
|
-
# * prepend a new role (we get the Role to build *two* ast nodes)
|
188
|
-
# * attach the qualifiers
|
189
|
-
clauses_ast = contracted_clauses.ast
|
190
|
-
clauses_ast[0].conjunction = conjunction.text_value
|
191
|
-
clauses_ast[0].phrases.unshift(role.ast)
|
192
|
-
clauses_ast[0].certainty = certainty.value
|
193
|
-
|
194
|
-
# A contraction returns an array containing:
|
195
|
-
# * a role AST
|
196
|
-
# * a qualifiers array
|
197
|
-
# * an array of Clauses
|
198
|
-
[role.ast, p.empty? ? [] : p.list] + clauses_ast
|
199
|
-
end
|
200
|
-
}
|
201
|
-
end
|
202
|
-
|
203
|
-
rule condition_contraction
|
204
|
-
role pq:post_qualifiers? certainty s comparator s e2:expression
|
205
|
-
!phrase # The contracted_clauses must not continue here!
|
206
|
-
{
|
207
|
-
def ast
|
208
|
-
c = Compiler::Comparison.new(comparator.text_value, role.ast, e2.ast, certainty.value)
|
209
|
-
c.conjunction = comparator.text_value
|
210
|
-
[ role.ast, pq.empty? ? [] : pq.list, c ]
|
211
|
-
end
|
212
|
-
}
|
213
|
-
end
|
214
|
-
|
215
|
-
rule comparison
|
216
|
-
e1:expression s certainty s comparator s contraction p:post_qualifiers?
|
217
|
-
{
|
218
|
-
def ast
|
219
|
-
role, qualifiers, *clauses_ast = *contraction.ast
|
220
|
-
clauses_ast[0].qualifiers += p.list unless p.empty? # apply post_qualifiers to the contracted clause
|
221
|
-
# clauses_ast[0].conjunction = 'and' # AND is implicit for a contraction
|
222
|
-
c = Compiler::Comparison.new(comparator.text_value, e1.ast, role, certainty.value)
|
223
|
-
[c] + clauses_ast
|
224
|
-
end
|
225
|
-
}
|
226
|
-
/
|
227
|
-
certainty e1:expression s comparator s e2:expression # comparisons have no post-qualifiers: p:post_qualifiers?
|
228
|
-
{
|
229
|
-
def ast
|
230
|
-
c = Compiler::Comparison.new(comparator.text_value, e1.ast, e2.ast, certainty.value)
|
231
|
-
[c]
|
232
|
-
end
|
233
|
-
}
|
234
|
-
end
|
235
|
-
|
236
|
-
rule comparator
|
237
|
-
'<=' / '<>' / '<' / '=' / '>=' / '>' / '!='
|
238
|
-
end
|
239
|
-
|
240
|
-
rule phrase
|
241
|
-
role # A role reference containing a term, perhaps with attached paraphernalia
|
242
|
-
/ # A hyphenated non-term. Important: no embedded spaces
|
243
|
-
id tail:('-' !term id)+ s
|
244
|
-
{
|
245
|
-
def ast
|
246
|
-
[id.value, *tail.elements.map{|e| e.id.value}]*"-"
|
247
|
-
end
|
248
|
-
def node_type; :linking; end
|
249
|
-
}
|
250
|
-
/ # A normal non-term
|
251
|
-
!non_phrase id s
|
252
|
-
{
|
253
|
-
def ast
|
254
|
-
id.value
|
255
|
-
end
|
256
|
-
def node_type; :linking; end
|
257
|
-
}
|
258
|
-
end
|
259
|
-
|
260
|
-
rule role
|
261
|
-
aggregate
|
262
|
-
/
|
263
|
-
simple_role
|
264
|
-
end
|
265
|
-
|
266
|
-
rule aggregate
|
267
|
-
aggregate:id s
|
268
|
-
agg_of s term_or_unary s agg_in s # REVISIT: this term may need to pre-scanned in the qualified_clauses
|
269
|
-
'(' qualified_clauses s ')' # REVISIT: Need to test to verify this is the right level (not query_clauses, etc)
|
270
|
-
{
|
271
|
-
def ast
|
272
|
-
raise "Not implemented: AST for '#{aggregate.text_value} of #{term_or_unary.text_value}'"
|
273
|
-
# This returns just the role with the nested clauses, which doesn't even work:
|
274
|
-
term.ast(
|
275
|
-
nil, # No quantifier
|
276
|
-
nil, # No function call
|
277
|
-
nil, # No role_name
|
278
|
-
nil, # No value_constraint
|
279
|
-
nil, # No literal
|
280
|
-
qualified_clauses.ast
|
281
|
-
)
|
282
|
-
end
|
283
|
-
}
|
284
|
-
end
|
285
|
-
|
286
|
-
rule role_quantifier
|
287
|
-
quantifier mapping_pragmas enforcement cn:context_note?
|
288
|
-
{
|
289
|
-
def ast
|
290
|
-
Compiler::Quantifier.new(
|
291
|
-
quantifier.value[0],
|
292
|
-
quantifier.value[1],
|
293
|
-
enforcement.ast,
|
294
|
-
cn.empty? ? nil : cn.ast,
|
295
|
-
mapping_pragmas.value
|
296
|
-
)
|
297
|
-
end
|
298
|
-
}
|
299
|
-
end
|
300
|
-
|
301
|
-
# This is the rule that causes most back-tracking. I think you can see why.
|
302
|
-
rule simple_role
|
303
|
-
q:role_quantifier?
|
304
|
-
player:derived_variable
|
305
|
-
lr:(
|
306
|
-
literal u:unit?
|
307
|
-
/
|
308
|
-
value_constraint enforcement
|
309
|
-
)?
|
310
|
-
oj:objectification_step?
|
311
|
-
{
|
312
|
-
def ast
|
313
|
-
if !q.empty? && q.quantifier.value
|
314
|
-
quantifier = q.ast
|
315
|
-
end
|
316
|
-
if !lr.empty?
|
317
|
-
if lr.respond_to?(:literal)
|
318
|
-
literal = Compiler::Literal.new(lr.literal.value, lr.u.empty? ? nil : lr.u.text_value)
|
319
|
-
end
|
320
|
-
value_constraint = Compiler::ValueConstraint.new(lr.value_constraint.ast, lr.enforcement.ast) if lr.respond_to?(:value_constraint)
|
321
|
-
raise "It is not permitted to provide both a literal value and a value constraint" if value_constraint and literal
|
322
|
-
end
|
323
|
-
|
324
|
-
nested_clauses =
|
325
|
-
if oj.empty?
|
326
|
-
nil
|
327
|
-
else
|
328
|
-
ast = oj.ast
|
329
|
-
ast[0].conjunction = 'where'
|
330
|
-
ast
|
331
|
-
end
|
332
|
-
player.ast(quantifier, value_constraint, literal, nested_clauses)
|
333
|
-
end
|
334
|
-
}
|
335
|
-
end
|
336
|
-
|
337
|
-
rule objectification_step
|
338
|
-
'(' s in_which s facts:query_clauses s ')' s
|
339
|
-
{
|
340
|
-
def ast
|
341
|
-
facts.ast
|
342
|
-
end
|
343
|
-
}
|
344
|
-
end
|
345
|
-
|
346
|
-
rule role_name
|
347
|
-
'(' s as S r:term s ')' s
|
348
|
-
{ def value; r.value; end }
|
349
|
-
end
|
350
|
-
|
351
|
-
rule subscript
|
352
|
-
'(' s i:([1-9] [0-9]*) s ')' s
|
353
|
-
{ def value; i.text_value.to_i; end }
|
354
|
-
end
|
355
|
-
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|
@@ -1,315 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts CQL Parser.
|
3
|
-
# Parse rules the English syntax of CQL.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
|
6
|
-
#
|
7
|
-
module ActiveFacts
|
8
|
-
module CQL
|
9
|
-
grammar English
|
10
|
-
|
11
|
-
# >>>>>>>>>>>>>>>>>>>> Object Types <<<<<<<<<<<<<<<<<<<<
|
12
|
-
# The pattern to introduce a Value Type
|
13
|
-
rule written_as
|
14
|
-
s 'is' s 'written' S as s
|
15
|
-
end
|
16
|
-
|
17
|
-
rule auto_assignment
|
18
|
-
'auto-assigned' S at s time:('assert' / 'commit') !alphanumeric s
|
19
|
-
{
|
20
|
-
def auto_assigned_at
|
21
|
-
time.text_value
|
22
|
-
end
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
# The pattern to introduce an Entity Type
|
27
|
-
rule identified_by
|
28
|
-
identified s by s
|
29
|
-
end
|
30
|
-
|
31
|
-
rule basetype_expression
|
32
|
-
is s i:( independent s )? identification
|
33
|
-
end
|
34
|
-
|
35
|
-
# The pattern to introduce an Entity Subtype
|
36
|
-
rule subtype_prefix
|
37
|
-
'is' s 'a' s ('kind'/'subtype') s 'of' S
|
38
|
-
end
|
39
|
-
|
40
|
-
rule subtype_expression
|
41
|
-
subtype_prefix i:( independent s )? supertype_list ident:identification?
|
42
|
-
end
|
43
|
-
|
44
|
-
# The pattern to introduce an objectified fact type with implicit identification
|
45
|
-
rule is_where
|
46
|
-
is s i:(independent s)? where
|
47
|
-
{ def independent; !i.empty?; end }
|
48
|
-
end
|
49
|
-
|
50
|
-
rule in_which # Introduce an objectification step
|
51
|
-
where / # Old syntax
|
52
|
-
in s which # preferred syntax
|
53
|
-
end
|
54
|
-
|
55
|
-
# Units conversion keyword
|
56
|
-
rule conversion
|
57
|
-
converts s a:(approximately s)? to s
|
58
|
-
{
|
59
|
-
def approximate?
|
60
|
-
!a.empty?
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
# >>>>>>>>>>>>>>>>>>>> Constraints <<<<<<<<<<<<<<<<<<<<
|
66
|
-
# External presence constraint syntax:
|
67
|
-
rule each_occurs_in_clauses
|
68
|
-
s 'each' s ('combination' S)? role_list s occurs s quantifier s 'time' 's'? s enforcement 'in' s
|
69
|
-
clauses_list s c:context_note? ';'
|
70
|
-
{
|
71
|
-
def role_list_ast
|
72
|
-
role_list.ast
|
73
|
-
end
|
74
|
-
def quantifier_ast
|
75
|
-
quantifier.ast
|
76
|
-
end
|
77
|
-
def clauses_ast
|
78
|
-
clauses_list.ast
|
79
|
-
end
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
|
-
# Alternate external presence constraint syntax:
|
84
|
-
rule either_or
|
85
|
-
s either? s r1:clauses s or s r2:clauses c:context_note? enforcement ';'
|
86
|
-
{
|
87
|
-
def role_list_ast
|
88
|
-
nil
|
89
|
-
end
|
90
|
-
def quantifier_ast
|
91
|
-
Compiler::Quantifier.new(1, nil)
|
92
|
-
end
|
93
|
-
def clauses_ast
|
94
|
-
[r1.ast, r2.ast]
|
95
|
-
end
|
96
|
-
}
|
97
|
-
end
|
98
|
-
|
99
|
-
# Exclusion (at most one) and mandatory exclusion (exactly one) constraint syntax:
|
100
|
-
rule for_each_how_many
|
101
|
-
s 'for' s 'each' s role_list s quantifier s 'of' s 'these' s 'holds' s enforcement ':' s
|
102
|
-
clauses_list s c:context_note? ';'
|
103
|
-
{
|
104
|
-
def role_list_ast
|
105
|
-
role_list.ast
|
106
|
-
end
|
107
|
-
def quantifier_ast
|
108
|
-
quantifier.ast
|
109
|
-
end
|
110
|
-
def clauses_ast
|
111
|
-
clauses_list.ast
|
112
|
-
end
|
113
|
-
}
|
114
|
-
end
|
115
|
-
|
116
|
-
# Alternate mandatory exclusion constraint syntax:
|
117
|
-
rule either_or_not_both
|
118
|
-
s either? s r1:clauses s or s r2:clauses but s not s both s c:context_note? enforcement ';'
|
119
|
-
{
|
120
|
-
def role_list_ast
|
121
|
-
nil
|
122
|
-
end
|
123
|
-
def quantifier_ast
|
124
|
-
Compiler::Quantifier.new(1, 1)
|
125
|
-
end
|
126
|
-
def clauses_ast
|
127
|
-
[r1.ast, r2.ast]
|
128
|
-
end
|
129
|
-
}
|
130
|
-
end
|
131
|
-
|
132
|
-
# Subset constraint using "A only if B" syntax
|
133
|
-
rule a_only_if_b
|
134
|
-
s clauses:query_clauses s only s if s r2:query_clauses s c:context_note? enforcement ';'
|
135
|
-
end
|
136
|
-
|
137
|
-
rule only_if
|
138
|
-
only s if s
|
139
|
-
end
|
140
|
-
|
141
|
-
# Subset constraint using "if A then B" syntax
|
142
|
-
rule if_b_then_a
|
143
|
-
s if s clauses s then s r2:clauses s c:context_note? enforcement ';'
|
144
|
-
end
|
145
|
-
|
146
|
-
# Equality constraint syntax:
|
147
|
-
rule if_and_only_if
|
148
|
-
s clauses s tail:( if s and s only s if s clauses s)+
|
149
|
-
c:context_note? enforcement ';'
|
150
|
-
end
|
151
|
-
|
152
|
-
# During the prescan we need to know where terms in a role list finish.
|
153
|
-
# This rule matches any non-term expressions that may follow a role list.
|
154
|
-
rule role_list_constraint_followers
|
155
|
-
occurs s quantifier s 'time'
|
156
|
-
end
|
157
|
-
|
158
|
-
# >>>>>>>>>>>>>>>>>>>> Quantifiers <<<<<<<<<<<<<<<<<<<<
|
159
|
-
rule quantifier
|
160
|
-
(
|
161
|
-
each s { def value; [1, nil]; end }
|
162
|
-
/ some s { def value; nil; end }
|
163
|
-
# REVISIT: "Some" means that any prior occurrence of this role player is to be ignored; this is a new occurrence
|
164
|
-
# "that" on the other hand means that this role player was *previously* designated using "some".
|
165
|
-
# These distinctions are lost here
|
166
|
-
/ that s { def value; nil; end }
|
167
|
-
/ which s { def value; nil; end }
|
168
|
-
/ one s { def value; [1, 1]; end }
|
169
|
-
/ no s { def value; [0, 0]; end }
|
170
|
-
/ exactly s quantity { def value; q = quantity.value; [q, q]; end }
|
171
|
-
/ at s least s quantity most:( and s at s most s q:quantity )?
|
172
|
-
{ def value;
|
173
|
-
[ quantity.value,
|
174
|
-
most.empty? ? nil : most.q.value
|
175
|
-
]
|
176
|
-
end
|
177
|
-
}
|
178
|
-
/ at s most s quantity { def value; [ nil, quantity.value ]; end }
|
179
|
-
/ from s numeric_range s { def value; numeric_range.value; end }
|
180
|
-
# / either_all_or_none s { def value; [ -1, 1 ]; end }
|
181
|
-
)
|
182
|
-
{
|
183
|
-
def ast
|
184
|
-
v = value
|
185
|
-
Compiler::Quantifier.new(v[0], v[1])
|
186
|
-
end
|
187
|
-
}
|
188
|
-
end
|
189
|
-
|
190
|
-
# rule either_all_or_none either s all s or s ( none / no ) end
|
191
|
-
|
192
|
-
rule quantity
|
193
|
-
one s { def value; 1; end }
|
194
|
-
/ number s { def value; number.value; end }
|
195
|
-
end
|
196
|
-
|
197
|
-
# >>>>>>>>>>>>>>>>>>>> Context Notes <<<<<<<<<<<<<<<<<<<<
|
198
|
-
rule as_agreed_by
|
199
|
-
s as s 'agreed' s d:('on' S date)? by s agents
|
200
|
-
{ def value; [ d.empty? ? nil : d.date.value, agents.value ]; end }
|
201
|
-
end
|
202
|
-
|
203
|
-
rule date
|
204
|
-
s d:(!(by/')') .)+
|
205
|
-
{ def value; d.text_value.strip; end }
|
206
|
-
end
|
207
|
-
|
208
|
-
rule agents
|
209
|
-
s h:agent s t:(',' s !context_type agent s)*
|
210
|
-
{
|
211
|
-
def value; [h.text_value] + t.elements.map{|e| e.agent.text_value }; end
|
212
|
-
def node_type; :linking; end
|
213
|
-
}
|
214
|
-
end
|
215
|
-
|
216
|
-
rule agent
|
217
|
-
id (s id)*
|
218
|
-
end
|
219
|
-
|
220
|
-
rule negative_prefix
|
221
|
-
s it s is s not s the s case s that s
|
222
|
-
end
|
223
|
-
|
224
|
-
rule agg_of of end
|
225
|
-
rule agg_in in end
|
226
|
-
rule restricted_to 'restricted' s 'to' s !alphanumeric end
|
227
|
-
# any is optionally used in an identifying role_list
|
228
|
-
rule any one / a end
|
229
|
-
|
230
|
-
# >>>>>>>>>>>>>>>>>>>> Internal vocabulary <<<<<<<<<<<<<<<<<<<<
|
231
|
-
rule a ('a' !alphanumeric /'an' !alphanumeric) end
|
232
|
-
rule all 'all' !alphanumeric end
|
233
|
-
rule ascending 'ascending' !alphanumeric end
|
234
|
-
rule at 'at' !alphanumeric end
|
235
|
-
rule both 'both' !alphanumeric end
|
236
|
-
rule converts 'converts' !alphanumeric end
|
237
|
-
rule descending 'descending' !alphanumeric end
|
238
|
-
rule each 'each' !alphanumeric end
|
239
|
-
rule either 'either' !alphanumeric end
|
240
|
-
rule entity 'entity' !alphanumeric end
|
241
|
-
rule exactly 'exactly' !alphanumeric end
|
242
|
-
rule from 'from' !alphanumeric end
|
243
|
-
rule includes 'includes' !alphanumeric end
|
244
|
-
rule least 'least' !alphanumeric end
|
245
|
-
rule matches 'matches' !alphanumeric end
|
246
|
-
rule most 'most' !alphanumeric end
|
247
|
-
rule no 'no' !alphanumeric end
|
248
|
-
rule none 'none' !alphanumeric end
|
249
|
-
rule not 'not' !alphanumeric end
|
250
|
-
rule occurs 'occurs' !alphanumeric end
|
251
|
-
rule one 'one' !alphanumeric end
|
252
|
-
rule some 'some' !alphanumeric end
|
253
|
-
|
254
|
-
# >>>>>>>>>>>>>>>>>>>> External vocabulary <<<<<<<<<<<<<<<<<<<<
|
255
|
-
rule according_to 'according' S to end
|
256
|
-
rule acyclic 'acyclic' !alphanumeric end
|
257
|
-
rule alias 'alias' !alphanumeric end
|
258
|
-
rule and 'and' !alphanumeric end
|
259
|
-
rule antisymmetric 'antisymmetric' !alphanumeric end
|
260
|
-
rule approximately 'approximately' !alphanumeric end
|
261
|
-
rule as 'as' !alphanumeric end
|
262
|
-
rule as_opposed_to as s 'opposed' S to end
|
263
|
-
rule asymmetric 'asymmetric' !alphanumeric end
|
264
|
-
rule because 'because' !alphanumeric end
|
265
|
-
rule but 'but' !alphanumeric end
|
266
|
-
rule by 'by' !alphanumeric end # fix? Used in 'returning' for ordering
|
267
|
-
rule case 'case' !alphanumeric end
|
268
|
-
rule definitely 'definitely' !alphanumeric end
|
269
|
-
rule ephemera 'ephemera' !alphanumeric end
|
270
|
-
rule false 'false' !alphanumeric end
|
271
|
-
rule feminine 'feminine' !alphanumeric end
|
272
|
-
rule identified ('known'/'identified') !alphanumeric end
|
273
|
-
rule if 'if' !alphanumeric end
|
274
|
-
rule in 'in' !alphanumeric end
|
275
|
-
rule import 'import' !alphanumeric end
|
276
|
-
rule independent 'independent' !alphanumeric end
|
277
|
-
rule stronglyintransitive 'strongly' s 'intransitive' !alphanumeric end
|
278
|
-
rule intransitive 'intransitive' !alphanumeric end
|
279
|
-
rule irreflexive 'irreflexive' !alphanumeric end
|
280
|
-
rule is 'is' !alphanumeric end
|
281
|
-
rule it 'it' !alphanumeric end
|
282
|
-
rule its 'its' !alphanumeric end
|
283
|
-
rule masculine 'masculine' !alphanumeric end
|
284
|
-
rule maybe 'maybe' !alphanumeric end
|
285
|
-
rule only 'only' !alphanumeric end
|
286
|
-
rule or 'or' !alphanumeric end
|
287
|
-
rule of 'of' !alphanumeric end
|
288
|
-
rule ordering_prefix by s (ascending/descending)? s end
|
289
|
-
rule otherwise 'otherwise' !alphanumeric end
|
290
|
-
rule partitioned 'partitioned' !alphanumeric end
|
291
|
-
rule personal 'personal' !alphanumeric end
|
292
|
-
rule radix_point '.' end
|
293
|
-
rule reflexive 'reflexive' !alphanumeric end
|
294
|
-
rule returning 'returning' !alphanumeric end
|
295
|
-
rule separate 'separate' !alphanumeric end
|
296
|
-
rule so_that 'so' S that end
|
297
|
-
rule static 'static' !alphanumeric end
|
298
|
-
rule symmetric 'symmetric' !alphanumeric end
|
299
|
-
rule that 'that' !alphanumeric end
|
300
|
-
rule the 'the' !alphanumeric end
|
301
|
-
rule then 'then' !alphanumeric end
|
302
|
-
rule to 'to' !alphanumeric end
|
303
|
-
rule to_avoid to s 'avoid' !alphanumeric end
|
304
|
-
rule transient 'transient' !alphanumeric end
|
305
|
-
rule transitive 'transitive' !alphanumeric end
|
306
|
-
rule true 'true' !alphanumeric end
|
307
|
-
rule vocabulary 'vocabulary' !alphanumeric end
|
308
|
-
rule where 'where' !alphanumeric end
|
309
|
-
rule which 'which' !alphanumeric end
|
310
|
-
rule was 'was' !alphanumeric end
|
311
|
-
rule who 'who' !alphanumeric end
|
312
|
-
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|