activefacts 0.7.3 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/Manifest.txt +24 -2
- data/Rakefile +25 -3
- data/bin/afgen +1 -1
- data/bin/cql +13 -2
- data/css/offline.css +3 -0
- data/css/orm2.css +24 -0
- data/css/print.css +8 -0
- data/css/style-print.css +357 -0
- data/css/style.css +387 -0
- data/download.html +85 -0
- data/examples/CQL/Address.cql +3 -3
- data/examples/CQL/Blog.cql +13 -14
- data/examples/CQL/CompanyDirectorEmployee.cql +4 -4
- data/examples/CQL/Death.cql +3 -2
- data/examples/CQL/Genealogy.cql +13 -11
- data/examples/CQL/Marriage.cql +2 -2
- data/examples/CQL/Metamodel.cql +136 -93
- data/examples/CQL/MultiInheritance.cql +2 -2
- data/examples/CQL/OilSupply.cql +14 -10
- data/examples/CQL/Orienteering.cql +22 -19
- data/examples/CQL/PersonPlaysGame.cql +3 -2
- data/examples/CQL/SchoolActivities.cql +4 -2
- data/examples/CQL/SimplestUnary.cql +1 -1
- data/examples/CQL/SubtypePI.cql +6 -7
- data/examples/CQL/Warehousing.cql +16 -19
- data/examples/CQL/unit.cql +584 -0
- data/examples/index.html +276 -0
- data/examples/intro.html +497 -0
- data/examples/local.css +20 -0
- data/index.html +96 -0
- data/lib/activefacts/api/concept.rb +48 -46
- data/lib/activefacts/api/constellation.rb +43 -23
- data/lib/activefacts/api/entity.rb +2 -2
- data/lib/activefacts/api/instance.rb +6 -2
- data/lib/activefacts/api/instance_index.rb +5 -0
- data/lib/activefacts/api/value.rb +8 -2
- data/lib/activefacts/api/vocabulary.rb +15 -10
- data/lib/activefacts/cql/CQLParser.treetop +109 -88
- data/lib/activefacts/cql/Concepts.treetop +32 -10
- data/lib/activefacts/cql/Context.treetop +34 -0
- data/lib/activefacts/cql/Expressions.treetop +9 -9
- data/lib/activefacts/cql/FactTypes.treetop +30 -31
- data/lib/activefacts/cql/Language/English.treetop +50 -0
- data/lib/activefacts/cql/LexicalRules.treetop +2 -1
- data/lib/activefacts/cql/Terms.treetop +117 -0
- data/lib/activefacts/cql/ValueTypes.treetop +152 -0
- data/lib/activefacts/cql/compiler.rb +1718 -0
- data/lib/activefacts/cql/parser.rb +124 -57
- data/lib/activefacts/generate/absorption.rb +1 -1
- data/lib/activefacts/generate/cql.rb +111 -100
- data/lib/activefacts/generate/cql/html.rb +5 -5
- data/lib/activefacts/generate/oo.rb +3 -3
- data/lib/activefacts/generate/ordered.rb +51 -19
- data/lib/activefacts/generate/ruby.rb +10 -8
- data/lib/activefacts/generate/sql/mysql.rb +14 -10
- data/lib/activefacts/generate/sql/server.rb +29 -24
- data/lib/activefacts/input/cql.rb +9 -1264
- data/lib/activefacts/input/orm.rb +213 -200
- data/lib/activefacts/persistence/columns.rb +11 -10
- data/lib/activefacts/persistence/index.rb +15 -18
- data/lib/activefacts/persistence/reference.rb +17 -17
- data/lib/activefacts/persistence/tables.rb +50 -51
- data/lib/activefacts/version.rb +1 -1
- data/lib/activefacts/vocabulary/extensions.rb +79 -8
- data/lib/activefacts/vocabulary/metamodel.rb +183 -114
- data/spec/absorption_ruby_spec.rb +99 -0
- data/spec/absorption_spec.rb +3 -4
- data/spec/api/constellation.rb +1 -1
- data/spec/api/entity_type.rb +3 -1
- data/spec/api/instance.rb +4 -2
- data/spec/api/roles.rb +8 -6
- data/spec/api_spec.rb +1 -2
- data/spec/cql/context_spec.rb +71 -0
- data/spec/cql/samples_spec.rb +154 -0
- data/spec/cql/unit_spec.rb +375 -0
- data/spec/cql_cql_spec.rb +31 -21
- data/spec/cql_mysql_spec.rb +70 -0
- data/spec/cql_parse_spec.rb +15 -9
- data/spec/cql_ruby_spec.rb +27 -13
- data/spec/cql_sql_spec.rb +42 -16
- data/spec/cql_symbol_tables_spec.rb +2 -3
- data/spec/cqldump_spec.rb +7 -7
- data/spec/helpers/file_matcher.rb +39 -0
- data/spec/norma_cql_spec.rb +20 -12
- data/spec/norma_ruby_spec.rb +6 -3
- data/spec/norma_sql_spec.rb +6 -3
- data/spec/norma_tables_spec.rb +6 -4
- data/spec/spec_helper.rb +27 -8
- data/status.html +69 -0
- data/why.html +60 -0
- metadata +34 -11
- data/lib/activefacts/cql/DataTypes.treetop +0 -81
- data/spec/cql_unit_spec.rb +0 -330
data/spec/cql_unit_spec.rb
DELETED
@@ -1,330 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# ActiveFacts tests: Test the CQL parser by looking at its parse trees.
|
3
|
-
# Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
|
4
|
-
#
|
5
|
-
require 'rubygems'
|
6
|
-
require 'treetop'
|
7
|
-
require 'activefacts/support'
|
8
|
-
require 'activefacts/api/support'
|
9
|
-
require 'activefacts/cql/parser'
|
10
|
-
|
11
|
-
describe "Valid Numbers, Strings and Ranges" do
|
12
|
-
ValidNumbersEtc = [
|
13
|
-
"a=b();", # Basic data type declaration, minimal whitespace
|
14
|
-
"a = b ( ) ; ", # Basic data type declaration, maximal whitespace
|
15
|
-
"a is written as b();", # Verbally named data type declaration
|
16
|
-
"a=b() inch;", # Data type declaration with unit
|
17
|
-
"a=b() inch ; ", # Data type declaration with unit
|
18
|
-
"a=b() inch^2 ; ", # Data type declaration with unit and exponent
|
19
|
-
|
20
|
-
# Comments etc as whitespace
|
21
|
-
"\na\n= \nb\n(\n)\n;\n", # Basic data type declaration, newlines for whitespace
|
22
|
-
"\ra\r=\rb\r(\r)\r;\r", # Basic data type declaration, returns for whitespace
|
23
|
-
"\ta\t=\tb\t(\t)\t;\t", # Basic data type declaration, tabs for whitespace
|
24
|
-
" /* Plugh */ a /* Plugh */ =\n b /* *Plugh* / */ ( /* *Plugh* / */ ) /* *Plugh* / */ ; /* *Plugh* / */ ",
|
25
|
-
"//Plugh\na // Plugh\n = // Plugh\n b // Plugh\n ( // Plugh\n ) // Plugh\n ; // Plugh\n ",
|
26
|
-
|
27
|
-
# Integers
|
28
|
-
"a=b(0);", # Integer zero
|
29
|
-
"a=b( 0 ) ; ", # Integer zero, maximal whitespace
|
30
|
-
"a=b(1);", # Integer one
|
31
|
-
"a=b(-1);", # Integer negative one
|
32
|
-
"a=b(+1);", # Positive integer
|
33
|
-
"a=b(1e4);", # Integer with exponent
|
34
|
-
"a=b(1e-4);", # Integer with negative exponent
|
35
|
-
"a=b(-1e-4);", # Negative integer with negative exponent
|
36
|
-
"a=b(077);", # Octal integer
|
37
|
-
"a=b(0xFace8);", # Hexadecimal integer
|
38
|
-
"a=b(0,1);", # Two parameters
|
39
|
-
"a=b( 0 , 1 );",
|
40
|
-
"a=b(0,1,2) ;", # Three parameters now allowed
|
41
|
-
|
42
|
-
# Reals
|
43
|
-
"a=b(1.0);",
|
44
|
-
"a=b(-1.0);",
|
45
|
-
"a=b(+1.0);",
|
46
|
-
"a=b(0.1);",
|
47
|
-
"a=b(-0.1);",
|
48
|
-
"a=b(+0.1);",
|
49
|
-
"a=b(0.0);",
|
50
|
-
"a=b(-0.0);",
|
51
|
-
"a=b(+0.0);",
|
52
|
-
|
53
|
-
# Integer value restrictions
|
54
|
-
"a=b()restricted to{1};", # Integer, minimal whitespace
|
55
|
-
"a=b() restricted to { 1 } ;", # Integer, maximal whitespace
|
56
|
-
"a=b() restricted to {1..2};", # Integer range, minimal whitespace
|
57
|
-
"a=b() restricted to { 1 .. 2 };", # Integer range, maximal whitespace
|
58
|
-
"a=b() restricted to {..2};", # Integer range with open start, minimal whitespace
|
59
|
-
"a=b() restricted to { .. 2 };", # Integer range with open start, maximal whitespace
|
60
|
-
"a=b() restricted to { ..2,3};", # Range followed by integer, minimal whitespace
|
61
|
-
"a=b() restricted to { 1,..2,3};", # Integer, open-start range, integer, minimal whitespace
|
62
|
-
"a=b() restricted to { .. 2 , 3 };", # Range followed by integer, maximal whitespace
|
63
|
-
"a=b() restricted to { ..2 , 3..4 };", # Range followed by range
|
64
|
-
"a=b() restricted to { ..2, 3..};", # Range followed by range with open end, minimal whitespace
|
65
|
-
"a=b() restricted to { ..2, 3 .. };", # Range followed by range with open end, maximal whitespace
|
66
|
-
"a=b() restricted to { 1e4 } ;", # Integer with exponent
|
67
|
-
"a=b() restricted to { -1e4 } ;", # Negative integer with exponent
|
68
|
-
"a=b() restricted to { 1e-4 } ;", # Integer with negative exponent
|
69
|
-
"a=b() restricted to { -1e-4 } ;", # Negative integer with negative exponent
|
70
|
-
|
71
|
-
# Real value restrictions
|
72
|
-
"a=b() restricted to {1.0};", # Real, minimal whitespace
|
73
|
-
"a=b() restricted to { 1.0 } ;", # Real, maximal whitespace
|
74
|
-
"a=b() restricted to { 1.0e4 } ;", # Real with exponent
|
75
|
-
"a=b() restricted to { 1.0e-4 } ;", # Real with negative exponent
|
76
|
-
"a=b() restricted to { -1.0e-4 } ;", # Negative real with negative exponent
|
77
|
-
"a=b() restricted to { 1.1 .. 2.2 } ;", # Real range, maximal whitespace
|
78
|
-
"a=b() restricted to { -1.1 .. 2.2 } ;", # Real range, maximal whitespace
|
79
|
-
"a=b() restricted to { 1.1..2.2};", # Real range, minimal whitespace
|
80
|
-
"a=b() restricted to { 1.1..2 } ;", # Real-integer range
|
81
|
-
"a=b() restricted to { 1..2.2 } ;", # Integer-real range
|
82
|
-
"a=b() restricted to { ..2.2};", # Real range with open start
|
83
|
-
"a=b() restricted to { 1.1.. };", # Real range with open end
|
84
|
-
"a=b() restricted to { 1.1.., 2 };", # Real range with open end and following integer
|
85
|
-
|
86
|
-
# Strings and string value restrictions
|
87
|
-
"a=b() restricted to {''};", # String, empty, minimal whitespace
|
88
|
-
"a=b() restricted to {'A'};", # String, minimal whitespace
|
89
|
-
"a=b() restricted to { 'A' };", # String, maximal whitespace
|
90
|
-
"a=b() restricted to { '\\b\\t\\f\\n\\r\\e\\\\' };", # String with special escapes
|
91
|
-
"a=b() restricted to { ' ' };", # String with space
|
92
|
-
"a=b() restricted to { '\t' };", # String with literal tab
|
93
|
-
"a=b() restricted to { '\\0' };", # String with nul character
|
94
|
-
"a=b() restricted to { '\\077' };", # String with octal escape
|
95
|
-
"a=b() restricted to { '\\0xA9' };", # String with hexadecimal escape
|
96
|
-
"a=b() restricted to { '\\0uBabe' };", # String with unicode escape
|
97
|
-
"a=b() restricted to {'A'..'F'};", # String range, minimal whitespace
|
98
|
-
"a=b() restricted to { 'A' .. 'F' };", # String range, maximal whitespace
|
99
|
-
"a=b() restricted to { ..'F' };", # String range, open start
|
100
|
-
"a=b() restricted to { 'A'.. };", # String range, open end
|
101
|
-
]
|
102
|
-
|
103
|
-
before :each do
|
104
|
-
@parser = ActiveFacts::CQLParser.new
|
105
|
-
end
|
106
|
-
|
107
|
-
ValidNumbersEtc.each do |c|
|
108
|
-
source, ast = *[c].flatten
|
109
|
-
it "should parse #{source.inspect}" do
|
110
|
-
result = @parser.parse_all(source, :definition)
|
111
|
-
|
112
|
-
puts @parser.failure_reason unless result
|
113
|
-
result.should_not be_nil
|
114
|
-
result.map{|d| d.value}.should == ast if ast
|
115
|
-
# puts result.map{|d| d.value}.inspect unless ast
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "Invalid Numbers and Strings" do
|
121
|
-
InvalidValueTypes = [
|
122
|
-
"a=b(08);", # Invalid octalnumber
|
123
|
-
"a=b(0xDice);", # Invalid hexadecimal
|
124
|
-
"a=b(- 1);", # Invalid negative
|
125
|
-
"a=b(+ 1);", # Invalid positive
|
126
|
-
"b(- 1e-4);", # Negative integer with negative exponent
|
127
|
-
"a=b(-077);", # Invalid negative octal
|
128
|
-
"a=b(-0xFace);", # Invalid negative hexadecimal
|
129
|
-
"a=b(.0);", # Invalid real
|
130
|
-
"a=b(0.);", # Invalid real
|
131
|
-
"b() inch ^2 ; ", # Illegal whitespace around unit exponent
|
132
|
-
"b() inch^ 2 ; ", # Illegal whitespace around unit exponent
|
133
|
-
"b() restricted to { '\\7a' };", # String with bad octal escape
|
134
|
-
"b() restricted to { '\001' };", # String with control char
|
135
|
-
"b() restricted to { '\n' };", # String with literal newline
|
136
|
-
"b() restricted to { 0..'A' };", # Cross-typed range
|
137
|
-
"b() restricted to { 'a'..27 };", # Cross-typed range
|
138
|
-
]
|
139
|
-
|
140
|
-
before :each do
|
141
|
-
@parser = ActiveFacts::CQLParser.new
|
142
|
-
end
|
143
|
-
|
144
|
-
InvalidValueTypes.each do |c|
|
145
|
-
source, ast = *c
|
146
|
-
it "should not parse #{source.inspect}" do
|
147
|
-
result = @parser.parse_all(source, :definition)
|
148
|
-
|
149
|
-
# puts @parser.failure_reason unless result.success?
|
150
|
-
result.should be_nil
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "Data Types" do
|
156
|
-
DataTypes = [
|
157
|
-
[ "a = b(1, 2) inch restricted to { 3 .. 4 } inch ;",
|
158
|
-
[["a", [:data_type, "b", [ 1, 2 ], "inch", [[3, 4]]]]]
|
159
|
-
],
|
160
|
-
# [ "a c = b(1, 2) inch restricted to { 3 .. 4 } inch ;",
|
161
|
-
# [["a c", [:data_type, "b", [1, 2], "inch", [[3, 4]]]]]
|
162
|
-
# ],
|
163
|
-
]
|
164
|
-
|
165
|
-
before :each do
|
166
|
-
@parser = ActiveFacts::CQLParser.new
|
167
|
-
end
|
168
|
-
|
169
|
-
DataTypes.each do |c|
|
170
|
-
source, ast = *c
|
171
|
-
it "should parse #{source.inspect}" do
|
172
|
-
result = @parser.parse_all(source, :definition)
|
173
|
-
|
174
|
-
puts @parser.failure_reason unless result
|
175
|
-
result.should_not be_nil
|
176
|
-
|
177
|
-
result.map{|d| d.value}.should == ast if ast
|
178
|
-
puts result.map{|d| d.value}.inspect unless ast
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "Entity Types" do
|
184
|
-
EntityTypes_RefMode = [
|
185
|
-
=begin
|
186
|
-
[ "a = entity(.id):c;", # Entity type declaration with reference mode
|
187
|
-
[["a", [:entity_type, [], {:mode=>"id"}, [[:fact_clause, [], [{:word=>"c"}]]]]]]
|
188
|
-
],
|
189
|
-
[ "a = entity ( . id ) : c ;", # Entity type declaration with reference mode, maximal whitespace
|
190
|
-
[["a", [:entity_type, [], {:mode=>"id"}, [[:fact_clause, [], [{:word=>"c"}]]]]]]
|
191
|
-
],
|
192
|
-
[ "a = entity(.id) where c;", # Entity type declaration with reference mode and where
|
193
|
-
[["a", [:entity_type, [], {:mode=>"id"}, [[:fact_clause, [], [{:word=>"c"}]]]]]]
|
194
|
-
],
|
195
|
-
=end
|
196
|
-
]
|
197
|
-
|
198
|
-
EntityTypes_Simple = [
|
199
|
-
[ "a is identified by b: c;", # Entity type declaration
|
200
|
-
[["a", [:entity_type, [], {:roles=>[["b"]]}, [[:fact_clause, [], [{:word=>"c"}]]]]]]
|
201
|
-
],
|
202
|
-
[ "a is identified by b where c;", # Entity type declaration with where
|
203
|
-
[["a", [:entity_type, [], {:roles=>[["b"]]}, [[:fact_clause, [], [{:word=>"c"}]]]]]]
|
204
|
-
],
|
205
|
-
[ "a is identified by b and c: d;", # Entity type declaration with two-part identifier
|
206
|
-
[["a", [:entity_type, [], {:roles=>[["b"], ["c"]]}, [[:fact_clause, [], [{:word=>"d"}]]]]]]
|
207
|
-
],
|
208
|
-
[ "a is identified by b, c: d;", # Entity type declaration with two-part identifier
|
209
|
-
[["a", [:entity_type, [], {:roles=>[["b"], ["c"]]}, [[:fact_clause, [], [{:word=>"d"}]]]]]]
|
210
|
-
],
|
211
|
-
[ "a=b(); c is identified by a:d;",
|
212
|
-
[["a", [:data_type, "b", [], nil, []]],
|
213
|
-
["c", [:entity_type, [], {:roles=>[["a"]]}, [[:fact_clause, [], [{:word=>"d"}]]]]]]
|
214
|
-
],
|
215
|
-
[ " a = b ( ) ; c is identified by a : d ; ",
|
216
|
-
[["a", [:data_type, "b", [ ], nil, []]],
|
217
|
-
["c", [:entity_type, [], {:roles=>[["a"]]}, [[:fact_clause, [], [{:word=>"d"}]]]]]]
|
218
|
-
],
|
219
|
-
[ "a is identified by c:maybe d;",
|
220
|
-
[["a", [:entity_type, [], {:roles=>[["c"]]}, [[:fact_clause, ["maybe"], [{:word=>"d"}]]]]]]
|
221
|
-
],
|
222
|
-
]
|
223
|
-
|
224
|
-
EntityTypes_Objectified = [
|
225
|
-
[ "Director = Person directs Company, Company is directed by Person;",
|
226
|
-
[["Director", [:fact_type, [[:fact_clause, [], [{:word=>"Person"}, {:word=>"directs"}, {:word=>"Company"}]], [:fact_clause, [], [{:word=>"Company"}, {:word=>"is"}, {:word=>"directed"}, {:word=>"by"}, {:word=>"Person"}]]], []]]]
|
227
|
-
],
|
228
|
-
[ "Director: Person directs company;",
|
229
|
-
[[nil, [:fact_type, [[:fact_clause, [], [{:word=>"Director"}]]], [[:fact_clause, [], [{:word=>"Person"}, {:word=>"directs"}, {:word=>"company"}]]]]]]
|
230
|
-
],
|
231
|
-
]
|
232
|
-
|
233
|
-
EntityTypes_Subtypes = [
|
234
|
-
[ "Employee is a kind of Person;",
|
235
|
-
[["Employee", [:entity_type, ["Person"], nil, nil]]]
|
236
|
-
],
|
237
|
-
[ "Employee is a subtype of Person;",
|
238
|
-
[["Employee", [:entity_type, ["Person"], nil, nil]]]
|
239
|
-
],
|
240
|
-
[ "AustralianEmployee is a subtype of Employee, Australian;",
|
241
|
-
[["AustralianEmployee", [:entity_type, ["Employee", "Australian"], nil, nil]]]
|
242
|
-
],
|
243
|
-
[ "Employee is a kind of Person identified by EmployeeNumber;",
|
244
|
-
[["Employee", [:entity_type, ["Person"], {:roles=>[["EmployeeNumber"]]}, nil]]]
|
245
|
-
],
|
246
|
-
[ "Employee is a subtype of Person identified by EmployeeNumber;",
|
247
|
-
[["Employee", [:entity_type, ["Person"], {:roles=>[["EmployeeNumber"]]}, nil]]]
|
248
|
-
],
|
249
|
-
[ "AustralianEmployee is a subtype of Employee, Australian identified by TaxFileNumber;",
|
250
|
-
[["AustralianEmployee", [:entity_type, ["Employee", "Australian"], {:roles=>[["TaxFileNumber"]]}, nil]]]
|
251
|
-
],
|
252
|
-
]
|
253
|
-
|
254
|
-
EntityTypes =
|
255
|
-
EntityTypes_RefMode +
|
256
|
-
EntityTypes_Simple +
|
257
|
-
EntityTypes_Objectified +
|
258
|
-
EntityTypes_Subtypes
|
259
|
-
|
260
|
-
before :each do
|
261
|
-
@parser = ActiveFacts::CQLParser.new
|
262
|
-
end
|
263
|
-
|
264
|
-
EntityTypes.each do |c|
|
265
|
-
source, ast = *c
|
266
|
-
it "should parse #{source.inspect}" do
|
267
|
-
result = @parser.parse_all(source, :definition)
|
268
|
-
|
269
|
-
puts @parser.failure_reason unless result
|
270
|
-
|
271
|
-
result.should_not be_nil
|
272
|
-
if ast
|
273
|
-
result.map{|d| d.value}.should == ast
|
274
|
-
else
|
275
|
-
puts "\n"+result.map{|d| d.value}.inspect
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
describe "Fact Types" do
|
282
|
-
FactTypes = [
|
283
|
-
[ "Director is old: Person directs company, Person is of age, age > 60;",
|
284
|
-
[nil, [:fact_type, [[:fact_clause, [], [{:word=>"Director"}, {:word=>"is"}, {:word=>"old"}]]], [[:fact_clause, [], [{:word=>"Person"}, {:word=>"directs"}, {:word=>"company"}]], [:fact_clause, [], [{:word=>"Person"}, {:word=>"is"}, {:word=>"of"}, {:word=>"age"}]], [">", [:variable, "age"], 60]]]]
|
285
|
-
],
|
286
|
-
[ "a: maybe a has completely- green b -totally [transitive, acyclic], b -c = 2;",
|
287
|
-
[nil, [:fact_type, [[:fact_clause, [], [{:word=>"a"}]]], [[:fact_clause, ["maybe", "transitive", "acyclic"], [{:word=>"a"}, {:word=>"has"}, {:word=>"green", :leading_adjective=>"completely"}, {:word=>"b", :trailing_adjective=>"totally"}]], ["=", [:+, [:variable, "b"], [:-, [:variable, "c"]]], 2]]]]
|
288
|
-
],
|
289
|
-
[ "Person is independent: Person has taxable- Income, taxable Income >= 20000 dollars;",
|
290
|
-
[nil, [:fact_type, [[:fact_clause, [], [{:word=>"Person"}, {:word=>"is"}, {:word=>"independent"}]]], [[:fact_clause, [], [{:word=>"Person"}, {:word=>"has"}, {:leading_adjective=>"taxable", :word=>"Income"}]], [">=", [:variable, "taxable", "Income"], [20000, "dollars"]]]]]
|
291
|
-
],
|
292
|
-
[ "Window requires toughening: Window has width-mm, Window has height-mm, width mm * height mm >= 10 foot^2;",
|
293
|
-
[nil, [:fact_type, [[:fact_clause, [], [{:word=>"Window"}, {:word=>"requires"}, {:word=>"toughening"}]]], [[:fact_clause, [], [{:word=>"Window"}, {:word=>"has"}, {:leading_adjective=>"width", :word=>"mm"}]], [:fact_clause, [], [{:word=>"Window"}, {:word=>"has"}, {:leading_adjective=>"height", :word=>"mm"}]], [">=", [:*, [:variable, "width", "mm"], [:variable, "height", "mm"]], [10, "foot^2"]]]]]
|
294
|
-
],
|
295
|
-
# REVISIT: Test all quantifiers
|
296
|
-
# REVISIT: Test all post-qualifiers
|
297
|
-
# REVISIT: Test functions
|
298
|
-
[ "AnnualIncome is where Person has total- Income in Year: Person has total- Income.sum(), Income was earned in current- time.Year() (as Year);",
|
299
|
-
["AnnualIncome", [:fact_type, [[:fact_clause, [], [{:word=>"Person"}, {:word=>"has"}, {:leading_adjective=>"total", :word=>"Income"}, {:word=>"in"}, {:word=>"Year"}]]], [[:fact_clause, [], [{:word=>"Person"}, {:word=>"has"}, {:function=>[:"(", "sum"], :leading_adjective=>"total", :word=>"Income"}]], [:fact_clause, [], [{:word=>"Income"}, {:word=>"was"}, {:word=>"earned"}, {:word=>"in"}, {:function=>[:"(", "Year"], :word=>"time", :role_name=>"Year", :leading_adjective=>"current"}]]]]]
|
300
|
-
],
|
301
|
-
[ "a is interesting : b- c -d has e- f -g;",
|
302
|
-
[nil, [:fact_type, [[:fact_clause, [], [{:word=>"a"}, {:word=>"is"}, {:word=>"interesting"}]]], [[:fact_clause, [], [{:trailing_adjective=>"d", :word=>"c", :leading_adjective=>"b"}, {:word=>"has"}, {:trailing_adjective=>"g", :word=>"f", :leading_adjective=>"e"}]]]]]
|
303
|
-
]
|
304
|
-
]
|
305
|
-
|
306
|
-
before :each do
|
307
|
-
@parser = ActiveFacts::CQLParser.new
|
308
|
-
end
|
309
|
-
|
310
|
-
FactTypes.each do |c|
|
311
|
-
source, ast, definition = *c
|
312
|
-
it "should parse #{source.inspect}" do
|
313
|
-
definitions = @parser.parse_all(source, :definition)
|
314
|
-
|
315
|
-
puts @parser.failure_reason unless definitions
|
316
|
-
|
317
|
-
definitions.should_not be_nil
|
318
|
-
result = definitions[-1]
|
319
|
-
|
320
|
-
if (definition)
|
321
|
-
result.definition.should == definition
|
322
|
-
else
|
323
|
-
#p @parser.definition(result)
|
324
|
-
end
|
325
|
-
|
326
|
-
result.value.should == ast if ast
|
327
|
-
puts result.map{|d| d.value}.inspect unless ast
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|