expressir 0.2.11-arm64-darwin → 0.2.12-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +16 -0
  3. data/expressir.gemspec +1 -0
  4. data/lib/expressir/express_exp/2.4/express_parser.bundle +0 -0
  5. data/lib/expressir/express_exp/2.5/express_parser.bundle +0 -0
  6. data/lib/expressir/express_exp/2.6/express_parser.bundle +0 -0
  7. data/lib/expressir/express_exp/2.7/express_parser.bundle +0 -0
  8. data/lib/expressir/express_exp/3.0/express_parser.bundle +0 -0
  9. data/lib/expressir/express_exp/formatter.rb +75 -89
  10. data/lib/expressir/express_exp/hyperlink_formatter.rb +25 -0
  11. data/lib/expressir/express_exp/schema_head_formatter.rb +14 -0
  12. data/lib/expressir/express_exp/visitor.rb +58 -58
  13. data/lib/expressir/model.rb +0 -1
  14. data/lib/expressir/model/attribute.rb +2 -0
  15. data/lib/expressir/model/constant.rb +2 -0
  16. data/lib/expressir/model/entity.rb +3 -2
  17. data/lib/expressir/model/enumeration_item.rb +2 -0
  18. data/lib/expressir/model/expressions/aggregate_initializer.rb +2 -0
  19. data/lib/expressir/model/expressions/aggregate_item.rb +2 -0
  20. data/lib/expressir/model/expressions/attribute_reference.rb +2 -0
  21. data/lib/expressir/model/expressions/binary_expression.rb +2 -0
  22. data/lib/expressir/model/expressions/call.rb +2 -0
  23. data/lib/expressir/model/expressions/entity_constructor.rb +2 -0
  24. data/lib/expressir/model/expressions/group_reference.rb +2 -0
  25. data/lib/expressir/model/expressions/index_reference.rb +2 -0
  26. data/lib/expressir/model/expressions/interval.rb +2 -0
  27. data/lib/expressir/model/expressions/query_expression.rb +2 -1
  28. data/lib/expressir/model/expressions/simple_reference.rb +2 -0
  29. data/lib/expressir/model/expressions/unary_expression.rb +2 -0
  30. data/lib/expressir/model/function.rb +3 -8
  31. data/lib/expressir/model/identifier.rb +0 -1
  32. data/lib/expressir/model/informal_proposition.rb +2 -0
  33. data/lib/expressir/model/interface.rb +2 -0
  34. data/lib/expressir/model/literals/binary.rb +2 -0
  35. data/lib/expressir/model/literals/integer.rb +2 -0
  36. data/lib/expressir/model/literals/logical.rb +2 -0
  37. data/lib/expressir/model/literals/real.rb +2 -0
  38. data/lib/expressir/model/literals/string.rb +2 -0
  39. data/lib/expressir/model/model_element.rb +71 -4
  40. data/lib/expressir/model/parameter.rb +2 -0
  41. data/lib/expressir/model/procedure.rb +3 -8
  42. data/lib/expressir/model/renamed_ref.rb +2 -0
  43. data/lib/expressir/model/repository.rb +2 -2
  44. data/lib/expressir/model/rule.rb +4 -9
  45. data/lib/expressir/model/schema.rb +5 -8
  46. data/lib/expressir/model/statements/alias.rb +2 -1
  47. data/lib/expressir/model/statements/assignment.rb +2 -0
  48. data/lib/expressir/model/statements/call.rb +2 -0
  49. data/lib/expressir/model/statements/case.rb +2 -0
  50. data/lib/expressir/model/statements/case_action.rb +2 -0
  51. data/lib/expressir/model/statements/compound.rb +2 -0
  52. data/lib/expressir/model/statements/if.rb +2 -0
  53. data/lib/expressir/model/statements/repeat.rb +2 -1
  54. data/lib/expressir/model/statements/return.rb +2 -0
  55. data/lib/expressir/model/subtype_constraint.rb +2 -1
  56. data/lib/expressir/model/type.rb +3 -6
  57. data/lib/expressir/model/types/aggregate.rb +2 -0
  58. data/lib/expressir/model/types/array.rb +2 -0
  59. data/lib/expressir/model/types/bag.rb +2 -0
  60. data/lib/expressir/model/types/binary.rb +2 -0
  61. data/lib/expressir/model/types/enumeration.rb +2 -0
  62. data/lib/expressir/model/types/generic.rb +2 -0
  63. data/lib/expressir/model/types/generic_entity.rb +2 -0
  64. data/lib/expressir/model/types/list.rb +2 -0
  65. data/lib/expressir/model/types/real.rb +2 -0
  66. data/lib/expressir/model/types/select.rb +2 -0
  67. data/lib/expressir/model/types/set.rb +2 -0
  68. data/lib/expressir/model/types/string.rb +2 -0
  69. data/lib/expressir/model/unique.rb +2 -0
  70. data/lib/expressir/model/variable.rb +2 -0
  71. data/lib/expressir/model/where.rb +2 -0
  72. data/lib/expressir/version.rb +1 -1
  73. data/original/examples/syntax/hyperlink.exp +8 -0
  74. data/original/examples/syntax/hyperlink_formatted.exp +19 -0
  75. data/original/examples/syntax/syntax.exp +18 -18
  76. data/original/examples/syntax/syntax_formatted.exp +32 -24
  77. data/spec/expressir/express_exp/{format_remark_spec.rb → formatter/remark_spec.rb} +2 -2
  78. data/spec/expressir/express_exp/{format_syntax_spec.rb → formatter/syntax_spec.rb} +2 -2
  79. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +24 -0
  80. data/spec/expressir/express_exp/{head_source_spec.rb → parser/head_source_spec.rb} +1 -1
  81. data/spec/expressir/express_exp/{parse_multiple_spec.rb → parser/multiple_spec.rb} +1 -1
  82. data/spec/expressir/express_exp/{parse_remark_spec.rb → parser/remark_spec.rb} +2 -2
  83. data/spec/expressir/express_exp/{source_spec.rb → parser/source_spec.rb} +1 -1
  84. data/spec/expressir/express_exp/{parse_syntax_spec.rb → parser/syntax_spec.rb} +76 -44
  85. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +36 -0
  86. data/spec/expressir/model/{scope_spec.rb → model_element/find_spec.rb} +7 -2
  87. data/spec/expressir/model/{model_element_spec.rb → model_element/hash_spec.rb} +7 -18
  88. metadata +32 -13
  89. data/lib/expressir/model/scope.rb +0 -71
  90. data/spec/expressir/express_exp/ap233_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7ca823c0cea8c0464cb3e31d6cd59d82ad2d82613260b082633d99d98380fc9
