activefacts 0.7.3 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/LICENSE +19 -0
  2. data/Manifest.txt +24 -2
  3. data/Rakefile +25 -3
  4. data/bin/afgen +1 -1
  5. data/bin/cql +13 -2
  6. data/css/offline.css +3 -0
  7. data/css/orm2.css +24 -0
  8. data/css/print.css +8 -0
  9. data/css/style-print.css +357 -0
  10. data/css/style.css +387 -0
  11. data/download.html +85 -0
  12. data/examples/CQL/Address.cql +3 -3
  13. data/examples/CQL/Blog.cql +13 -14
  14. data/examples/CQL/CompanyDirectorEmployee.cql +4 -4
  15. data/examples/CQL/Death.cql +3 -2
  16. data/examples/CQL/Genealogy.cql +13 -11
  17. data/examples/CQL/Marriage.cql +2 -2
  18. data/examples/CQL/Metamodel.cql +136 -93
  19. data/examples/CQL/MultiInheritance.cql +2 -2
  20. data/examples/CQL/OilSupply.cql +14 -10
  21. data/examples/CQL/Orienteering.cql +22 -19
  22. data/examples/CQL/PersonPlaysGame.cql +3 -2
  23. data/examples/CQL/SchoolActivities.cql +4 -2
  24. data/examples/CQL/SimplestUnary.cql +1 -1
  25. data/examples/CQL/SubtypePI.cql +6 -7
  26. data/examples/CQL/Warehousing.cql +16 -19
  27. data/examples/CQL/unit.cql +584 -0
  28. data/examples/index.html +276 -0
  29. data/examples/intro.html +497 -0
  30. data/examples/local.css +20 -0
  31. data/index.html +96 -0
  32. data/lib/activefacts/api/concept.rb +48 -46
  33. data/lib/activefacts/api/constellation.rb +43 -23
  34. data/lib/activefacts/api/entity.rb +2 -2
  35. data/lib/activefacts/api/instance.rb +6 -2
  36. data/lib/activefacts/api/instance_index.rb +5 -0
  37. data/lib/activefacts/api/value.rb +8 -2
  38. data/lib/activefacts/api/vocabulary.rb +15 -10
  39. data/lib/activefacts/cql/CQLParser.treetop +109 -88
  40. data/lib/activefacts/cql/Concepts.treetop +32 -10
  41. data/lib/activefacts/cql/Context.treetop +34 -0
  42. data/lib/activefacts/cql/Expressions.treetop +9 -9
  43. data/lib/activefacts/cql/FactTypes.treetop +30 -31
  44. data/lib/activefacts/cql/Language/English.treetop +50 -0
  45. data/lib/activefacts/cql/LexicalRules.treetop +2 -1
  46. data/lib/activefacts/cql/Terms.treetop +117 -0
  47. data/lib/activefacts/cql/ValueTypes.treetop +152 -0
  48. data/lib/activefacts/cql/compiler.rb +1718 -0
  49. data/lib/activefacts/cql/parser.rb +124 -57
  50. data/lib/activefacts/generate/absorption.rb +1 -1
  51. data/lib/activefacts/generate/cql.rb +111 -100
  52. data/lib/activefacts/generate/cql/html.rb +5 -5
  53. data/lib/activefacts/generate/oo.rb +3 -3
  54. data/lib/activefacts/generate/ordered.rb +51 -19
  55. data/lib/activefacts/generate/ruby.rb +10 -8
  56. data/lib/activefacts/generate/sql/mysql.rb +14 -10
  57. data/lib/activefacts/generate/sql/server.rb +29 -24
  58. data/lib/activefacts/input/cql.rb +9 -1264
  59. data/lib/activefacts/input/orm.rb +213 -200
  60. data/lib/activefacts/persistence/columns.rb +11 -10
  61. data/lib/activefacts/persistence/index.rb +15 -18
  62. data/lib/activefacts/persistence/reference.rb +17 -17
  63. data/lib/activefacts/persistence/tables.rb +50 -51
  64. data/lib/activefacts/version.rb +1 -1
  65. data/lib/activefacts/vocabulary/extensions.rb +79 -8
  66. data/lib/activefacts/vocabulary/metamodel.rb +183 -114
  67. data/spec/absorption_ruby_spec.rb +99 -0
  68. data/spec/absorption_spec.rb +3 -4
  69. data/spec/api/constellation.rb +1 -1
  70. data/spec/api/entity_type.rb +3 -1
  71. data/spec/api/instance.rb +4 -2
  72. data/spec/api/roles.rb +8 -6
  73. data/spec/api_spec.rb +1 -2
  74. data/spec/cql/context_spec.rb +71 -0
  75. data/spec/cql/samples_spec.rb +154 -0
  76. data/spec/cql/unit_spec.rb +375 -0
  77. data/spec/cql_cql_spec.rb +31 -21
  78. data/spec/cql_mysql_spec.rb +70 -0
  79. data/spec/cql_parse_spec.rb +15 -9
  80. data/spec/cql_ruby_spec.rb +27 -13
  81. data/spec/cql_sql_spec.rb +42 -16
  82. data/spec/cql_symbol_tables_spec.rb +2 -3
  83. data/spec/cqldump_spec.rb +7 -7
  84. data/spec/helpers/file_matcher.rb +39 -0
  85. data/spec/norma_cql_spec.rb +20 -12
  86. data/spec/norma_ruby_spec.rb +6 -3
  87. data/spec/norma_sql_spec.rb +6 -3
  88. data/spec/norma_tables_spec.rb +6 -4
  89. data/spec/spec_helper.rb +27 -8
  90. data/status.html +69 -0
  91. data/why.html +60 -0
  92. metadata +34 -11
  93. data/lib/activefacts/cql/DataTypes.treetop +0 -81
  94. data/spec/cql_unit_spec.rb +0 -330
@@ -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