expressir 0.2.16-x86-linux → 0.2.17-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +51 -13
  3. data/lib/expressir/express_exp/formatter.rb +185 -135
  4. data/lib/expressir/express_exp/parser.rb +29 -29
  5. data/lib/expressir/express_exp/schema_head_formatter.rb +1 -4
  6. data/lib/expressir/express_exp/visitor.rb +11 -6
  7. data/lib/expressir/model/entity.rb +6 -6
  8. data/lib/expressir/model/expressions/query_expression.rb +3 -3
  9. data/lib/expressir/model/function.rb +15 -11
  10. data/lib/expressir/model/informal_proposition.rb +4 -1
  11. data/lib/expressir/model/interfaced_item.rb +4 -1
  12. data/lib/expressir/model/model_element.rb +20 -7
  13. data/lib/expressir/model/procedure.rb +15 -11
  14. data/lib/expressir/model/repository.rb +3 -3
  15. data/lib/expressir/model/rule.rb +16 -12
  16. data/lib/expressir/model/schema.rb +52 -45
  17. data/lib/expressir/model/statements/alias.rb +3 -3
  18. data/lib/expressir/model/statements/repeat.rb +3 -3
  19. data/lib/expressir/model/subtype_constraint.rb +1 -6
  20. data/lib/expressir/model/type.rb +9 -5
  21. data/lib/expressir/version.rb +1 -1
  22. data/original/examples/syntax/{hyperlink.exp → multiple.exp} +8 -8
  23. data/original/examples/syntax/multiple.yaml +180 -0
  24. data/original/examples/syntax/multiple_formatted.exp +71 -0
  25. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  26. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  27. data/original/examples/syntax/remark.exp +41 -41
  28. data/original/examples/syntax/remark.yaml +445 -0
  29. data/original/examples/syntax/remark_formatted.exp +62 -50
  30. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  31. data/original/examples/syntax/single.yaml +8 -0
  32. data/original/examples/syntax/single_formatted.exp +6 -0
  33. data/original/examples/syntax/single_formatted.yaml +18 -0
  34. data/original/examples/syntax/syntax.exp +29 -19
  35. data/original/examples/syntax/syntax.yaml +3438 -0
  36. data/original/examples/syntax/syntax_formatted.exp +271 -131
  37. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  38. data/spec/expressir/express_exp/formatter_spec.rb +110 -0
  39. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  40. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +93 -10
  41. metadata +17 -16
  42. data/original/examples/syntax/hyperlink_formatted.exp +0 -51
  43. data/original/examples/syntax/source.exp +0 -16
  44. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  45. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  46. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -28
  47. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
  48. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  49. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  50. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3086
  51. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -40
  52. 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: 5605346daba217ea78c0d0a4fa95529e10e83142d79c906247e805a2185b85b3
4
- data.tar.gz: 1a81312bdaf232380aee7cde9657e7311637877507d855aed9811324735e2c6d
3
+ metadata.gz: 85881d47f6f0ae98d38e81923c841e53e01f7c0c1e5acc002d22dd2393d5b798
4
+ data.tar.gz: 2a0a8c25dd8b7e468a0ff9d40e16c52a730c19075c4c15719c7edcfc95c3413f
5
5
  SHA512:
6
- metadata.gz: 68be748e767b745c6234ed1ec3ea7066463bfeb927370714ae72b86c09bfbe964e4bf9fead7c312c9acdbf6fecedc13b6735d079de812aa97ccb3b92a74bbf1b
7
- data.tar.gz: d498f9c24e397b1c0a0e4027f0788cc9173c58a2898e6e23fd4ee14c8f3e92e51f894b1adf30f23970486d4d7360d9854c76e82a25e2c7942e6cb479ca895705
6
+ metadata.gz: 886134f22089082f34cccba7ee85eac35a0969a8aa28416dceb75165e6fcc8be21bed1d7eefa25a7fc4aa844d16ace21babbfe65c0ded9531ea198d9b70d29fc
7
+ data.tar.gz: 434341f651c7680a1583fef1e1373e54ba298117077f77677892ee14541c18cf1eef9b0e66e42e959f9f9039496db1bc8426cdc164c42bf6834f94edbc70d181
data/exe/format CHANGED
@@ -1,27 +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 = [
9
+ exp_files = [
7
10
  # basic test
8
11
  # '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
9
12
  # '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
10
13
  # '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
11
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
12
18
  # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
13
- # '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp'
14
- # renamed reference test
15
- '../iso-10303-stepmod/ballots/ballots/ap210_wg12/express/resources/mathematical_functions_schema.exp',
16
- '../iso-10303-stepmod/data/resources/iso13584_expressions_schema/iso13584_expressions_schema.exp',
17
- # all valid iso-10303-stepmod files (takes 10 min)
18
- # *`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}
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}
19
51
  ]