4
- data.tar.gz: 0bceba8f9858852533ad4eb734b5b559a46ab97ba219594b5a44aab86e234f3d
3
+ metadata.gz: 752baf32f6dd6ee50c00a7816890e657cca06bf2d6caeb7fb59f2c9b26a76de4
4
+ data.tar.gz: 6956c5eb8889afabb1ba99cc81111e1f175425f2ae77d35e3d7964b662d7d77d
5
5
  SHA512:
6
- metadata.gz: 9831af9252d67dee6425594d251471a64f9c769d953610fbbeb7932eed7cf3599429e466e12f78f61b793d1a294487a24dd0b8f4d04111eda1f77de611f82e52
7
- data.tar.gz: 67dcad8003be72122c2b9aeeb504ce33cfd4e74fa509fa9de795050f9051b7be4220398d6de2b94d182fe15431ebbfc593c9aaf8685c03448f77558f04eec1e3
6
+ metadata.gz: a611a4cc0b0f00e98ccd2ee99d2fa3331fb8fbb2541555314c9afc1ac892a05a514a8f9902d99c896bd0a752ad2ade1986e7d3569e17852d2236792546a4e61a
7
+ data.tar.gz: 02e514f4037f7bb3e543aef11db5c9a7dd60fec258753e4dccebaf561ccf6b2b72b782b50b2ece15df41186c366457c1f023f7e29ec67f0b1907eb6443920a55
data/exe/format ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "expressir/express_exp/parser"
4
+ require "expressir/express_exp/hyperlink_formatter"
5
+
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
+ ]
11
+
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)
15
+
16
+ puts result
data/expressir.gemspec CHANGED
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "antlr4-native", "~> 1.1.0"
37
37
  spec.add_development_dependency "bundler", "~> 2.0"
38
38
  spec.add_development_dependency "pry", "~> 0.12.2"
