expressir 0.2.13-x64-mingw32 → 0.2.18-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +56 -11
  3. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  4. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  5. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  6. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  7. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  8. data/lib/expressir/express_exp/formatter.rb +201 -147
  9. data/lib/expressir/express_exp/hyperlink_formatter.rb +6 -4
  10. data/lib/expressir/express_exp/parser.rb +38 -25
  11. data/lib/expressir/express_exp/schema_head_formatter.rb +2 -7
  12. data/lib/expressir/express_exp/visitor.rb +27 -54
  13. data/lib/expressir/model.rb +2 -1
  14. data/lib/expressir/model/entity.rb +6 -6
  15. data/lib/expressir/model/expressions/query_expression.rb +3 -3
  16. data/lib/expressir/model/function.rb +15 -11
  17. data/lib/expressir/model/informal_proposition.rb +4 -1
  18. data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +2 -2
  19. data/lib/expressir/model/interfaced_item.rb +26 -0
  20. data/lib/expressir/model/model_element.rb +28 -7
  21. data/lib/expressir/model/procedure.rb +15 -11
  22. data/lib/expressir/model/repository.rb +3 -3
  23. data/lib/expressir/model/rule.rb +16 -12
  24. data/lib/expressir/model/schema.rb +60 -29
  25. data/lib/expressir/model/statements/alias.rb +3 -3
  26. data/lib/expressir/model/statements/repeat.rb +3 -3
  27. data/lib/expressir/model/subtype_constraint.rb +1 -6
  28. data/lib/expressir/model/type.rb +9 -5
  29. data/lib/expressir/version.rb +1 -1
  30. data/original/examples/syntax/multiple.exp +23 -0
  31. data/original/examples/syntax/multiple.yaml +184 -0
  32. data/original/examples/syntax/multiple_formatted.exp +71 -0
  33. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  34. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  35. data/original/examples/syntax/remark.exp +41 -41
  36. data/original/examples/syntax/remark.yaml +446 -0
  37. data/original/examples/syntax/remark_formatted.exp +62 -50
  38. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  39. data/original/examples/syntax/single.yaml +9 -0
  40. data/original/examples/syntax/single_formatted.exp +6 -0
  41. data/original/examples/syntax/single_formatted.yaml +19 -0
  42. data/original/examples/syntax/single_root_path.yaml +9 -0
  43. data/original/examples/syntax/syntax.exp +29 -19
  44. data/original/examples/syntax/syntax.yaml +3439 -0
  45. data/original/examples/syntax/syntax_formatted.exp +271 -131
  46. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  47. data/spec/expressir/express_exp/formatter_spec.rb +111 -0
  48. data/spec/expressir/express_exp/parser_spec.rb +121 -0
  49. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +110 -10
  50. metadata +20 -18
  51. data/original/examples/syntax/hyperlink.exp +0 -8
  52. data/original/examples/syntax/hyperlink_formatted.exp +0 -19
  53. data/original/examples/syntax/source.exp +0 -16
  54. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  55. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  56. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -24
  57. data/spec/expressir/express_exp/parser/head_source_spec.rb +0 -38
  58. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -32
  59. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  60. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  61. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3080
  62. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -36
  63. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 893b08150342d7e5e7d8ec1f0edd111c916355ef2b619e5b99d6faac4e5cd967
4
- data.tar.gz: 20fec0d8ca1b42dce5dd650c50514bc8d6b1e3985278fd3a37613d51534fc0ae
3
+ metadata.gz: 74fbffaca7721129472a080630b58879825bb258d21167c9be56e6550a79218f
4
+ data.tar.gz: 1e16a2240c951ceca1f4b5efbbecb798dcd4081df42546b973e66079e4212abc
5
5
  SHA512:
6
- metadata.gz: 51dbf159b960e3d973b27239be90a2321598b0557c1c50bff4b74e305564fd8a06fc34efc534382524085102ede330e5961b5ec4a198fea721bf1ec4f9fbec36
7
- data.tar.gz: 40ae0df6545e9fd98271507696074d5d43339c62feefead2a21590ce7a60eb950037f0efb25deb8cad74f73f29b268fc44a73482fab597a076055a77ad264f8e
6
+ metadata.gz: f7b9873a16fcbb596c8e64ce29fc343927922dc97fde81ee36e2412379e81986ee674981bf600534d84b301bc54540f26263cdcabca495f7a53ca86eb1fd700f
7
+ data.tar.gz: 365b91eca6706ac74aa977e9aad173e9a1a5d34c2285f49a6196db1daefb1cfaaeea2ed204bb10b74ad18adba9e2831545439f9de92264933a9c27e7ae209a6b
data/exe/format CHANGED
@@ -1,20 +1,65 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "yaml"
3
4
  require "expressir/express_exp/parser"