20
52
 
21
- repo = Expressir::ExpressExp::Parser.from_files(input_files)
22
- # schema = repo.schemas.find{|x| x.id == 'action_schema'}
23
- # schema = repo.schemas.find{|x| x.id == 'product_property_definition_schema'}
24
- schema = repo.schemas.find{|x| x.id == 'mathematical_functions_schema'}
25
- 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}"
26
64
 
27
- puts result
65
+ # puts YAML.dump(result)
@@ -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,13 +412,15 @@ 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
  ';',
@@ -455,31 +463,32 @@ module Expressir
455
463
  'PROCEDURE',
456
464
  ' ',
457
465
  node.id,
458
- *if node.parameters and node.parameters.length > 0
466
+ *if node.parameters.length > 0
467
+ parameter_indent = INDENT_CHAR * "PROCEDURE #{node.id}(".length
459
468
  [
460
469
  '(',
461
- node.parameters.map{|x| format(x)}.join('; '),
470
+ node.parameters.map{|x| format(x)}.join(";\n#{parameter_indent}"),
462
471
  ')'
463
472
  ].join('')
464
473
  end,
465
474
  ';'
466
475
  ].join(''),
467
- *if node.types and node.types.length > 0
476
+ *if node.types.length > 0
468
477
  indent(node.types.map{|x| format(x)}.join("\n"))
469
478
  end,
470
- *if node.entities and node.entities.length > 0
479
+ *if node.entities.length > 0
471
480
  indent(node.entities.map{|x| format(x)}.join("\n"))
472
481
  end,
473
- *if node.subtype_constraints and node.subtype_constraints.length > 0
482
+ *if node.subtype_constraints.length > 0
474
483
  indent(node.subtype_constraints.map{|x| format(x)}.join("\n"))
475
484
  end,
476
- *if node.functions and node.functions.length > 0
485
+ *if node.functions.length > 0
477
486
  indent(node.functions.map{|x| format(x)}.join("\n"))
478
487
  end,
479
- *if node.procedures and node.procedures.length > 0
488
+ *if node.procedures.length > 0
480
489
  indent(node.procedures.map{|x| format(x)}.join("\n"))
481
490
  end,
482
- *if node.constants and node.constants.length > 0
491
+ *if node.constants.length > 0
483
492
  indent([
484
493
  'CONSTANT',
485
494
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -489,7 +498,7 @@ module Expressir
489
498
  ].join('')
490
499
  ].join("\n"))
491
500
  end,
492
- *if node.variables and node.variables.length > 0
501
+ *if node.variables.length > 0
493
502
  indent([
494
503
  'LOCAL',
495
504
  indent(node.variables.map{|x| format(x)}.join("\n")),
@@ -499,7 +508,7 @@ module Expressir
499
508
  ].join('')
500
509
  ].join("\n"))
501
510
  end,
502
- *if node.statements and node.statements.length > 0
511
+ *if node.statements.length > 0
503
512
  indent(node.statements.map{|x| format(x)}.join("\n"))
504
513
  end,
505
514
  [
@@ -510,11 +519,7 @@ module Expressir
510
519
  end
511
520
 
512
521
  def format_repository(node)
513
- [
514
- *if node.schemas and node.schemas.length > 0
515
- node.schemas.map{|node| format(node)}
516
- end
517
- ].join("\n")
522
+ node.schemas.map{|node| format(node)}.join("\n\n")
518
523
  end
519
524
 
520
525
  def format_rule(node)
@@ -531,22 +536,22 @@ module Expressir
531
536
  ')',
532
537
  ';'
533
538
  ].join(''),
