expressir 0.2.12-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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +57 -8
  3. data/lib/expressir/express_exp/formatter.rb +201 -147
  4. data/lib/expressir/express_exp/hyperlink_formatter.rb +6 -4
  5. data/lib/expressir/express_exp/parser.rb +31 -25
  6. data/lib/expressir/express_exp/schema_head_formatter.rb +2 -7
  7. data/lib/expressir/express_exp/visitor.rb +27 -54
  8. data/lib/expressir/model.rb +2 -1
  9. data/lib/expressir/model/entity.rb +6 -6
  10. data/lib/expressir/model/expressions/query_expression.rb +3 -3
  11. data/lib/expressir/model/function.rb +15 -11
  12. data/lib/expressir/model/informal_proposition.rb +4 -1
  13. data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +2 -2
  14. data/lib/expressir/model/interfaced_item.rb +26 -0
  15. data/lib/expressir/model/model_element.rb +20 -7
  16. data/lib/expressir/model/procedure.rb +15 -11
  17. data/lib/expressir/model/repository.rb +3 -3
  18. data/lib/expressir/model/rule.rb +16 -12
  19. data/lib/expressir/model/schema.rb +60 -17
  20. data/lib/expressir/model/statements/alias.rb +3 -3
  21. data/lib/expressir/model/statements/repeat.rb +3 -3
  22. data/lib/expressir/model/subtype_constraint.rb +1 -6
  23. data/lib/expressir/model/type.rb +9 -5
  24. data/lib/expressir/version.rb +1 -1
  25. data/original/examples/syntax/multiple.exp +23 -0
  26. data/original/examples/syntax/multiple.yaml +180 -0
  27. data/original/examples/syntax/multiple_formatted.exp +71 -0
  28. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  29. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  30. data/original/examples/syntax/remark.exp +41 -41
  31. data/original/examples/syntax/remark.yaml +445 -0
  32. data/original/examples/syntax/remark_formatted.exp +62 -50
  33. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  34. data/original/examples/syntax/single.yaml +8 -0
  35. data/original/examples/syntax/single_formatted.exp +6 -0
  36. data/original/examples/syntax/single_formatted.yaml +18 -0
  37. data/original/examples/syntax/syntax.exp +29 -19
  38. data/original/examples/syntax/syntax.yaml +3438 -0
  39. data/original/examples/syntax/syntax_formatted.exp +271 -131
  40. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  41. data/spec/expressir/express_exp/formatter_spec.rb +110 -0
  42. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  43. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +93 -10
  44. metadata +19 -18
  45. data/original/examples/syntax/hyperlink.exp +0 -8
  46. data/original/examples/syntax/hyperlink_formatted.exp +0 -19
  47. data/original/examples/syntax/source.exp +0 -16
  48. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  49. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  50. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -24
  51. data/spec/expressir/express_exp/parser/head_source_spec.rb +0 -38
  52. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -32
  53. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  54. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  55. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3080
  56. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -36
  57. 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: 432faff204670f985cc301c087b0c9da0c689b08f0a848a95fc3e3f95fc6b7b4
4
- data.tar.gz: 59403e704f248d53d94663a8ece3d6a7650f895e8edd416983701e0b91f42f4b
3
+ metadata.gz: 85881d47f6f0ae98d38e81923c841e53e01f7c0c1e5acc002d22dd2393d5b798
4
+ data.tar.gz: 2a0a8c25dd8b7e468a0ff9d40e16c52a730c19075c4c15719c7edcfc95c3413f
5
5
  SHA512:
6
- metadata.gz: f3291946e2a534e087d8f288bdcba3e43854280a2d4ffda087cfbbad25ca1f4517dc14dda9a6f2ae57b9804aeff86b25a158bc686c4d2f8777648fbd1913ccfa
7
- data.tar.gz: 7a2c7cc654c8ac2518f659006ffd006830f7f58c93eaf908af7714d58f7a25ba63964f2e13ea09cf036fc527ab4d46133dee7bdc3dec20248c1767bd33e2504f
6
+ metadata.gz: 886134f22089082f34cccba7ee85eac35a0969a8aa28416dceb75165e6fcc8be21bed1d7eefa25a7fc4aa844d16ace21babbfe65c0ded9531ea198d9b70d29fc
7
+ data.tar.gz: 434341f651c7680a1583fef1e1373e54ba298117077f77677892ee14541c18cf1eef9b0e66e42e959f9f9039496db1bc8426cdc164c42bf6834f94edbc70d181
data/exe/format CHANGED
@@ -1,16 +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'
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
18
+ # '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_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}
10
51
  ]
11
52
 
12
- repo = Expressir::ExpressExp::Parser.from_files(input_files)
13
- schema = repo.schemas.find{|x| x.id == 'action_schema'}
14
- 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}"
15
64
 
16
- 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('')