5
+ require "expressir/express_exp/formatter"
6
+ require "expressir/express_exp/schema_head_formatter"
4
7
  require "expressir/express_exp/hyperlink_formatter"
5
8
 
6
- input_files = [
7
- '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
8
- '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
9
- '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
10
- # cyclic reference
9
+ exp_files = [
10
+ # basic test
11
+ # '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
12
+ # '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
13
+ # '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
14
+ # cyclic reference test
15
+ # '../iso-10303-stepmod/data/modules/analysis/mim_annotated.exp',
16
+ # '../iso-10303-stepmod/data/modules/analysis_product_relationships/mim_annotated.exp',
17
+ # cyclic reference test 2
11
18
  # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
12
- # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp'
19
+ # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
20
+ # renamed reference test (36s)
21
+ # '../iso-10303-stepmod/ballots/ballots/ap210_wg12/express/resources/mathematical_functions_schema.exp',
22
+ # '../iso-10303-stepmod/data/resources/iso13584_expressions_schema/iso13584_expressions_schema.exp',
23
+ # annotated-express test (12s)
24
+ # see https://github.com/metanorma/annotated-express/blob/master/data/documents/resources/fundamentals_of_product_description_and_support/sections/04-schemas.adoc
25
+ # '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
26
+ # '../iso-10303-stepmod/data/resources/application_context_schema/application_context_schema_annotated.exp',
27
+ # '../iso-10303-stepmod/data/resources/approval_schema/approval_schema_annotated.exp',
28
+ # '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
29
+ # '../iso-10303-stepmod/data/resources/certification_schema/certification_schema_annotated.exp',
30
+ # '../iso-10303-stepmod/data/resources/contract_schema/contract_schema_annotated.exp',
31
+ # '../iso-10303-stepmod/data/resources/date_time_schema/date_time_schema_annotated.exp',
32
+ # '../iso-10303-stepmod/data/resources/document_schema/document_schema.exp',
33
+ # '../iso-10303-stepmod/data/resources/effectivity_schema/effectivity_schema_annotated.exp',
34
+ # '../iso-10303-stepmod/data/resources/experience_schema/experience_schema_annotated.exp',
35
+ # '../iso-10303-stepmod/data/resources/external_reference_schema/external_reference_schema_annotated.exp',
36
+ # '../iso-10303-stepmod/data/resources/group_schema/group_schema_annotated.exp',
37
+ # '../iso-10303-stepmod/data/resources/language_schema/language_schema_annotated.exp',
38
+ # '../iso-10303-stepmod/data/resources/location_schema/location_schema_annotated.exp',
39
+ # '../iso-10303-stepmod/data/resources/management_resources_schema/management_resources_schema_annotated.exp',
40
+ # '../iso-10303-stepmod/data/resources/measure_schema/measure_schema_annotated.exp',
41
+ # '../iso-10303-stepmod/data/resources/person_organization_schema/person_organization_schema_annotated.exp',
42
+ # '../iso-10303-stepmod/data/resources/process_property_schema/process_property_schema_annotated.exp',
43
+ # '../iso-10303-stepmod/data/resources/product_definition_schema/product_definition_schema_annotated.exp',
44
+ # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
45
+ # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
46
+ # '../iso-10303-stepmod/data/resources/qualifications_schema/qualifications_schema_annotated.exp',
47
+ # '../iso-10303-stepmod/data/resources/security_classification_schema/security_classification_schema_annotated.exp',
48
+ # '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
49
+ # full test (6m18s + 8s = 6m26s)
50
+ *`bundle exec ../stepmod-utils/exe/stepmod-find-express-files ../iso-10303-stepmod`.strip.split("\n").map{|file| File.exists?(file.sub(/\.exp$/, '_annotated.exp')) ? file.sub(/\.exp$/, '_annotated.exp') : file}
13
51
  ]
14
52
 
15
- repo = Expressir::ExpressExp::Parser.from_files(input_files)
16
- schema = repo.schemas.find{|x| x.id == 'action_schema'}
17
- # schema = repo.schemas.find{|x| x.id == 'product_property_definition_schema'}
18
- result = Expressir::ExpressExp::HyperlinkFormatter.format(schema)
53
+ start = Time.now
54
+ repository = Expressir::ExpressExp::Parser.from_files(exp_files)
55
+ puts "Parsing time: #{Time.now - start}"
56
+ start2 = Time.now
57
+ formatter = Class.new(Expressir::ExpressExp::Formatter) do
58
+ include Expressir::ExpressExp::SchemaHeadFormatter
59
+ include Expressir::ExpressExp::HyperlinkFormatter
60
+ end
61
+ result = repository.to_hash(formatter: formatter, skip_empty: true)
62
+ puts "Formatting & serializing time: #{Time.now - start2}"
63
+ puts "Total time: #{Time.now - start}"
19
64
 
20
- puts result
65
+ # puts YAML.dump(result)
@@ -50,12 +50,12 @@ module Expressir
50
50
  format_function(node)
51
51
  elsif node.is_a? Model::Interface
52
52
  format_interface(node)
53
+ elsif node.is_a? Model::InterfaceItem
54
+ format_interface_item(node)
53
55
  elsif node.is_a? Model::Parameter
54
56
  format_parameter(node)
55
57
  elsif node.is_a? Model::Procedure
56
58
  format_procedure(node)
57
- elsif node.is_a? Model::RenamedRef
58
- format_renamed_ref(node)
59
59
  elsif node.is_a? Model::Repository
60
60
  format_repository(node)
61
61
  elsif node.is_a? Model::Rule
@@ -163,7 +163,8 @@ module Expressir
163
163
  elsif node.is_a? Model::Types::String
164
164
  format_types_string(node)
165
165
  else
166
- puts node.class
166
+ STDERR.puts "#{node.class.name} format not implemented"
167
+ ''
167
168
  end
168
169
  end
169
170
 
@@ -245,51 +246,55 @@ module Expressir
245
246
  *if node.abstract and !node.supertype_expression
246
247
  [
247
248
  "\n",
248
- INDENT,
249
- 'ABSTRACT',
250
- ' ',
251
- 'SUPERTYPE'
249
+ indent([
250
+ 'ABSTRACT',
251
+ ' ',
252
+ 'SUPERTYPE'
253
+ ].join(''))
252
254
  ].join('')
253
255
  end,
254
256
  *if node.abstract and node.supertype_expression
255
257
  [
256
258
  "\n",
257
- INDENT,
258
- 'ABSTRACT',
259
- ' ',
260
- 'SUPERTYPE',
261
- ' ',
262
- 'OF',
263
- ' ',
264
- '(',
265
- format(node.supertype_expression),
266
- ')'
259
+ indent([
260
+ 'ABSTRACT',
261
+ ' ',
262
+ 'SUPERTYPE',
263
+ ' ',
264
+ 'OF',
265
+ ' ',
266
+ '(',
267
+ format(node.supertype_expression),
268
+ ')'
269
+ ].join(''))
267
270
  ].join('')
268
271
  end,
269
272
  *if !node.abstract and node.supertype_expression
270
273
  [
271
274
  "\n",
272
- INDENT,
273
- 'SUPERTYPE',
274
- ' ',
275
- 'OF',
276
- ' ',
277
- '(',
278
- format(node.supertype_expression),
279
- ')'
275
+ indent([
276
+ 'SUPERTYPE',
277
+ ' ',
278
+ 'OF',
279
+ ' ',
280
+ '(',
281
+ format(node.supertype_expression),
282
+ ')'
283
+ ].join(''))
280
284
  ].join('')
281
285
  end,
282
- *if node.subtype_of and node.subtype_of.length > 0
286
+ *if node.subtype_of.length > 0
283
287
  [
284
288
  "\n",
285
- INDENT,
286
- 'SUBTYPE',
287
- ' ',
288
- 'OF',
289
- ' ',
290
- '(',
291
- node.subtype_of.map{|x| format(x)}.join(', '),
292
- ')'
289
+ indent([
290
+ 'SUBTYPE',
291
+ ' ',
292
+ 'OF',
293
+ ' ',
294
+ '(',
295
+ node.subtype_of.map{|x| format(x)}.join(', '),
296
+ ')'
297
+ ].join(''))
293
298
  ].join('')
294
299
  end,
295
300
  ';'
@@ -298,28 +303,28 @@ module Expressir
298
303
  indent(explicit_attributes.map{|x| format(x)}.join("\n"))
299
304
  end,
300
305
  *if derived_attributes and derived_attributes.length > 0
301
- indent([
306
+ [
302
307
  'DERIVE',
303
308
  indent(derived_attributes.map{|x| format(x)}.join("\n")),
304
- ].join("\n"))
309
+ ]
305
310
  end,
306
311
  *if inverse_attributes and inverse_attributes.length > 0
307
- indent([
312
+ [
308
313
  'INVERSE',
309
314
  indent(inverse_attributes.map{|x| format(x)}.join("\n")),
310
- ].join("\n"))
315
+ ]
311
316
  end,
312
- *if node.unique and node.unique.length > 0
313
- indent([
317
+ *if node.unique.length > 0
318
+ [
314
319
  'UNIQUE',
315
320
  indent(node.unique.map{|x| format(x)}.join("\n"))
316
- ].join("\n"))
321
+ ]
317
322
  end,
318
- *if node.where and node.where.length > 0
319
- indent([
323
+ *if node.where.length > 0
324
+ [
320
325
  'WHERE',
321
326
  indent(node.where.map{|x| format(x)}.join("\n")),
322
- ].join("\n"))
327
+ ]
323
328
  end,
324
329
  [
325
330
  'END_ENTITY',
@@ -338,10 +343,11 @@ module Expressir
338
343
  'FUNCTION',
339
344
  ' ',
340
345
  node.id,
341
- *if node.parameters and node.parameters.length > 0
346
+ *if node.parameters.length > 0
347
+ parameter_indent = INDENT_CHAR * "FUNCTION #{node.id}(".length
342
348
  [
343
349
  '(',
344
- node.parameters.map{|x| format(x)}.join('; '),
350
+ node.parameters.map{|x| format(x)}.join(";\n#{parameter_indent}"),
345
351
  ')'
346
352
  ].join('')
347
353
  end,
@@ -351,22 +357,22 @@ module Expressir
351
357
  format(node.return_type),
352
358
  ';'
353
359
  ].join(''),
354
- *if node.types and node.types.length > 0
360
+ *if node.types.length > 0
355
361
  indent(node.types.map{|x| format(x)}.join("\n"))
356
362
  end,
357
- *if node.entities and node.entities.length > 0
363
+ *if node.entities.length > 0
358
364
  indent(node.entities.map{|x| format(x)}.join("\n"))
359
365
  end,
360
- *if node.subtype_constraints and node.subtype_constraints.length > 0
366
+ *if node.subtype_constraints.length > 0
361
367
  indent(node.subtype_constraints.map{|x| format(x)}.join("\n"))
362
368
  end,
363
- *if node.functions and node.functions.length > 0
369
+ *if node.functions.length > 0
364
370
  indent(node.functions.map{|x| format(x)}.join("\n"))
365
371
  end,
366
- *if node.procedures and node.procedures.length > 0
372
+ *if node.procedures.length > 0
367
373
  indent(node.procedures.map{|x| format(x)}.join("\n"))
368
374
  end,
369
- *if node.constants and node.constants.length > 0
375
+ *if node.constants.length > 0
370
376
  indent([
371
377
  'CONSTANT',
372
378
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -376,7 +382,7 @@ module Expressir
376
382
  ].join('')
377
383
  ].join("\n"))