39
+ spec.add_development_dependency "byebug", "~> 11.1"
39
40
  spec.add_development_dependency "rake", "~> 13.0"
40
41
  spec.add_development_dependency "rake-compiler", "~> 1.1"
41
42
  spec.add_development_dependency "rake-compiler-dock", "~> 1.1"
@@ -38,129 +38,129 @@ module Expressir
38
38
  end
39
39
 
40
40
  def format(node)
41
- if node.instance_of? Model::Attribute
41
+ if node.is_a? Model::Attribute
42
42
  format_attribute(node)
43
- elsif node.instance_of? Model::Constant
43
+ elsif node.is_a? Model::Constant
44
44
  format_constant(node)
45
- elsif node.instance_of? Model::Entity
45
+ elsif node.is_a? Model::Entity
46
46
  format_entity(node)
47
- elsif node.instance_of? Model::EnumerationItem
47
+ elsif node.is_a? Model::EnumerationItem
48
48
  format_enumeration_item(node)
49
- elsif node.instance_of? Model::Function
49
+ elsif node.is_a? Model::Function
50
50
  format_function(node)
51
- elsif node.instance_of? Model::Interface
51
+ elsif node.is_a? Model::Interface
52
52
  format_interface(node)
53
- elsif node.instance_of? Model::Parameter
53
+ elsif node.is_a? Model::Parameter
54
54
  format_parameter(node)
55
- elsif node.instance_of? Model::Procedure
55
+ elsif node.is_a? Model::Procedure
56
56
  format_procedure(node)
57
- elsif node.instance_of? Model::RenamedRef
57
+ elsif node.is_a? Model::RenamedRef
58
58
  format_renamed_ref(node)
59
- elsif node.instance_of? Model::Repository
59
+ elsif node.is_a? Model::Repository
60
60
  format_repository(node)
61
- elsif node.instance_of? Model::Rule
61
+ elsif node.is_a? Model::Rule
62
62
  format_rule(node)
63
- elsif node.instance_of? Model::Schema
63
+ elsif node.is_a? Model::Schema
64
64
  format_schema(node)
65
- elsif node.instance_of? Model::SubtypeConstraint
65
+ elsif node.is_a? Model::SubtypeConstraint
66
66
  format_subtype_constraint(node)
67
- elsif node.instance_of? Model::Type
67
+ elsif node.is_a? Model::Type
68
68
  format_type(node)
69
- elsif node.instance_of? Model::Unique
69
+ elsif node.is_a? Model::Unique
70
70
  format_unique(node)
71
- elsif node.instance_of? Model::Variable
71
+ elsif node.is_a? Model::Variable
72
72
  format_variable(node)
73
- elsif node.instance_of? Model::Where
73
+ elsif node.is_a? Model::Where
74
74
  format_where(node)
75
- elsif node.instance_of? Model::Expressions::AggregateInitializer
75
+ elsif node.is_a? Model::Expressions::AggregateInitializer
76
76
  format_expressions_aggregate_initializer(node)
77
- elsif node.instance_of? Model::Expressions::AggregateItem
77
+ elsif node.is_a? Model::Expressions::AggregateItem
78
78
  format_expressions_aggregate_item(node)
79
- elsif node.instance_of? Model::Expressions::AttributeReference
79
+ elsif node.is_a? Model::Expressions::AttributeReference
80
80
  format_expressions_attribute_reference(node)
81
- elsif node.instance_of? Model::Expressions::BinaryExpression
81
+ elsif node.is_a? Model::Expressions::BinaryExpression
82
82
  format_expressions_binary_expression(node)
83
- elsif node.instance_of? Model::Expressions::Call
83
+ elsif node.is_a? Model::Expressions::Call
84
84
  format_expressions_call(node)
85
- elsif node.instance_of? Model::Expressions::EntityConstructor
85
+ elsif node.is_a? Model::Expressions::EntityConstructor
86
86
  format_expressions_entity_constructor(node)
87
- elsif node.instance_of? Model::Expressions::GroupReference
87
+ elsif node.is_a? Model::Expressions::GroupReference
88
88
  format_expressions_group_reference(node)
89
- elsif node.instance_of? Model::Expressions::IndexReference
89
+ elsif node.is_a? Model::Expressions::IndexReference
90
90
  format_expressions_index_reference(node)