534
- *if node.types and node.types.length > 0
539
+ *if node.types.length > 0
535
540
  indent(node.types.map{|x| format(x)}.join("\n"))
536
541
  end,
537
- *if node.entities and node.entities.length > 0
542
+ *if node.entities.length > 0
538
543
  indent(node.entities.map{|x| format(x)}.join("\n"))
539
544
  end,
540
- *if node.subtype_constraints and node.subtype_constraints.length > 0
545
+ *if node.subtype_constraints.length > 0
541
546
  indent(node.subtype_constraints.map{|x| format(x)}.join("\n"))
542
547
  end,
543
- *if node.functions and node.functions.length > 0
548
+ *if node.functions.length > 0
544
549
  indent(node.functions.map{|x| format(x)}.join("\n"))
545
550
  end,
546
- *if node.procedures and node.procedures.length > 0
551
+ *if node.procedures.length > 0
547
552
  indent(node.procedures.map{|x| format(x)}.join("\n"))
548
553
  end,
549
- *if node.constants and node.constants.length > 0
554
+ *if node.constants.length > 0
550
555
  indent([
551
556
  'CONSTANT',
552
557
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -556,7 +561,7 @@ module Expressir
556
561
  ].join('')
557
562
  ].join("\n"))
558
563
  end,
559
- *if node.variables and node.variables.length > 0
564
+ *if node.variables.length > 0
560
565
  indent([
561
566
  'LOCAL',
562
567
  indent(node.variables.map{|x| format(x)}.join("\n")),
@@ -566,14 +571,14 @@ module Expressir
566
571
  ].join('')
567
572
  ].join("\n"))
568
573
  end,
569
- *if node.statements and node.statements.length > 0
574
+ *if node.statements.length > 0
570
575
  indent(node.statements.map{|x| format(x)}.join("\n"))
571
576
  end,
572
- *if node.where and node.where.length > 0
573
- indent([
577
+ *if node.where.length > 0
578
+ [
574
579
  'WHERE',
575
580
  indent(node.where.map{|x| format(x)}.join("\n"))
576
- ].join("\n"))
581
+ ]
577
582
  end,
578
583
  [
579
584
  'END_RULE',
@@ -582,7 +587,7 @@ module Expressir
582
587
  ].join("\n")
583
588
  end
584
589
 
585
- def format_schema(node)
590
+ def format_schema_head(node)
586
591
  [
587
592
  [
588
593
  'SCHEMA',
@@ -596,10 +601,18 @@ module Expressir
596
601
  end,
597
602
  ';'
598
603
  ].join(''),
599
- *if node.interfaces and node.interfaces.length > 0
600
- node.interfaces.map{|x| format(x)}.join("\n")
601
- end,
602
- *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
603
616
  [
604
617
  'CONSTANT',
605
618
  indent(node.constants.map{|x| format(x)}.join("\n")),
@@ -609,23 +622,34 @@ module Expressir
609
622
  ].join('')
610
623
  ].join("\n")
611
624
  end,
612
- *if node.types and node.types.length > 0
613
- node.types.map{|x| format(x)}.join("\n")
625
+ *if node.types.length > 0
626
+ node.types.map{|x| format(x)}
614
627
  end,
615
- *if node.entities and node.entities.length > 0
616
- node.entities.map{|x| format(x)}.join("\n")
628
+ *if node.entities.length > 0
629
+ node.entities.map{|x| format(x)}
617
630
  end,
618
- *if node.subtype_constraints and node.subtype_constraints.length > 0
619
- node.subtype_constraints.map{|x| format(x)}.join("\n")
631
+ *if node.subtype_constraints.length > 0
632
+ node.subtype_constraints.map{|x| format(x)}
620
633
  end,
621
- *if node.functions and node.functions.length > 0
622
- node.functions.map{|x| format(x)}.join("\n")
634
+ *if node.functions.length > 0
635
+ node.functions.map{|x| format(x)}
623
636
  end,