378
384
  end,
379
- *if node.variables and node.variables.length > 0
385
+ *if node.variables.length > 0
380
386
  indent([
381
387
  'LOCAL',
382
388
  indent(node.variables.map{|x| format(x)}.join("\n")),
@@ -386,7 +392,7 @@ module Expressir
386
392
  ].join('')
387
393
  ].join("\n"))
388
394
  end,
389
- *if node.statements and node.statements.length > 0
395
+ *if node.statements.length > 0
390
396
  indent(node.statements.map{|x| format(x)}.join("\n"))
391
397
  end,
392
398
  [
@@ -406,19 +412,35 @@ module Expressir
406
412
  'FROM',
407
413
  ' ',
408
414
  format(node.schema),
409
- *if node.items and node.items.length > 0
415
+ *if node.items.length > 0
416
+ item_indent = INDENT_CHAR * '('.length
410
417
  [
411
418
  "\n",
412
- INDENT,
413
- '(',
414
- node.items.map{|x| format(x)}.join(', '),
415
- ')'
419
+ indent([
420
+ '(',
421
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
422
+ ')'
423
+ ].join(''))
416
424
  ].join('')
417
425
  end,
418
426
  ';',
419
427
  ].join('')
420
428
  end
421
429
 
430
+ def format_interface_item(node)
431
+ [
432
+ format(node.ref),
433
+ *if node.id
434
+ [
435
+ ' ',
436
+ 'AS',
437
+ ' ',
438
+ node.id
439
+ ]
440
+ end
441
+ ].join('')
442
+ end
443
+
422
444
  def format_parameter(node)