91
- elsif node.instance_of? Model::Expressions::Interval
91
+ elsif node.is_a? Model::Expressions::Interval
92
92
  format_expressions_interval(node)
93
- elsif node.instance_of? Model::Expressions::QueryExpression
93
+ elsif node.is_a? Model::Expressions::QueryExpression
94
94
  format_expressions_query_expression(node)
95
- elsif node.instance_of? Model::Expressions::SimpleReference
95
+ elsif node.is_a? Model::Expressions::SimpleReference
96
96
  format_expressions_simple_reference(node)
97
- elsif node.instance_of? Model::Expressions::UnaryExpression
97
+ elsif node.is_a? Model::Expressions::UnaryExpression
98
98
  format_expressions_unary_expression(node)
99
- elsif node.instance_of? Model::Literals::Binary
99
+ elsif node.is_a? Model::Literals::Binary
100
100
  format_literals_binary(node)
101
- elsif node.instance_of? Model::Literals::Integer
101
+ elsif node.is_a? Model::Literals::Integer
102
102
  format_literals_integer(node)
103
- elsif node.instance_of? Model::Literals::Logical
103
+ elsif node.is_a? Model::Literals::Logical
104
104
  format_literals_logical(node)
105
- elsif node.instance_of? Model::Literals::Real
105
+ elsif node.is_a? Model::Literals::Real
106
106
  format_literals_real(node)
107
- elsif node.instance_of? Model::Literals::String
107
+ elsif node.is_a? Model::Literals::String
108
108
  format_literals_string(node)
109
- elsif node.instance_of? Model::Statements::Alias
109
+ elsif node.is_a? Model::Statements::Alias
110
110
  format_statements_alias(node)
111
- elsif node.instance_of? Model::Statements::Assignment
111
+ elsif node.is_a? Model::Statements::Assignment
112
112
  format_statements_assignment(node)
113
- elsif node.instance_of? Model::Statements::Call
113
+ elsif node.is_a? Model::Statements::Call
114
114
  format_statements_call(node)
115
- elsif node.instance_of? Model::Statements::Case
115
+ elsif node.is_a? Model::Statements::Case
116
116
  format_statements_case(node)
117
- elsif node.instance_of? Model::Statements::CaseAction
117
+ elsif node.is_a? Model::Statements::CaseAction
118
118
  format_statements_case_action(node)
119
- elsif node.instance_of? Model::Statements::Compound
119
+ elsif node.is_a? Model::Statements::Compound
120
120
  format_statements_compound(node)
121
- elsif node.instance_of? Model::Statements::Escape
121
+ elsif node.is_a? Model::Statements::Escape
122
122
  format_statements_escape(node)
123
- elsif node.instance_of? Model::Statements::If
123
+ elsif node.is_a? Model::Statements::If
124
124
  format_statements_if(node)
125
- elsif node.instance_of? Model::Statements::Null
125
+ elsif node.is_a? Model::Statements::Null
126
126
  format_statements_null(node)
127
- elsif node.instance_of? Model::Statements::Repeat
127
+ elsif node.is_a? Model::Statements::Repeat
128
128
  format_statements_repeat(node)
129
- elsif node.instance_of? Model::Statements::Return
129
+ elsif node.is_a? Model::Statements::Return
130
130
  format_statements_return(node)
131
- elsif node.instance_of? Model::Statements::Skip
131
+ elsif node.is_a? Model::Statements::Skip
132
132
  format_statements_skip(node)
133
- elsif node.instance_of? Model::Types::Aggregate
133
+ elsif node.is_a? Model::Types::Aggregate
134
134
  format_types_aggregate(node)
135
- elsif node.instance_of? Model::Types::Array
135
+ elsif node.is_a? Model::Types::Array
136
136
  format_types_array(node)
137
- elsif node.instance_of? Model::Types::Bag
137
+ elsif node.is_a? Model::Types::Bag
138
138
  format_types_bag(node)
139
- elsif node.instance_of? Model::Types::Binary
139
+ elsif node.is_a? Model::Types::Binary
140
140
  format_types_binary(node)
141
- elsif node.instance_of? Model::Types::Boolean
141
+ elsif node.is_a? Model::Types::Boolean
142
142
  format_types_boolean(node)
143
- elsif node.instance_of? Model::Types::Enumeration
143
+ elsif node.is_a? Model::Types::Enumeration
144
144
  format_types_enumeration(node)
