activefacts-cql 1.9.6 → 1.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd022cd38f05ea499b7713c4d5e01b28e101a445
4
- data.tar.gz: 61009d0a5dba377aad97b7f1af587f52b8b85a89
3
+ metadata.gz: 79eea1540c275b37e1db24f1a39e7715b0af50d1
4
+ data.tar.gz: cf068ad7b25a9891e64609fdd10a3b2eee26727b
5
5
  SHA512:
6
- metadata.gz: c602d72038965d2bc49812291bdca817b7eee6d609c61c0cb0db9ae5a4a96eef14f5fb45b2104cb0af4e8fe5bcd44ddef088140279bf9cc5cd8720a199971c46
7
- data.tar.gz: 69fb6ce9c7f77a558cf07f6c54fe453d5f27333330d39a889c525eca9bce3604064622073f0564733bd008fa90b366a2af146e1dc8833de6ffbc094a2353c3c9
6
+ metadata.gz: 287e271910e4c1597c7911168d39b61231e8bed548d096f1c5e133533b1b79e80c3a4f48092d2056726e80ae1c304840bd25c5edea2cd97188e4459319f850b2
7
+ data.tar.gz: be9d2a0af83823548df7d36b48f5c069f8dee127c55708abeab469580ce15631514c7705241c35774d3f74ee4e0808a72b6d83631ce65ea45e73722be2ed606c
data/Rakefile CHANGED
@@ -5,6 +5,25 @@ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
7
 