423
445
  [
424
446
  *if node.var
@@ -441,31 +463,32 @@ module Expressir
441
463
  'PROCEDURE',
442
464
  ' ',
443
465
  node.id,
444
- *if node.parameters and node.parameters.length > 0
466
+ *if node.parameters.length > 0
467
+ parameter_indent = INDENT_CHAR * "PROCEDURE #{node.id}(".length
445
468
  [
446
469
  '(',
447
- node.parameters.map{|x| format(x)}.join('; '),
470
+ node.parameters.map{|x| format(x)}.join(";\n#{parameter_indent}"),
448
471
  ')'
449
472
  ].join('')
450
473
  end,
451
474
  ';'
452
475
  ].join(''),
453
- *if node.types and node.types.length > 0
476
+ *if node.types.length > 0
454
477
  indent(node.types.map{|x| format(x)}.join("\n"))
455
478
  end,
456
- *if node.entities and node.entities.length > 0
479
+ *if node.entities.length > 0
457
480
  indent(node.entities.map{|x| format(x)}.join("\n"))
458
481
  end,
459
- *if node.subtype_constraints and node.subtype_constraints.length > 0
482
+ *if node.subtype_constraints.length > 0
460
483
  indent(node.subtype_constraints.map{|x| format(x)}.join("\n"))