145
- elsif node.instance_of? Model::Types::GenericEntity
145
+ elsif node.is_a? Model::Types::GenericEntity
146
146
  format_types_generic_entity(node)
147
- elsif node.instance_of? Model::Types::Generic
147
+ elsif node.is_a? Model::Types::Generic
148
148
  format_types_generic(node)
149
- elsif node.instance_of? Model::Types::Integer
149
+ elsif node.is_a? Model::Types::Integer
150
150
  format_types_integer(node)
151
- elsif node.instance_of? Model::Types::List
151
+ elsif node.is_a? Model::Types::List
152
152
  format_types_list(node)
153
- elsif node.instance_of? Model::Types::Logical
153
+ elsif node.is_a? Model::Types::Logical
154
154
  format_types_logical(node)
155
- elsif node.instance_of? Model::Types::Number
155
+ elsif node.is_a? Model::Types::Number
156
156
  format_types_number(node)
157
- elsif node.instance_of? Model::Types::Real
157
+ elsif node.is_a? Model::Types::Real
158
158
  format_types_real(node)
159
- elsif node.instance_of? Model::Types::Select
159
+ elsif node.is_a? Model::Types::Select
160
160
  format_types_select(node)
161
- elsif node.instance_of? Model::Types::Set
161
+ elsif node.is_a? Model::Types::Set
162
162
  format_types_set(node)
163
- elsif node.instance_of? Model::Types::String
163
+ elsif node.is_a? Model::Types::String
164
164
  format_types_string(node)
165
165
  else
166
166
  puts node.class
@@ -509,8 +509,7 @@ module Expressir
509
509
  [
510
510
  *if node.schemas and node.schemas.length > 0
511
511
  node.schemas.map{|node| format(node)}
512
- end,
513
- *format_scope_remarks(node)
512
+ end
514
513
  ].join("\n")
515
514
  end
516
515
 
@@ -627,7 +626,8 @@ module Expressir
627
626
  [
628
627
  'END_SCHEMA',
629
628
  ';'
630
- ].join('')
629
+ ].join(''),
630
+ *format_scope_remarks(node)
631
631
  ].join("\n")
632
632
  end
633
633
 
@@ -773,11 +773,11 @@ module Expressir
773
773
 
774
774
  def format_expressions_binary_expression(node)
775
775
  [
776
- *if node.operand1.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
776
+ *if node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
777
777
  '('
778
778
  end,
779
779
  format(node.operand1),
780
- *if node.operand1.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
780
+ *if node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]
781
781
  ')'
782
782
  end,
783
783
  ' ',
@@ -806,11 +806,11 @@ module Expressir
806
806
  when Model::Expressions::BinaryExpression::XOR then 'XOR'
807
807
  end,
808
808
  ' ',
809
- *if node.operand2.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
809
+ *if node.operand2.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
810
810
  '('
811
811
  end,
812
812
  format(node.operand2),
813
- *if node.operand2.instance_of? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
813
+ *if node.operand2.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]
814
814
  ')'
815
815
  end,
816
816
  ].join('')
@@ -911,11 +911,11 @@ module Expressir
911
911
  if node.operator == Model::Expressions::UnaryExpression::NOT
912
912
  ' '
913
913
  end,
914
- *if node.operand.instance_of? Model::Expressions::BinaryExpression
914
+ *if node.operand.is_a? Model::Expressions::BinaryExpression
915
915
  '('
916
916
  end,
917
917
  format(node.operand),
918
- *if node.operand.instance_of? Model::Expressions::BinaryExpression
918
+ *if node.operand.is_a? Model::Expressions::BinaryExpression
919
919
  ')'
920
920
  end
921
921
  ].join('')
@@ -1442,25 +1442,13 @@ module Expressir
1442
1442
  str.split("\n").map{|x| "#{INDENT}#{x}"}.join("\n")
1443
1443
  end
1444
1444
 
1445
- def format_remark_ref(node)
1446
- [
1447
- *if node.class.method_defined? :parent and node.parent.class.method_defined? :id and node.parent != node
1448
- [
1449
- format_remark_ref(node.parent),
1450
- '.'
1451
- ].join('')
1452
- end,
1453
- node.id,
1454
- ].join('')
1455
- end
1456
-
1457
1445
  def format_remark(node, remark)
1458
1446
  if remark.include?("\n")