8
+ task :build => [:create_treetop_files, :clean_treetop_files]
9
+ task :create_treetop_files do
10
+ cqlpath = File.expand_path('../lib/activefacts/cql/parser', __FILE__)
11
+ Dir[cqlpath+"/**/*.treetop"].each do |tt|
12
+ rb = tt.sub(/treetop\Z/, 'rb')
13
+ sh(%Q{tt #{tt}})
14
+ end
15
+ end
16
+ def clean_treetop_files
17
+ cqlpath = File.expand_path('../lib/activefacts/cql/parser', __FILE__)
18
+ Dir[cqlpath+"/**/*.treetop"].each do |tt|
19
+ rb = tt.sub(/treetop\Z/, 'rb')
20
+ File.unlink(rb) rescue nil
21
+ end
22
+ end
23
+ task :clean_treetop_files do
24
+ at_exit { clean_treetop_files }
25
+ end
26
+
8
27
  desc "Bump gem version patch number"
9
28
  task :bump do
10
29
  path = File.expand_path('../lib/activefacts/cql/version.rb', __FILE__)
@@ -14,14 +14,16 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "http://github.com/cjheath/activefacts-cql"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = `git ls-files -z`.
18
+ split("\x0").
19
+ reject { |f| f.match(%r{^(test|spec|features)/}) }.
20
+ map{|file| file.sub(/\.treetop$/,'.rb')}
18
21
  spec.bindir = "exe"
19
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
23
  spec.require_paths = ["lib"]
21
- spec.extensions << 'lib/activefacts/cql/Rakefile'
22
24
 
23
25
  spec.add_development_dependency "bundler", ">= 1.10"
24
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rake", "> 10"
25
27
  spec.add_development_dependency "rspec", "~> 3.3"
26
28
 
27
29
  spec.add_runtime_dependency "activefacts-metamodel", "~> 1", ">= 1.9.22"
@@ -261,6 +261,10 @@ module ActiveFacts
261
261
  raise failure_reason || "not all input was understood" unless @index == input.size
262
262
  return nil # No input, or no more input
263
263
  end
264
+ unless @vocabulary_seen || !node.ast
265
+ @vocabulary_seen = Compiler::Vocabulary === node.ast
266
+ raise "CQL files must begin with a vocabulary, schema or transform definition" unless @vocabulary_seen
267
+ end
264
268
  if @block
265
269
  @block.call(node)
266
270
  else
@@ -1,5 +1,5 @@
1
1
  module ActiveFacts
2
2
  module CQL
3
- VERSION = "1.9.6"
3
+ VERSION = "1.9.7"
4
4
  end
5
5
  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.9.6
4
+ version: 1.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-15 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -97,8 +97,7 @@ description: Compiler for the Constellation Query Language, part of the ActiveFa
97
97
  email:
98
98
  - clifford.heath@gmail.com
99
99
  executables: []
100
- extensions:
101
- - lib/activefacts/cql/Rakefile
100
+ extensions: []
102
101
  extra_rdoc_files: []
103
102
  files:
104
103
  - ".gitignore"
@@ -112,7 +111,6 @@ files:
112
111
  - bin/setup
113
112
  - lib/activefacts/cql.rb
114
113
  - lib/activefacts/cql/.gitignore
115
- - lib/activefacts/cql/Rakefile
116
114
  - lib/activefacts/cql/compiler.rb
117
115
  - lib/activefacts/cql/compiler/clause.rb
118
116
  - lib/activefacts/cql/compiler/constraint.rb
@@ -126,18 +124,18 @@ files:
126
124
  - lib/activefacts/cql/compiler/transform_rule.rb
127
125
  - lib/activefacts/cql/compiler/value_type.rb
128
126
  - lib/activefacts/cql/parser.rb
129
- - lib/activefacts/cql/parser/CQLParser.treetop
130
- - lib/activefacts/cql/parser/Context.treetop
131
- - lib/activefacts/cql/parser/Expressions.treetop
132
- - lib/activefacts/cql/parser/FactTypes.treetop
133
- - lib/activefacts/cql/parser/Language/English.treetop
134
- - lib/activefacts/cql/parser/Language/French.treetop
135
- - lib/activefacts/cql/parser/Language/Mandarin.treetop
136
- - lib/activefacts/cql/parser/LexicalRules.treetop
137
- - lib/activefacts/cql/parser/ObjectTypes.treetop
138
- - lib/activefacts/cql/parser/Terms.treetop
139
- - lib/activefacts/cql/parser/TransformRules.treetop
140
- - lib/activefacts/cql/parser/ValueTypes.treetop
127
+ - lib/activefacts/cql/parser/CQLParser.rb
128
+ - lib/activefacts/cql/parser/Context.rb
129
+ - lib/activefacts/cql/parser/Expressions.rb
130
+ - lib/activefacts/cql/parser/FactTypes.rb
131
+ - lib/activefacts/cql/parser/Language/English.rb
132
+ - lib/activefacts/cql/parser/Language/French.rb
133
+ - lib/activefacts/cql/parser/Language/Mandarin.rb
134
+ - lib/activefacts/cql/parser/LexicalRules.rb
135
+ - lib/activefacts/cql/parser/ObjectTypes.rb
136
+ - lib/activefacts/cql/parser/Terms.rb
137
+ - lib/activefacts/cql/parser/TransformRules.rb
138
+ - lib/activefacts/cql/parser/ValueTypes.rb
141
139
  - lib/activefacts/cql/parser/nodes.rb
142
140
  - lib/activefacts/cql/require.rb
143
141
  - lib/activefacts/cql/verbaliser.rb
@@ -1,14 +0,0 @@
1
- #
2
- # ActiveFacts CQL Parser.
3
- # A Rakefile to run Treetop when the ActiveFacts gem is installed.
4
- # This isn't mandatory but makes it much faster to start the parser.
5
- # Delete the generated files during parser development.
6
- #
7
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
8
- #
9
- task :default do
10
- pattern = File.dirname(__FILE__) + '**/*.treetop'
11
- files = Dir[pattern]
12
- # Hopefully this quoting will work where there are spaces in filenames, and even maybe on Windows?
13
- exec "tt '#{files*"' '"}'"
14
- end
@@ -1,258 +0,0 @@
1
- #
2
- # ActiveFacts CQL Parser.
3
- # Parse rules relating to high-level CQL definitions and constraints.
4
- #
5
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
6
- #
7
- require 'activefacts/cql/parser/LexicalRules'
8
- require 'activefacts/cql/parser/Language/English'
9
- require 'activefacts/cql/parser/Expressions'
10
- require 'activefacts/cql/parser/Terms'
11
- require 'activefacts/cql/parser/ObjectTypes'
12
- require 'activefacts/cql/parser/ValueTypes'
13
- require 'activefacts/cql/parser/FactTypes'
14
- require 'activefacts/cql/parser/TransformRules'
15
- require 'activefacts/cql/parser/Context'
16
-
17
- module ActiveFacts
18
- module CQL
19
- grammar CQL
20
- include LexicalRules
21
- include Expressions
22
- include Terms
23
- include ObjectTypes
24
- include ValueTypes
25
- include FactTypes
26
- include TransformRules
27
- include Context
28
-
29
- rule cql_file
30
- s seq:definition*
31
- {
32
- def definitions
33
- seq.elements.map{|e|
34
- e.value rescue $stderr.puts "Can't call value() on #{e.inspect}"
35
- }
36
- end
37
- }
38
- end
39
-
40
- # Each definition has an ast() method that returns an instance of a subclass of Compiler::Definition
41
- rule definition
42
- definition_body s
43
- {
44
- def ast
45
- definition_body.ast
46
- end
47
-
48
- def body
49
- definition_body.text_value
50
- end
51
- }
52
- end
53
-
54
- rule definition_body
55
- vocabulary_definition
56
- / import_definition
57
- # Magic here to avoid a Treetop bug with sem-preds, which require a sequence (this doesn't need to make a sequence)
58
- / '' &{|s| _nt_prescan; false } # Always fails, but its side-effects are needed in the following
59
- / constraint
60
- / unit_definition # REVISIT: Move this above the prescan?
61
- / object_type
62
- / informal_description
63
- / query
64
- / transform_rule
65
- / s ';' s { def ast; nil; end }
66
- end
67
-
68
- rule vocabulary_definition
69
- schema_definition /
70
- transform_definition
71
- end
72
-
73
- rule schema_definition
74
- s ( schema / topic / vocabulary ) S vocabulary_name vn:version_number? s ';'
75
- {
76
- def ast
77
- Compiler::Vocabulary.new(vocabulary_name.value, false, vn.empty? ? nil : vn.value)
78
- end
79
- }
80
- end
81
-
82
- rule transform_definition
83
- s transform S vocabulary_name vn:version_number? s ';'
84
- {
85
- def ast
86
- Compiler::Vocabulary.new(vocabulary_name.value, true, vn.empty? ? nil : vn.value)
87
- end
88
- }
89
- end
90
-
91
- rule vocabulary_name
92
- id tail:(S !version id)*
93
- {
94
- def node_type; :vocabulary; end
95
- def value
96
- [id.value, *tail.elements.map{|e| e.id.value }].join(' ')
97
- end
98
- }
99
- end
100
-
101
- rule import_definition
102
- s import i:import_role? S vocabulary_name vp:version_pattern? alias_list ';'
103
- {
104
- def ast
105
- Compiler::Import.new(
106
- import.input.parser, vocabulary_name.value, i.empty? ? "topic" : i.value, vp.empty? ? nil : vp.value, alias_list.value
107
- )
108
- end
109
- }
110
- end
111
-
112
- rule version_number
113
- S version S version_number_string
114
- {
115
- def value
116
- version_number_string.text_value
117
- end
118
- }
119
- end
120
-
121
- rule version_pattern
122
- S version S version_pattern_string
123
- {
124
- def value
125
- version_pattern_string.text_value
126
- end
127
- }
128
- end
129
-
130
- rule version_number_string
131
- [0-9]+ '.' [0-9]+ '.' [0-9]+ ('-' [0-9A-Za-z-]+ ('.' [0-9A-Za-z-]+ )* )?
132
- end
133
-
134
- rule version_pattern_string
135
- [0-9]+ ('.' [0-9]+ ('.' [0-9]+ ('-' [0-9A-Za-z-]+ ('.' [0-9A-Za-z-]+ )* )? )? )?
136
- end
137
-
138
- rule import_role
139
- S id
140
- {
141
- def value
142
- id.text_value
143
- end
144
- }
145
- end
146
-
147
- # REVISIT: Need a way to define equivalent readings for fact types here (and in the metamodel)
148
- rule alias_list
149
- ( s ',' s alias S aliased_from:alias_term S as S alias_to:alias_term s )*
150
- {
151
- def value
152
- elements.inject({}){|h, e| h[e.aliased_from.value] = e.alias_to; h }
153
- end
154
- }
155
- end
156
-
157
- rule alias_term
158
- id
159
- { def node_type; :term; end }
160
- end
161
-
162
- rule informal_description
163
- informally s ',' s
164
- subject:informal_description_subject s
165
- informal_description_body
166
- informal_description_closer
167
- {
168
- def ast
169
- kind = subject.signifier.text_value.to_sym
170
- subject_name = (kind == :each ? subject.term.text_value : subject.reading.text_value)
171
- phrases = subject.reading.elements.map(&:ast) if kind == :when
172
- Compiler::InformalDefinition.new(kind, subject_name, phrases, informal_description_body.text_value)
173
- end
174
- }
175
- end
176
-
177
- rule informal_description_subject
178
- signifier:each S term # Informal definition of an object type
179
- /
180
- signifier:when S reading:phrase+ s ',' # or a fact type
181
- end
182
-
183
- rule informal_description_body
184
- (!informal_description_closer (string / .))* # Allow . inside a string
185
- end
186
-
187
- # The description terminates in a fullstop at the end of a line, or EOF
188
- rule informal_description_closer
189
- (!. / '.' [ \t\r]* "\n")
190
- end
191
-
192
- rule constraint
193
- subset_constraint /
194
- equality_constraint /
195
- set_constraint /
196
- presence_constraint
197
- # REVISIT: / value_constraint
198
- end
199
-
200
- # Adding enforcement to a constraint makes it deontic
201
- rule enforcement
202
- s '(' s
203
- otherwise s
204
- action:id s # An enforcement action, like SMS, email, log, alarm, etc.
205
- a:agent? s
206
- ')' s
207
- {
208
- def ast; Compiler::Enforcement.new(action.text_value, a.empty? ? nil : a.text_value); end
209
- }
210
- /
211
- ''
212
- {
213
- def ast; nil; end
214
- }
215
- end
216
-
217
- # presence constraint:
218
- rule presence_constraint
219
- (each_occurs_in_clauses / either_or)
220
- {
221
- def ast
222
- Compiler::PresenceConstraint.new c, enforcement.ast, clauses_ast, role_list_ast, quantifier_ast
223
- end
224
- }
225
- end
226
-
227
- # set (exclusion, mandatory exclusion, complex equality) constraint
228
- rule set_constraint
229
- (for_each_how_many / either_or_not_both)
230
- {
231
- def ast
232
- Compiler::SetExclusionConstraint.new c, enforcement.ast, clauses_ast, role_list_ast, quantifier_ast
233
- end
234
- }
235
- end
236
-
237
- rule subset_constraint
238
- (a_only_if_b / if_b_then_a)
239
- {
240
- def ast
241
- Compiler::SubsetConstraint.new c, enforcement.ast, [clauses.ast, r2.ast]
242
- end
243
- }
244
- end
245
-
246
- rule equality_constraint
247
- if_and_only_if
248
- {
249
- def ast
250
- all_clauses = [clauses.ast, *tail.elements.map{|e| e.clauses.ast }]
251
- Compiler::SetEqualityConstraint.new c, enforcement.ast, all_clauses
252
- end
253
- }
254
- end
255
-
256
- end
257
- end
258
- end
@@ -1,46 +0,0 @@
1
- #
2
- # ActiveFacts CQL Parser.
3
- # Parse rules relating to definition context.
4
- #
5
- # Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
6
- #
7
- module ActiveFacts
8
- module CQL
9
- grammar Context
10
- rule context_note
11
- '('
12
- s w:who_says? s context_type description agreed:(',' a:as_agreed_by)? s
13
- ')' s
14
- {
15
- def value
16
- [ w.empty? ? nil : w.value, context_type.value, description.text_value, agreed.empty? ? [] : agreed.a.value]
17
- end
18
- def ast
19
- who = w.empty? ? nil : w.value
20
- ag = agreed.empty? ? [] : agreed.a.value
21
- Compiler::ContextNote.new context_type.value, description.text_value, who, ag
22
- end
23
- }
24
- end
25
-
26
- rule who_says
27
- according_to agents s ','
28
- { def value; agents.value; end }
29
- end
30
-
31
- rule context_type
32
- because s { def value; 'because'; end } /
33
- as_opposed_to { def value; 'as_opposed_to'; end } /
34
- so_that { def value; 'so_that'; end } /
35
- to_avoid { def value; 'to_avoid'; end }
36
- end
37
-
38
- rule description
39
- '(' description ')' / (!( [()] / ',' as_agreed_by) .)*
40
- {
41
- def node_type; :linking; end
42
- }
43
- end
44
- end
45
- end
46
- end