461
484
  end,
462
- *if node.functions and node.functions.length > 0
485
+ *if node.functions.length > 0
463
486
  indent(node.functions.map{|x| format(x)}.join("\n"))
464
487
  end,
465
- *if node.procedures and node.procedures.length > 0
488
+ *if node.procedures.length > 0
466
489
  indent(node.procedures.map{|x| format(x)}.join("\n"))
467
490
  end,
468
- *if node.constants and node.constants.length > 0
491
+ *if node.constants.length > 0
469
492
  indent([
470
493
  'CONSTANT',
471
494
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -475,7 +498,7 @@ module Expressir
475
498
  ].join('')
476
499
  ].join("\n"))
477
500
  end,
478
- *if node.variables and node.variables.length > 0
501
+ *if node.variables.length > 0
479
502
  indent([
480
503
  'LOCAL',
481
504
  indent(node.variables.map{|x| format(x)}.join("\n")),
@@ -485,7 +508,7 @@ module Expressir
485
508
  ].join('')
486
509
  ].join("\n"))
487
510
  end,
488
- *if node.statements and node.statements.length > 0
511
+ *if node.statements.length > 0
489
512
  indent(node.statements.map{|x| format(x)}.join("\n"))
490
513
  end,
491
514
  [
@@ -495,22 +518,8 @@ module Expressir
495
518
  ].join("\n")
496
519
  end
497
520
 
498
- def format_renamed_ref(node)
499
- [
500
- format(node.ref),
501
- ' ',
502
- 'AS',
503
- ' ',
504
- node.id
505
- ].join('')
506
- end
507
-
508
521
  def format_repository(node)
509
- [
510
- *if node.schemas and node.schemas.length > 0
511
- node.schemas.map{|node| format(node)}
512
- end
513
- ].join("\n")
522
+ node.schemas.map{|node| format(node)}.join("\n\n")
514
523
  end
515
524
 
516
525
  def format_rule(node)
@@ -527,22 +536,22 @@ module Expressir
527
536
  ')',