1459
1447
  [
1460
1448
  [
1461
1449
  '(*',
1462
1450
  '"',
1463
- format_remark_ref(node),
1451
+ node.path,
1464
1452
  '"',
1465
1453
  ].join(''),
1466
1454
  remark,
@@ -1470,7 +1458,7 @@ module Expressir
1470
1458
  [
1471
1459
  '--',
1472
1460
  '"',
1473
- format_remark_ref(node),
1461
+ node.path,
1474
1462
  '"',
1475
1463
  ' ',
1476
1464
  remark
@@ -1479,7 +1467,7 @@ module Expressir
1479
1467
  end
1480
1468
 
1481
1469
  def format_remarks(node)
1482
- if node.class.method_defined? :remarks and node.remarks and node.remarks.length > 0
1470
+ if node.class.method_defined? :remarks
1483
1471
  node.remarks.map do |remark|
1484
1472
  format_remark(node, remark)
1485
1473
  end
@@ -1491,9 +1479,7 @@ module Expressir
1491
1479
  def format_scope_remarks(node)
1492
1480
  [
1493
1481
  *format_remarks(node),
1494
- *if node.class.method_defined? :children
1495
- node.children.select{|x| x.parent == node}.flat_map{|x| format_scope_remarks(x)}
1496
- end
1482
+ *node.children.select{|x| !x.is_a? Model::EnumerationItem or node.is_a? Model::Type}.flat_map{|x| format_scope_remarks(x)}
1497
1483
  ]
1498
1484
  end
1499
1485
  end
@@ -0,0 +1,25 @@
1
+ require "expressir/express_exp/formatter"
2
+
3
+ module Expressir
4
+ module ExpressExp
5
+ class HyperlinkFormatter < Formatter
6
+ def format_expressions_simple_reference(node)
7
+ return node.id if node.parent.is_a? Model::Expressions::AttributeReference
8
+
9
+ # skip hyperlink if target node can't be found
10
+ target_node = node.find(node.id)
11
+ return node.id unless target_node
12
+
13
+ # skip hyperlink for implicit scopes
14
+ return node.id if target_node.is_a? Model::Statements::Alias or target_node.is_a? Model::Statements::Repeat or target_node.is_a? Model::Expressions::QueryExpression
15
+
16
+ # skip hyperlink if this node and target node are in the same main item
17
+ node_path_parts = node.path.split(".")
18
+ target_node_path_parts = target_node.path.split(".")
19
+ return node.id if node_path_parts[0..1] == target_node_path_parts[0..1]
20
+
21
+ "{{{<<express:#{target_node.path},#{node.id}>>}}}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require "expressir/express_exp/formatter"
2
+
3
+ module Expressir
4
+ module ExpressExp
5
+ class SchemaHeadFormatter < Formatter
6
+ def format_schema(node)
7
+ [
8
+ "SCHEMA #{node.id}#{node.version ? " #{format(node.version)}" : ""};",
9
+ *node.interfaces.map{|x| format(x)}
10
+ ].join("\n")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -14,7 +14,7 @@ require "set"
14
14
  # > method of gaining this information is multi-pass parsing: the first pass collects the identifiers from their
15
15
  # > declarations, so that subsequent passes are then able to distinguish a veriable_ref from a function_ref,
16
16
  # > for example.
17
- #
17
+ # - such multi-pass parsing is not implemented yet
18
18
  # - xxxRef - merged to SimpleReference
19
19
  # - entityConstructor, functionCall - merged to Call
20
20
  #
@@ -44,11 +44,10 @@ module Expressir
44
44
  end
45
45
 
46
46
  def visit(ctx)
47
- result = super(ctx)
48
- attach_source(ctx, result)
49
- attach_parent(result)
50
- attach_remarks(ctx, result)
51
- result
47
+ node = super(ctx)
48
+ attach_source(ctx, node)
49
+ attach_remarks(ctx, node)
50
+ node
52
51
  end
53
52
 
54
53
  def visit_if(ctx, default = nil)
@@ -84,7 +83,7 @@ module Expressir
84
83
  end
85
84
 
86
85
  def get_tokens(ctx)
87
- start_index, stop_index = if ctx.instance_of? ::ExpressParser::SyntaxContext
86
+ start_index, stop_index = if ctx.is_a? ::ExpressParser::SyntaxContext
88
87
  [0, @tokens.size - 1]
89
88
  else
90
89
  [ctx.start.token_index, ctx.stop.token_index]
@@ -94,7 +93,7 @@ module Expressir
94
93
  end
95
94
 
96
95
  def get_head_tokens(ctx)
97
- start_index, stop_index = if ctx.instance_of? ::ExpressParser::SchemaDeclContext
96
+ start_index, stop_index = if ctx.is_a? ::ExpressParser::SchemaDeclContext
98
97
  start_index = ctx.start.token_index
99
98
  stop_index = if ctx.schema_body.interface_specification.length > 0
100
99
  ctx.schema_body.interface_specification.last.stop.token_index
@@ -124,25 +123,30 @@ module Expressir
124
123
  end
125
124
  end
126
125
 
127
- def attach_parent(node)
128
- if node.class.method_defined? :attach_parent_to_children
129
- node.attach_parent_to_children
130
- end
131
- end
132
-
133
126
  def find_remark_target(node, path)
134
- current_node = node
135
- target_node = nil
127
+ target_node = node.find(path)
128
+ return target_node if target_node
136
129
 
137
- if current_node.class.method_defined? :find_or_create
138
- target_node = current_node.find_or_create(path)
139
- end
140
- while !target_node and current_node.class.method_defined? :parent and current_node.parent.class.method_defined? :find_or_create
141
- current_node = current_node.parent
142
- target_node = current_node.find_or_create(path)
143
- end
130
+ # check if path should create implicit informal proposal
131
+ # see https://github.com/lutaml/expressir/issues/50
132
+ rest, _, current_path = path.rpartition(".") # get last path part
133
+ _, _, current_path = current_path.rpartition(":") # ignore prefix
144
134
 
145
- target_node
135
+ # match informal proposition id
136
+ informal_proposition_id = current_path.match(/^IP\d+$/).to_a[0]
137
+ return unless informal_proposition_id
138
+
139
+ # find informal proposition target
140
+ target_node = node.find(rest)
141
+ return unless target_node and target_node.class.method_defined? :informal_propositions
142
+
143
+ # create implicit informal proposition
144
+ informal_proposition = Model::InformalProposition.new({
145
+ id: informal_proposition_id
146
+ })
147
+ target_node.informal_propositions << informal_proposition
148
+ informal_proposition.parent = target_node
149
+ informal_proposition
146
150
  end
147
151
 
148
152
  def attach_remarks(ctx, node)
@@ -767,7 +771,7 @@ module Expressir
767
771
  id = visit_if(ctx__entity_head__entity_id)
768
772
  abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true
769
773
  supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule)
770
- subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration)
774
+ subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, [])
771
775
  attributes = [
772
776
  *visit_if_map_flatten(ctx__entity_body__explicit_attr),
773
777
  *visit_if(ctx__entity_body__derive_clause),
@@ -967,11 +971,11 @@ module Expressir
967
971
  parameters = visit_if_map_flatten(ctx__function_head__formal_parameter)
968
972
  return_type = visit_if(ctx__function_head__parameter_type)
969
973
  declarations = visit_if_map(ctx__algorithm_head__declaration)
970
- types = declarations.select{|x| x.instance_of? Model::Type}
971
- entities = declarations.select{|x| x.instance_of? Model::Entity}
972
- subtype_constraints = declarations.select{|x| x.instance_of? Model::SubtypeConstraint}
973
- functions = declarations.select{|x| x.instance_of? Model::Function}
974
- procedures = declarations.select{|x| x.instance_of? Model::Procedure}
974
+ types = declarations.select{|x| x.is_a? Model::Type}
975
+ entities = declarations.select{|x| x.is_a? Model::Entity}
976
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
977
+ functions = declarations.select{|x| x.is_a? Model::Function}
978
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
975
979
  constants = visit_if(ctx__algorithm_head__constant_decl, [])
976
980
  variables = visit_if(ctx__algorithm_head__local_decl, [])
977
981
  statements = visit_if_map(ctx__stmt)
@@ -1595,11 +1599,11 @@ module Expressir
1595
1599
  id = visit_if(ctx__procedure_head__procedure_id)
1596
1600
  parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter)