624
- *if node.procedures and node.procedures.length > 0
625
- node.procedures.map{|x| format(x)}.join("\n")
637
+ *if node.rules.length > 0
638
+ node.rules.map{|x| format(x)}
626
639
  end,
627
- *if node.rules and node.rules.length > 0
628
- 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
+ ]
629
653
  end,
630
654
  [
631
655
  'END_SCHEMA',
@@ -655,7 +679,7 @@ module Expressir
655
679
  ';'
656
680
  ].join(''))
657
681
  end,
658
- *if node.total_over and node.total_over.length > 0
682
+ *if node.total_over.length > 0
659
683
  indent([
660
684
  'TOTAL_OVER',
661
685
  '(',
@@ -689,11 +713,11 @@ module Expressir
689
713
  format(node.type),
690
714
  ';',
691
715
  ].join(''),
692
- *if node.where and node.where.length > 0
693
- indent([
716
+ *if node.where.length > 0
717
+ [
694
718
  'WHERE',
695
719
  indent(node.where.map{|x| format(x)}.join("\n"))
696
- ].join("\n"))
720
+ ]
697
721
  end,
698
722
  [
699
723
  'END_TYPE',
@@ -707,7 +731,6 @@ module Expressir
707
731
  *if node.id
708
732
  [
709
733
  node.id,
710
- ' ',
711
734
  ':',
712
735
  ' '
713
736
  ].join('')
@@ -741,7 +764,6 @@ module Expressir
741
764
  *if node.id
742
765
  [
743
766
  node.id,
744
- ' ',
745
767
  ':',
746
768
  ' '
747
769
  ].join('')
@@ -976,7 +998,7 @@ module Expressir
976
998
  format(node.expression),
977
999
  ';'
978
1000
  ].join(''),
979
- *if node.statements and node.statements.length > 0
1001
+ *if node.statements.length > 0
980
1002
  indent(node.statements.map{|x| format(x)}.join("\n"))
981
1003
  end,
982
1004
  *format_remarks(node),
@@ -1001,7 +1023,7 @@ module Expressir
1001
1023
  def format_statements_call(node)
1002
1024
  [
1003
1025
  format(node.ref),
1004
- *if node.parameters and node.parameters.length > 0
1026
+ *if node.parameters.length > 0
1005
1027
  [
1006
1028
  '(',
1007
1029
  node.parameters.map{|x| format(x)}.join(', '),
@@ -1021,7 +1043,7 @@ module Expressir
1021
1043
  ' ',
1022
1044
  'OF'
1023
1045
  ].join(''),
1024
- *if node.actions and node.actions.length > 0
1046
+ *if node.actions.length > 0
1025
1047
  node.actions.map{|x| format(x)}
1026
1048
  end,
1027
1049
  *if node.otherwise_statement
@@ -1055,7 +1077,7 @@ module Expressir
1055
1077
  def format_statements_compound(node)
1056
1078
  [
1057
1079
  'BEGIN',
1058
- *if node.statements and node.statements.length > 0
1080
+ *if node.statements.length > 0
1059
1081
  indent(node.statements.map{|x| format(x)}.join("\n"))
1060
1082
  end,
1061
1083
  [
@@ -1081,10 +1103,10 @@ module Expressir
1081
1103
  ' ',
1082
1104
  'THEN'
1083
1105
  ].join(''),
1084
- *if node.statements and node.statements.length > 0
1106
+ *if node.statements.length > 0
1085
1107
  indent(node.statements.map{|x| format(x)}.join("\n"))
1086
1108
  end,
1087
- *if node.else_statements and node.else_statements.length > 0
1109
+ *if node.else_statements.length > 0
1088
1110
  [
1089
1111
  'ELSE',
1090
1112
  indent(node.else_statements.map{|x| format(x)}.join("\n")),
@@ -1145,7 +1167,7 @@ module Expressir
1145
1167
  end,
1146
1168
  ';'
1147
1169
  ].join(''),
1148
- *if node.statements and node.statements.length > 0
1170
+ *if node.statements.length > 0
1149
1171
  indent(node.statements.map{|x| format(x)}.join("\n"))
1150
1172
  end,
1151
1173
  *format_remarks(node),
@@ -1267,14 +1289,17 @@ module Expressir
1267
1289
  ].join('')
1268
1290
  end,
1269
1291
  'ENUMERATION',
1270
- *if node.items and node.items.length > 0
1292
+ *if node.items.length > 0
1293
+ item_indent = INDENT_CHAR * '('.length
1271
1294
  [
1272
1295
  ' ',
1273
1296
  'OF',
1274
- ' ',
1275
- '(',
1276
- node.items.map{|x| format(x)}.join(', '),
1277
- ')'
1297
+ "\n",
1298
+ indent([
1299
+ '(',
1300
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1301
+ ')'
1302
+ ].join(''))
1278
1303
  ].join('')
1279
1304
  end,
1280
1305
  *if node.extension_type
@@ -1285,25 +1310,44 @@ module Expressir
1285
1310
  format(node.extension_type)
1286
1311
  ].join('')
1287
1312
  end,
1288
- *if node.extension_items and node.extension_items.length > 0
1313
+ *if node.extension_items.length > 0
1314
+ item_indent = INDENT_CHAR * '('.length
1289
1315
  [
1290
1316
  ' ',
1291
1317
  'WITH',
1292
- ' ',
1293
- '(',
1294
- node.extension_items.map{|x| format(x)}.join(', '),
1295
- ')'
1318
+ "\n",
1319
+ indent([
1320
+ '(',
1321
+ node.extension_items.map{|x| format(x)}.join(",\n#{item_indent}"),
1322
+ ')'
1323
+ ].join(''))
1296
1324
  ].join('')
1297
1325
  end
1298
1326
  ].join('')