528
537
  ';'
529
538
  ].join(''),
530
- *if node.types and node.types.length > 0
539
+ *if node.types.length > 0
531
540
  indent(node.types.map{|x| format(x)}.join("\n"))
532
541
  end,
533
- *if node.entities and node.entities.length > 0
542
+ *if node.entities.length > 0
534
543
  indent(node.entities.map{|x| format(x)}.join("\n"))
535
544
  end,
536
- *if node.subtype_constraints and node.subtype_constraints.length > 0
545
+ *if node.subtype_constraints.length > 0
537
546
  indent(node.subtype_constraints.map{|x| format(x)}.join("\n"))
538
547
  end,
539
- *if node.functions and node.functions.length > 0
548
+ *if node.functions.length > 0
540
549
  indent(node.functions.map{|x| format(x)}.join("\n"))
541
550
  end,
542
- *if node.procedures and node.procedures.length > 0
551
+ *if node.procedures.length > 0
543
552
  indent(node.procedures.map{|x| format(x)}.join("\n"))
544
553
  end,
545
- *if node.constants and node.constants.length > 0
554
+ *if node.constants.length > 0
546
555
  indent([
547
556
  'CONSTANT',
548
557
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -552,7 +561,7 @@ module Expressir
552
561
  ].join('')
553
562
  ].join("\n"))
554
563
  end,
555
- *if node.variables and node.variables.length > 0
564
+ *if node.variables.length > 0
556
565
  indent([
557
566
  'LOCAL',
558
567
  indent(node.variables.map{|x| format(x)}.join("\n")),
@@ -562,14 +571,14 @@ module Expressir
562
571
  ].join('')
563
572
  ].join("\n"))
564
573
  end,
565
- *if node.statements and node.statements.length > 0
574
+ *if node.statements.length > 0
566
575
  indent(node.statements.map{|x| format(x)}.join("\n"))
567
576
  end,
568
- *if node.where and node.where.length > 0
569
- indent([
577
+ *if node.where.length > 0
578
+ [
570
579
  'WHERE',
571
580
  indent(node.where.map{|x| format(x)}.join("\n"))
572
- ].join("\n"))
581
+ ]
573
582
  end,
574
583
  [
575
584
  'END_RULE',
@@ -578,7 +587,7 @@ module Expressir
578
587
  ].join("\n")
579
588
  end
580
589
 
581
- def format_schema(node)
590
+ def format_schema_head(node)
582
591
  [
583
592
  [
584
593
  'SCHEMA',
@@ -592,10 +601,18 @@ module Expressir
592
601
  end,
593
602
  ';'
594
603
  ].join(''),
595
- *if node.interfaces and node.interfaces.length > 0
596
- node.interfaces.map{|x| format(x)}.join("\n")
597
- end,
598
- *if node.constants and node.constants.length > 0
604
+ *if node.interfaces.length > 0
605
+ [
606
+ '',
607
+ node.interfaces.map{|x| format(x)}.join("\n")
608
+ ]
609
+ end
610
+ ].join("\n")
611
+ end
612
+
613
+ def format_schema(node)
614
+ schema_declarations = [
615
+ *if node.constants.length > 0
599
616
  [
600
617
  'CONSTANT',
601
618
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -605,23 +622,34 @@ module Expressir
605
622
  ].join('')
606
623
  ].join("\n")
607
624
  end,
608
- *if node.types and node.types.length > 0
609
- node.types.map{|x| format(x)}.join("\n")
625
+ *if node.types.length > 0
626
+ node.types.map{|x| format(x)}
610
627
  end,
611
- *if node.entities and node.entities.length > 0
612
- node.entities.map{|x| format(x)}.join("\n")
628
+ *if node.entities.length > 0
629
+ node.entities.map{|x| format(x)}
613
630
  end,
614
- *if node.subtype_constraints and node.subtype_constraints.length > 0
615
- node.subtype_constraints.map{|x| format(x)}.join("\n")
631
+ *if node.subtype_constraints.length > 0
632
+ node.subtype_constraints.map{|x| format(x)}
616
633
  end,
617
- *if node.functions and node.functions.length > 0
618
- node.functions.map{|x| format(x)}.join("\n")
634
+ *if node.functions.length > 0
635
+ node.functions.map{|x| format(x)}
619
636
  end,