1597
1601
  declarations = visit_if_map(ctx__algorithm_head__declaration)
1598
- types = declarations.select{|x| x.instance_of? Model::Type}
1599
- entities = declarations.select{|x| x.instance_of? Model::Entity}
1600
- subtype_constraints = declarations.select{|x| x.instance_of? Model::SubtypeConstraint}
1601
- functions = declarations.select{|x| x.instance_of? Model::Function}
1602
- procedures = declarations.select{|x| x.instance_of? Model::Procedure}
1602
+ types = declarations.select{|x| x.is_a? Model::Type}
1603
+ entities = declarations.select{|x| x.is_a? Model::Entity}
1604
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1605
+ functions = declarations.select{|x| x.is_a? Model::Function}
1606
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1603
1607
  constants = visit_if(ctx__algorithm_head__constant_decl, [])
1604
1608
  variables = visit_if(ctx__algorithm_head__local_decl, [])
1605
1609
  statements = visit_if_map(ctx__stmt)
@@ -1837,20 +1841,16 @@ module Expressir
1837
1841
  ctx__resource_ref = ctx.resource_ref
1838
1842
  ctx__rename_id = ctx.rename_id
1839
1843
 
1840
- if ctx__resource_ref
1841
- if ctx__rename_id
1842
- ref = visit(ctx__resource_ref)
1843
- id = visit(ctx__rename_id)
1844
+ ref = visit_if(ctx__resource_ref)
1845
+ id = visit_if(ctx__rename_id)
1844
1846
 
