activefacts-cql 1.8.3 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -292,7 +292,8 @@ module ActiveFacts
292
292
  rule radix_point ',' end
293
293
  rule reflexive 'réflexive' !alphanumeric end
294
294
  rule returning 'retour' !alphanumeric end
295
- rule separate 'distincte' !alphanumeric end
295
+ rule separate 'distincte' !alphanumeric end
296
+ rule schema 'schema' !alphanumeric end
296
297
  rule si 'si' !alphanumeric end
297
298
  rule so_that 'pour' s 'que' !alphanumeric end
298
299
  rule soit 'soit' !alphanumeric end
@@ -302,9 +303,12 @@ module ActiveFacts
302
303
  rule then 'puis' !alphanumeric end
303
304
  rule to 'à' !alphanumeric end
304
305
  rule to_avoid ('pour' s 'empecher' s 'de' / 'pour' s 'ne' s 'pas') !alphanumeric end
306
+ rule topic 'sujet' !alphanumeric end
307
+ rule transform 'transform' !alphanumeric end
305
308
  rule transient 'transitoires' !alphanumeric end
306
309
  rule transitive 'transitif' !alphanumeric end
307
- rule true 'vrai' !alphanumeric end
310
+ rule true 'vrai' !alphanumeric end
311
+ rule version 'version' !alphanumeric end
308
312
  rule vocabulary 'vocabulaire' !alphanumeric end
309
313
  rule where 'où' !alphanumeric end
310
314
  rule who 'qui' !alphanumeric end
@@ -294,7 +294,8 @@ module ActiveFacts
294
294
  rule to_avoid ('pour' s 'empecher' s 'de' / 'pour' s 'ne' s 'pas') !alphanumeric end
295
295
  rule transient 'transitoires' !alphanumeric end
296
296
  rule transitive 'transitif' !alphanumeric end
297
- rule true 'vrai' !alphanumeric end
297
+ rule true 'vrai' !alphanumeric end
298
+ rule version 'version' !alphanumeric end
298
299
  rule vocabulary 'vocabulaire' !alphanumeric end
299
300
  rule where 'où' !alphanumeric end
300
301
  rule who 'qui' !alphanumeric end
@@ -155,8 +155,8 @@ module ActiveFacts
155
155
 
156
156
  rule global_term
157
157
  # This rule shouldn't be used outside the prescan, it will memoize the wrong things.