620
- *if node.procedures and node.procedures.length > 0
621
- node.procedures.map{|x| format(x)}.join("\n")
637
+ *if node.rules.length > 0
638
+ node.rules.map{|x| format(x)}
622
639
  end,
623
- *if node.rules and node.rules.length > 0
624
- node.rules.map{|x| format(x)}.join("\n")
640
+ *if node.procedures and node.procedures.length > 0
641
+ node.procedures.map{|x| format(x)}
642
+ end
643
+ ]
644
+
645
+ [
646
+ format_schema_head(node),
647
+ *if schema_declarations.length > 0
648
+ [
649
+ '',
650
+ schema_declarations.join("\n\n"),
651
+ ''
652
+ ]
625
653
  end,
626
654
  [
627
655
  'END_SCHEMA',
@@ -651,7 +679,7 @@ module Expressir
651
679
  ';'
652
680
  ].join(''))
653
681
  end,
654
- *if node.total_over and node.total_over.length > 0
682
+ *if node.total_over.length > 0
655
683
  indent([
656
684
  'TOTAL_OVER',
657
685
  '(',
@@ -685,11 +713,11 @@ module Expressir
685
713
  format(node.type),
686
714
  ';',
687
715
  ].join(''),
688
- *if node.where and node.where.length > 0
689
- indent([
716
+ *if node.where.length > 0
717
+ [
690
718
  'WHERE',
691
719
  indent(node.where.map{|x| format(x)}.join("\n"))
692
- ].join("\n"))
720
+ ]
693
721
  end,
694
722
  [
695
723
  'END_TYPE',
@@ -703,7 +731,6 @@ module Expressir
703
731
  *if node.id
704
732
  [
705
733
  node.id,
706
- ' ',
707
734
  ':',
708
735
  ' '
709
736
  ].join('')
@@ -737,7 +764,6 @@ module Expressir
737
764
  *if node.id
738
765
  [
739
766
  node.id,
740
- ' ',
741
767
  ':',
742
768
  ' '
743
769
  ].join('')
@@ -972,7 +998,7 @@ module Expressir
972
998
  format(node.expression),
973
999
  ';'
974
1000
  ].join(''),
975
- *if node.statements and node.statements.length > 0
1001
+ *if node.statements.length > 0
976
1002
  indent(node.statements.map{|x| format(x)}.join("\n"))
977
1003
  end,
978
1004
  *format_remarks(node),
@@ -997,7 +1023,7 @@ module Expressir
997
1023
  def format_statements_call(node)
998
1024
  [
999
1025
  format(node.ref),
1000
- *if node.parameters and node.parameters.length > 0
1026
+ *if node.parameters.length > 0
1001
1027
  [
1002
1028
  '(',
1003
1029
  node.parameters.map{|x| format(x)}.join(', '),
@@ -1017,7 +1043,7 @@ module Expressir
1017
1043
  ' ',
1018
1044
  'OF'
1019
1045
  ].join(''),
1020
- *if node.actions and node.actions.length > 0
1046
+ *if node.actions.length > 0
1021
1047
  node.actions.map{|x| format(x)}
1022
1048
  end,
1023
1049
  *if node.otherwise_statement
@@ -1051,7 +1077,7 @@ module Expressir
1051
1077
  def format_statements_compound(node)
1052
1078
  [
1053
1079
  'BEGIN',
1054
- *if node.statements and node.statements.length > 0
1080
+ *if node.statements.length > 0
1055
1081
  indent(node.statements.map{|x| format(x)}.join("\n"))
1056
1082
  end,
1057
1083
  [
@@ -1077,10 +1103,10 @@ module Expressir
1077
1103
  ' ',
1078
1104
  'THEN'
1079
1105
  ].join(''),
1080
- *if node.statements and node.statements.length > 0
1106
+ *if node.statements.length > 0
1081
1107
  indent(node.statements.map{|x| format(x)}.join("\n"))
1082
1108
  end,
1083
- *if node.else_statements and node.else_statements.length > 0
1109
+ *if node.else_statements.length > 0
1084
1110
  [
1085
1111
  'ELSE',
1086
1112
  indent(node.else_statements.map{|x| format(x)}.join("\n")),
@@ -1141,7 +1167,7 @@ module Expressir
1141
1167
  end,
1142
1168
  ';'
1143
1169
  ].join(''),
1144
- *if node.statements and node.statements.length > 0
1170
+ *if node.statements.length > 0
1145
1171
  indent(node.statements.map{|x| format(x)}.join("\n"))
1146
1172
  end,
1147
1173
  *format_remarks(node),
@@ -1263,14 +1289,17 @@ module Expressir
1263
1289
  ].join('')
1264
1290
  end,
1265
1291
  'ENUMERATION',
1266
- *if node.items and node.items.length > 0
1292
+ *if node.items.length > 0
1293
+ item_indent = INDENT_CHAR * '('.length
1267
1294
  [
1268
1295
  ' ',
1269
1296
  'OF',
1270
- ' ',
1271
- '(',
1272
- node.items.map{|x| format(x)}.join(', '),
1273
- ')'
1297
+ "\n",
1298
+ indent([
1299
+ '(',
1300
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1301
+ ')'
1302
+ ].join(''))
1274
1303
  ].join('')
1275
1304
  end,
1276
1305
  *if node.extension_type
@@ -1281,25 +1310,44 @@ module Expressir
1281
1310
  format(node.extension_type)
1282
1311
  ].join('')
1283
1312
  end,
1284
- *if node.extension_items and node.extension_items.length > 0
1313
+ *if node.extension_items.length > 0
1314
+ item_indent = INDENT_CHAR * '('.length
1285
1315
  [
1286
1316
  ' ',
1287
1317
  'WITH',
1288
- ' ',
1289
- '(',
1290
- node.extension_items.map{|x| format(x)}.join(', '),
1291
- ')'
1318
+ "\n",
1319
+ indent([
1320
+ '(',
1321
+ node.extension_items.map{|x| format(x)}.join(",\n#{item_indent}"),
1322
+ ')'
1323
+ ].join(''))
1292
1324
  ].join('')
1293
1325
  end
1294
1326
  ].join('')