1845
- Model::RenamedRef.new({
1846
- ref: ref,
1847
- id: id
1848
- })
1849
- else
1850
- visit(ctx__resource_ref)
1851
- end
1847
+ if id
1848
+ Model::RenamedRef.new({
1849
+ ref: ref,
1850
+ id: id
1851
+ })
1852
1852
  else
1853
- raise 'Invalid state'
1853
+ ref
1854
1854
  end
1855
1855
  end
1856
1856
 
@@ -1888,11 +1888,11 @@ module Expressir
1888
1888
  id = visit_if(ctx__rule_head__rule_id)
1889
1889
  applies_to = visit_if_map(ctx__rule_head__entity_ref)
1890
1890
  declarations = visit_if_map(ctx__algorithm_head__declaration)
1891
- types = declarations.select{|x| x.instance_of? Model::Type}
1892
- entities = declarations.select{|x| x.instance_of? Model::Entity}
1893
- subtype_constraints = declarations.select{|x| x.instance_of? Model::SubtypeConstraint}
1894
- functions = declarations.select{|x| x.instance_of? Model::Function}
1895
- procedures = declarations.select{|x| x.instance_of? Model::Procedure}
1891
+ types = declarations.select{|x| x.is_a? Model::Type}
1892
+ entities = declarations.select{|x| x.is_a? Model::Entity}
1893
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1894
+ functions = declarations.select{|x| x.is_a? Model::Function}
1895
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1896
1896
  constants = visit_if(ctx__algorithm_head__constant_decl, [])
1897
1897
  variables = visit_if(ctx__algorithm_head__local_decl, [])
1898
1898
  statements = visit_if_map(ctx__stmt)
@@ -1953,12 +1953,12 @@ module Expressir
1953
1953
  interfaces = visit_if_map(ctx__schema_body__interface_specification)
1954
1954
  constants = visit_if(ctx__schema_body__constant_decl, [])
1955
1955
  declarations = visit_if_map(ctx__schema_body__schema_body_declaration)
1956
- types = declarations.select{|x| x.instance_of? Model::Type}
1957
- entities = declarations.select{|x| x.instance_of? Model::Entity}
1958
- subtype_constraints = declarations.select{|x| x.instance_of? Model::SubtypeConstraint}
1959
- functions = declarations.select{|x| x.instance_of? Model::Function}
1960
- procedures = declarations.select{|x| x.instance_of? Model::Procedure}
1961
- rules = declarations.select{|x| x.instance_of? Model::Rule}
1956
+ types = declarations.select{|x| x.is_a? Model::Type}
1957
+ entities = declarations.select{|x| x.is_a? Model::Entity}
1958
+ subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1959
+ functions = declarations.select{|x| x.is_a? Model::Function}
1960
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1961
+ rules = declarations.select{|x| x.is_a? Model::Rule}
1962
1962
 
1963
1963
  Model::Schema.new({
1964
1964
  id: id,