158
- head:id x &{|s| input.context.term_starts?(s[0].text_value, s[1]) }
159
- tail:(s w:id &{|s| input.context.term_continues?(s[1].text_value) } )*
158
+ head:id x &{|s| input.context.global_term_starts?(s[0].text_value, s[1]) }
159
+ tail:(s w:id &{|s| input.context.global_term_continues?(s[1].text_value) } )*
160
160
  { def value
161
161
  tail.elements.inject(head.value) { |t, e| "#{t} #{e.w.value}" }
162
162
  end
@@ -0,0 +1,226 @@
1
+ #
2
+ # ActiveFacts CQL Parser.
3
+ # Parse rules relating to Transformation Rules.
4
+ #
5
+ # Copyright (c) 2017 Factil Pty Ltd. Read the LICENSE file.
6
+ #
7
+ module ActiveFacts
8
+ module CQL
9
+ grammar TransformRules
10
+
11
+ rule transform_rule
12
+ ctr:compound_matching s ';'
13
+ {
14
+ def ast
15
+ Compiler::TransformRule.new(ctr.ast)
16
+ end
17
+ }
18
+ end
19
+
20
+ rule compound_matching
21
+ s tl:term_list s '<==' s tq:transform_query? s '{' tr:transform_matchings s '}'
22
+ {
23
+ def ast
24
+ Compiler::CompoundMatching.new(tl.ast, tq.empty? ? nil : tq.ast, tr.ast)
25
+ end
26
+ }
27
+ end
28
+
29
+ rule simple_matching
30
+ s tl:term_list s '<--' s te:transform_expr?
31
+ {
32
+ def ast
33
+ Compiler::SimpleMatching.new(tl.ast, te.empty? ? nil : te.ast)
34
+ end
35
+ }
36
+ end
37
+
38
+ rule transform_query
39
+ cl:clauses_list { def ast; cl.ast; end; }
40
+ / t:term { def ast; t.ast; end; }
41
+ end
42
+
43
+ rule transform_matchings
44
+ s r0:transform_matching tail:(s ',' s r1:transform_matching)*
45
+ {
46
+ def ast
47
+ [r0.ast, *tail.elements.map{|e| e.r1.ast }]
48
+ end
49
+ }
50
+ end
51
+
52
+ rule transform_matching
53
+ str:simple_matching { def ast; str.ast; end; }
54
+ / ctr:compound_matching { def ast; ctr.ast; end; }
55
+ end
56
+
57
+ rule term_list
58
+ s t0:term tail:(s '.' s t1:term_list)*
59
+ {
60
+ def ast
61
+ if tail.elements.empty?
62
+ [t0.ast]
63
+ else
64
+ [t0.ast, *tail.elements.map{|t| t.t1.ast }]
65
+ end
66
+ end
67
+ }
68
+ end
69
+
70
+ rule transform_expr
71
+ s c:logical_texpr s '?' s t0:logical_texpr s ':' s t1:logical_texpr
72
+ {
73
+ def ast
74
+ Compiler::Ternary.new(c.ast, t0.ast, t1.ast)
75
+ end
76
+ }
77
+ / s o:aggregate_op S agg_of s t:logical_texpr
78
+ {
79
+ def ast
80
+ Compiler::Aggregate.new(o.text_value, t.ast)
81
+ end
82
+ }
83
+ / s t0:logical_texpr { def ast; t0.ast; end; }
84
+ end
85
+
86
+ rule aggregate_op
87
+ 'sum' / 'average' / 'max' / 'min' / 'count'
88
+ end
89
+
90
+ rule logical_texpr
91
+ s t0:logical_and_texpr tail:(s op:or s t1:logical_and_texpr)*
92
+ {
93
+ def ast
94
+ if tail.elements.empty?
95
+ t0.ast
96
+ else
97
+ Compiler::LogicalOr.new(t0.ast, *tail.elements.map{|e| e.t1.ast})
98
+ end
99
+ end
100
+ }
101
+ end
102
+
103
+ rule logical_and_texpr
104
+ s t0:equality_texpr tail:(s op:and s t1:equality_texpr)*
105
+ {
106
+ def ast
107
+ if tail.elements.empty?
108
+ t0.ast
109
+ else
110
+ Compiler::LogicalAnd.new(t0.ast, *tail.elements.map{|e| e.t1.ast})
111
+ end
112
+ end
113
+ }
114
+ end
115
+
116
+ rule equality_texpr
117
+ s t0:relational_texpr operation:(s op:equality_op s t1:relational_texpr)?
118
+ {
119
+ def ast
120
+ if operation.empty?
121
+ t0.ast
122
+ else
123
+ Compiler::Comparison.new(op.text_value, t0.ast, operation.t1.ast)
124
+ end
125
+ end
126
+ }
127
+ end
128
+
129
+ rule equality_op
130
+ '=' / '!='
131
+ end
132
+
133
+ rule relational_texpr
134
+ s t0:additive_texpr operation:(s op:relational_op s t1:additive_texpr)?
135
+ {
136
+ def ast
137
+ if operation.empty?
138
+ t0.ast
139
+ else
140
+ Compiler::Comparison.new(op.text_value, t0.ast, operation.t1.ast)
141
+ end
142
+ end
143
+ }
144
+ end
145
+
146
+ rule relational_op
147
+ '<' / '>' / '>=' / '<='
148
+ end
149
+
150
+ rule additive_texpr
151
+ s t0:multiplicative_texpr tail:(s op:additive_op s t1:multiplicative_texpr)*
152
+ {
153
+ def ast
154
+ if tail.elements.empty?
155
+ t0.ast
156
+ else
157
+ Compiler::Sum.new(
158
+ t0.ast,
159
+ *tail.elements.map{|e| e.op.text_value == '-' ? Compiler::Negate.new(e.t1.ast) : e.t1.ast}
160
+ )
161
+ end
162
+ end
163
+ }
164
+ end
165
+
166
+ rule additive_op
167
+ '+' / '-'
168
+ end
169
+
170
+ rule multiplicative_texpr
171
+ s t0:unary_texpr tail:(s op:multiplicative_op s t1:unary_texpr)*
172
+ {
173
+ def ast
174
+ if tail.elements.empty?
175
+ t0.ast
176
+ else
177
+ Compiler::Product.new(
178
+ t0.ast,
179
+ *tail.elements.map{|e| e.op.text_value == '/' ? Compiler::Reciprocal.new(e.t1.ast) : e.t1.ast}
180
+ )
181
+ end
182
+ end
183
+ }
184
+ end
185
+
186
+ rule multiplicative_op
187
+ '*' / '/'
188
+ end
189
+
190
+ rule unary_texpr
191
+ s u:unary_op? s t:primary_texpr
192
+ {
193
+ def ast
194
+ if u.empty?
195
+ t.ast
196
+ else
197
+ u.text_value == '-' ? Compiler::Negate.new(t.ast) : Compiler::Negation.new(t.ast)
198
+ end
199
+ end
200
+ }
201
+ end
202
+
203
+ rule unary_op
204
+ '-' / '!'
205
+ end
206
+
207
+ rule primary_texpr
208
+ tl:term_list
209
+ {
210
+ def ast
211
+ Compiler::ExpressionTermList.new(tl.ast)
212
+ end
213
+ }
214
+ / l:literal
215
+ {
216
+ def ast
217
+ Compiler::Literal.new(l.value, nil)
218
+ end
219
+ }
220
+ # / '(' source_expr ')'
221
+ # / id '(' source_expr (s ',' s source_expr) * ')'
222
+ end
223
+
224
+ end
225
+ end
226
+ end
@@ -472,13 +472,11 @@ module ActiveFacts
472
472
  subscript ||= prr.subscript if prr
473
473
  trace :subscript, "Need to apply subscript #{subscript} to #{role_ref.role.object_type.name}" if subscript
474
474
  object_type = role_ref.role.object_type
475
- (play_name ||
476
- [
477
- role_ref.leading_adjective,
478
- object_type.name,
479
- role_ref.trailing_adjective
480
- ].compact*' '
481
- ) +
475
+ [
476
+ role_ref.leading_adjective,
477
+ play_name || object_type.name,
478
+ role_ref.trailing_adjective
479
+ ].compact*' ' +
482
480
  (value ? ' '+value.inspect : '') +
483
481
  (subscript ? "(#{subscript})" : '')
484
482
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveFacts
2
2
  module CQL
3
- VERSION = "1.8.3"
3
+ VERSION = "1.9.1"
4
4
  end
5
5
  end
@@ -12,9 +12,10 @@ module ActiveFacts
12
12
  # Invoke as
13
13
  # afgen --<generator> <file>.cql
14
14
  class CQL
15
+ EXTENSIONS = ['fiml', 'fidl', 'fiql', 'cql']
15
16
  # Read the specified file
16
17
  def self.readfile(filename)
17
- if File.basename(filename, '.cql') == "-"
18
+ if EXTENSIONS.detect { |extension| File.basename(filename, extension) == "-" }
18
19
  read(STDIN, "<standard input>")
19
20
  else
20
21
  File.open(filename) {|file|
@@ -1,12 +1,15 @@
1
- Gem.post_install do |installer|
2
- if installer.spec.name == 'activefacts-cql'
3
- pattern = installer.dir + '/lib/activefacts/cql/**/*.treetop'
4
- files = Dir[pattern]
5
- # Hopefully this quoting will work where there are spaces in filenames, and even maybe on Windows?
6
- cmd = "tt '#{files*"' '"}'"
7
- puts "Compiling Treetop grammars:"
8
- puts cmd
9
- system cmd
10
- puts 'For more information on ActiveFacts, see http://dataconstellation.com/ActiveFacts/'
11
- end
12
- end
1
+ #
2
+ # Ruby files are now included in the gem package
3
+ #
4
+ # Gem.post_install do |installer|
5
+ # if installer.spec.name == 'activefacts-cql'
6
+ # pattern = installer.dir + '/lib/activefacts/cql/**/*.treetop'
7
+ # files = Dir[pattern]
8
+ # # Hopefully this quoting will work where there are spaces in filenames, and even maybe on Windows?
9
+ # cmd = "tt '#{files*"' '"}'"
10
+ # puts "Compiling Treetop grammars:"
11
+ # puts cmd
12
+ # system cmd
13
+ # puts 'For more information on ActiveFacts, see http://dataconstellation.com/ActiveFacts/'
14
+ # end
15
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activefacts-cql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,7 +61,7 @@ dependencies:
61
61
  version: '1'
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 1.9.5
64
+ version: 1.9.14
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '1'
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 1.9.5
74
+ version: 1.9.14
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: treetop
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,7 @@ files:
123
123
  - lib/activefacts/cql/compiler/informal.rb
124
124
  - lib/activefacts/cql/compiler/query.rb
125
125
  - lib/activefacts/cql/compiler/shared.rb
126
+ - lib/activefacts/cql/compiler/transform_rule.rb
126
127
  - lib/activefacts/cql/compiler/value_type.rb
127
128
  - lib/activefacts/cql/parser.rb
128
129
  - lib/activefacts/cql/parser/CQLParser.treetop
@@ -135,6 +136,7 @@ files:
135
136
  - lib/activefacts/cql/parser/LexicalRules.treetop
136
137
  - lib/activefacts/cql/parser/ObjectTypes.treetop
137
138
  - lib/activefacts/cql/parser/Terms.treetop
139
+ - lib/activefacts/cql/parser/TransformRules.treetop
138
140
  - lib/activefacts/cql/parser/ValueTypes.treetop
139
141
  - lib/activefacts/cql/parser/nodes.rb
140
142
  - lib/activefacts/cql/require.rb