1295
1327
  end
1296
1328
 
1297
1329
  def format_types_generic_entity(node)
1298
- 'GENERIC_ENTITY'
1330
+ [
1331
+ 'GENERIC_ENTITY',
1332
+ *if node.id
1333
+ [
1334
+ ':',
1335
+ node.id
1336
+ ]
1337
+ end
1338
+ ].join('')
1299
1339
  end
1300
1340
 
1301
1341
  def format_types_generic(node)
1302
- 'GENERIC'
1342
+ [
1343
+ 'GENERIC',
1344
+ *if node.id
1345
+ [
1346
+ ':',
1347
+ node.id
1348
+ ]
1349
+ end
1350
+ ].join('')
1303
1351
  end
1304
1352
 
1305
1353
  def format_types_integer(node)
@@ -1369,12 +1417,15 @@ module Expressir
1369
1417
  ].join('')
1370
1418
  end,
1371
1419
  'SELECT',
1372
- *if node.items and node.items.length > 0
1420
+ *if node.items.length > 0
1421
+ item_indent = INDENT_CHAR * '('.length
1373
1422
  [
1374
- ' ',
1375
- '(',
1376
- node.items.map{|x| format(x)}.join(', '),
1377
- ')'
1423
+ "\n",
1424
+ indent([
1425
+ '(',
1426
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1427
+ ')'
1428
+ ].join(''))
1378
1429
  ].join('')
1379
1430
  end,
1380
1431
  *if node.extension_type
@@ -1385,14 +1436,17 @@ module Expressir
1385
1436
  format(node.extension_type)
1386
1437
  ].join('')
1387
1438
  end,
1388
- *if node.extension_items and node.extension_items.length > 0
1439
+ *if node.extension_items.length > 0
1440
+ item_indent = INDENT_CHAR * '('.length
1389
1441
  [
1390
1442
  ' ',
1391
1443
  'WITH',
1392
- ' ',
1393
- '(',
1394
- node.extension_items.map{|x| format(x)}.join(', '),
1395
- ')'
1444
+ "\n",
1445
+ indent([
1446
+ '(',
1447
+ node.extension_items.map{|x| format(x)}.join(",\n#{item_indent}"),
1448
+ ')'
1449
+ ].join(''))
1396
1450
  ].join('')
1397
1451
  end
1398
1452
  ].join('')