1299
1327
  end
1300
1328
 
1301
1329
  def format_types_generic_entity(node)
1302
- 'GENERIC_ENTITY'
1330
+ [
1331
+ 'GENERIC_ENTITY',
1332
+ *if node.id
1333
+ [
1334
+ ':',
1335
+ node.id
1336
+ ]
1337
+ end
1338
+ ].join('')
1303
1339
  end
1304
1340
 
1305
1341
  def format_types_generic(node)
1306
- 'GENERIC'
1342
+ [
1343
+ 'GENERIC',
1344
+ *if node.id
1345
+ [
1346
+ ':',
1347
+ node.id
1348
+ ]
1349
+ end
1350
+ ].join('')
1307
1351
  end
1308
1352
 
1309
1353
  def format_types_integer(node)
@@ -1373,12 +1417,15 @@ module Expressir
1373
1417
  ].join('')
1374
1418
  end,
1375
1419
  'SELECT',
1376
- *if node.items and node.items.length > 0
1420
+ *if node.items.length > 0
1421
+ item_indent = INDENT_CHAR * '('.length
1377
1422
  [
1378
- ' ',
1379
- '(',
1380
- node.items.map{|x| format(x)}.join(', '),
1381
- ')'
1423
+ "\n",
1424
+ indent([
1425
+ '(',
1426
+ node.items.map{|x| format(x)}.join(",\n#{item_indent}"),
1427
+ ')'
1428
+ ].join(''))
1382
1429
  ].join('')
1383
1430
  end,
1384
1431
  *if node.extension_type
@@ -1389,14 +1436,17 @@ module Expressir
1389
1436
  format(node.extension_type)
1390
1437
  ].join('')
1391
1438
  end,
1392
- *if node.extension_items and node.extension_items.length > 0
1439
+ *if node.extension_items.length > 0
1440
+ item_indent = INDENT_CHAR * '('.length
1393
1441
  [
1394
1442
  ' ',
1395
1443
  'WITH',
1396
- ' ',
1397
- '(',
1398
- node.extension_items.map{|x| format(x)}.join(', '),
1399
- ')'
1444
+ "\n",
1445
+ indent([
1446
+ '(',
1447
+ node.extension_items.map{|x| format(x)}.join(",\n#{item_indent}"),
1448
+ ')'
1449
+ ].join(''))
1400
1450
  ].join('')
1401
1451
  end
1402
1452
  ].join('')