expressir 0.2.16-x86-mingw32 → 0.2.24-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +5 -0
  3. data/.github/workflows/release.yml +31 -3
  4. data/README.adoc +3 -3
  5. data/exe/format +66 -12
  6. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  7. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  8. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  9. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  10. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  11. data/lib/expressir/express_exp/cache.rb +48 -0
  12. data/lib/expressir/express_exp/formatter.rb +185 -135
  13. data/lib/expressir/express_exp/parser.rb +33 -29
  14. data/lib/expressir/express_exp/schema_head_formatter.rb +1 -4
  15. data/lib/expressir/express_exp/visitor.rb +29 -23
  16. data/lib/expressir/model.rb +3 -1
  17. data/lib/expressir/model/attribute.rb +12 -5
  18. data/lib/expressir/model/cache.rb +13 -0
  19. data/lib/expressir/model/constant.rb +9 -2
  20. data/lib/expressir/model/entity.rb +15 -13
  21. data/lib/expressir/model/enumeration_item.rb +7 -0
  22. data/lib/expressir/model/expressions/aggregate_initializer.rb +1 -1
  23. data/lib/expressir/model/expressions/aggregate_item.rb +2 -2
  24. data/lib/expressir/model/expressions/attribute_reference.rb +2 -2
  25. data/lib/expressir/model/expressions/binary_expression.rb +3 -3
  26. data/lib/expressir/model/expressions/call.rb +2 -2
  27. data/lib/expressir/model/expressions/entity_constructor.rb +2 -2
  28. data/lib/expressir/model/expressions/group_reference.rb +2 -2
  29. data/lib/expressir/model/expressions/index_reference.rb +3 -3
  30. data/lib/expressir/model/expressions/interval.rb +5 -5
  31. data/lib/expressir/model/expressions/query_expression.rb +7 -5
  32. data/lib/expressir/model/expressions/simple_reference.rb +1 -1
  33. data/lib/expressir/model/expressions/unary_expression.rb +2 -2
  34. data/lib/expressir/model/function.rb +27 -21
  35. data/lib/expressir/model/identifier.rb +6 -3
  36. data/lib/expressir/model/interface.rb +3 -3
  37. data/lib/expressir/model/interface_item.rb +2 -2
  38. data/lib/expressir/model/interfaced_item.rb +11 -3
  39. data/lib/expressir/model/literals/binary.rb +1 -1
  40. data/lib/expressir/model/literals/integer.rb +1 -1
  41. data/lib/expressir/model/literals/logical.rb +1 -1
  42. data/lib/expressir/model/literals/real.rb +1 -1
  43. data/lib/expressir/model/literals/string.rb +2 -2
  44. data/lib/expressir/model/model_element.rb +54 -19
  45. data/lib/expressir/model/parameter.rb +9 -2
  46. data/lib/expressir/model/procedure.rb +26 -20
  47. data/lib/expressir/model/{informal_proposition.rb → remark_item.rb} +3 -3
  48. data/lib/expressir/model/repository.rb +4 -4
  49. data/lib/expressir/model/rule.rb +29 -23
  50. data/lib/expressir/model/schema.rb +63 -54
  51. data/lib/expressir/model/statements/alias.rb +7 -5
  52. data/lib/expressir/model/statements/assignment.rb +2 -2
  53. data/lib/expressir/model/statements/call.rb +2 -2
  54. data/lib/expressir/model/statements/case.rb +3 -3
  55. data/lib/expressir/model/statements/case_action.rb +2 -2
  56. data/lib/expressir/model/statements/compound.rb +1 -1
  57. data/lib/expressir/model/statements/if.rb +3 -3
  58. data/lib/expressir/model/statements/repeat.rb +11 -9
  59. data/lib/expressir/model/statements/return.rb +1 -1
  60. data/lib/expressir/model/subtype_constraint.rb +9 -7
  61. data/lib/expressir/model/type.rb +14 -8
  62. data/lib/expressir/model/types/aggregate.rb +8 -1
  63. data/lib/expressir/model/types/array.rb +5 -5
  64. data/lib/expressir/model/types/bag.rb +3 -3
  65. data/lib/expressir/model/types/binary.rb +2 -2
  66. data/lib/expressir/model/types/enumeration.rb +4 -4
  67. data/lib/expressir/model/types/generic.rb +7 -0
  68. data/lib/expressir/model/types/generic_entity.rb +7 -0
  69. data/lib/expressir/model/types/list.rb +4 -4
  70. data/lib/expressir/model/types/real.rb +1 -1
  71. data/lib/expressir/model/types/select.rb +5 -5
  72. data/lib/expressir/model/types/set.rb +3 -3
  73. data/lib/expressir/model/types/string.rb +2 -2
  74. data/lib/expressir/model/unique.rb +8 -1
  75. data/lib/expressir/model/variable.rb +9 -2
  76. data/lib/expressir/model/where.rb +8 -1
  77. data/lib/expressir/version.rb +1 -1
  78. data/original/examples/syntax/{hyperlink.exp → multiple.exp} +8 -8
  79. data/original/examples/syntax/multiple.yaml +184 -0
  80. data/original/examples/syntax/multiple_formatted.exp +71 -0
  81. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  82. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  83. data/original/examples/syntax/remark.exp +52 -50
  84. data/original/examples/syntax/remark.yaml +452 -0
  85. data/original/examples/syntax/remark_formatted.exp +64 -50
  86. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  87. data/original/examples/syntax/single.yaml +9 -0
  88. data/original/examples/syntax/single_formatted.exp +6 -0
  89. data/original/examples/syntax/single_formatted.yaml +19 -0
  90. data/original/examples/syntax/syntax.exp +29 -19
  91. data/original/examples/syntax/syntax.yaml +3439 -0
  92. data/original/examples/syntax/syntax_formatted.exp +271 -131
  93. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  94. data/spec/expressir/express_exp/cache_spec.rb +64 -0
  95. data/spec/expressir/express_exp/formatter_spec.rb +111 -0
  96. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  97. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +96 -10
  98. metadata +21 -17
  99. data/original/examples/syntax/hyperlink_formatted.exp +0 -51
  100. data/original/examples/syntax/source.exp +0 -16
  101. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  102. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  103. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -28
  104. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
  105. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  106. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  107. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3086
  108. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -40
  109. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -6,54 +6,58 @@ rescue LoadError
6
6
  end
7
7
  require 'expressir/express_exp/visitor'
8
8
 
9
- module Expressir
10
- module ExpressExp
11
- class Parser
12
- def self.from_file(file)
13
- input = File.read(file)
14
-
15
9
  =begin
16
- char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
17
- lexer = ::ExpressParser::Lexer.new(char_stream)
18
- token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
19
- parser = ::ExpressParser::Parser.new(token_stream)
10
+ char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
11
+ lexer = ::ExpressParser::Lexer.new(char_stream)
12
+ token_stream = Antlr4::Runtime::CommonTokenStream.new(lexer)
13
+ parser = ::ExpressParser::Parser.new(token_stream)
20
14
 
21
- # don't attempt to recover from any parsing error
22
- parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)
15
+ # don't attempt to recover from any parsing error
16
+ parser.instance_variable_set(:@_err_handler, Antlr4::Runtime::BailErrorStrategy.new)
23
17
 
24
- parse_tree = parser.syntax()
18
+ parse_tree = parser.syntax()
25
19
 
26
- visitor = Visitor.new(token_stream)
27
- repo = visitor.visit(parse_tree)
20
+ visitor = Visitor.new(token_stream)
21
+ repo = visitor.visit(parse_tree)
28
22
  =end
29
23
 
24
+ module Expressir
25
+ module ExpressExp
26
+ class Parser
27
+ def self.from_file(file, options = {})
28
+ input = File.read(file)
29
+
30
30
  parser = ::ExpressParser::Parser.parse(input)
31
31
 
32
32
  parse_tree = parser.syntax()
33
33
 
34
- visitor = Visitor.new(parser.tokens)
35
- repo = visitor.visit(parse_tree)
34
+ visitor = Visitor.new(parser.tokens, options)
35
+ repository = visitor.visit(parse_tree)
36
36
 
37
- repo.schemas.each{|schema| schema.file = file}
37
+ repository.schemas.each do |schema|
38
+ schema.file = file.to_s
39
+ end
38
40
 
39
- repo
41
+ repository
40
42
  end
41
43
 
42
- def self.from_files(files)
43
- schemas = files.map{|file| self.from_file(file).schemas}.flatten
44
+ def self.from_files(files, options = {})
45
+ schemas = files.each_with_index.map do |file, i|
46
+ # start = Time.now
47
+ repository = self.from_file(file, options)
48
+ # STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}"
49
+ repository.schemas
50
+ end.flatten
44
51
 
45
- repo = Model::Repository.new({
52
+ repository = Model::Repository.new({
46
53
  schemas: schemas
47
54
  })
48
55
 
49
- repo.schemas.each{|schema| schema.parent = repo}
50
-
51
- repo
52
- end
56
+ repository.schemas.each do |schema|
57
+ schema.parent = repository
58
+ end
53
59
 
54
- # deprecated
55
- def self.from_exp(file)
56
- self.from_file(file)
60
+ repository
57
61
  end
58
62
  end
59
63
  end
@@ -2,10 +2,7 @@ module Expressir
2
2
  module ExpressExp
3
3
  module SchemaHeadFormatter
4
4
  def format_schema(node)
5
- [
6
- "SCHEMA #{node.id}#{node.version ? " #{format(node.version)}" : ""};",
7
- *node.interfaces.map{|x| format(x)}
8
- ].join("\n")
5
+ format_schema_head(node)
9
6
  end
10
7
  end
11
8
  end
@@ -36,8 +36,10 @@ module Expressir
36
36
  class Visitor < ::ExpressParser::Visitor
37
37
  REMARK_CHANNEL = 2
38
38
 
39
- def initialize(tokens)
39
+ def initialize(tokens, options = {})
40
40
  @tokens = tokens
41
+ @include_source = options[:include_source]
42
+
41
43
  @attached_remark_tokens = ::Set.new
42
44
 
43
45
  super()
@@ -45,7 +47,9 @@ module Expressir
45
47
 
46
48
  def visit(ctx)
47
49
  node = super(ctx)
48
- attach_source(ctx, node)
50
+ if @include_source
51
+ attach_source(ctx, node)
52
+ end
49
53
  attach_remarks(ctx, node)
50
54
  node
51
55
  end
@@ -103,26 +107,28 @@ module Expressir
103
107
  target_node = node.find(path)
104
108
  return target_node if target_node
105
109
 
106
- # check if path should create implicit informal proposal
107
- # see https://github.com/lutaml/expressir/issues/50
110
+ # check if path can create implicit remark item
111
+ # see https://github.com/lutaml/expressir/issues/78
108
112
  rest, _, current_path = path.rpartition(".") # get last path part
109
113
  _, _, current_path = current_path.rpartition(":") # ignore prefix
114
+ parent_node = node.find(rest)
115
+ if parent_node and parent_node.class.method_defined? :remark_items
116
+ remark_item = Model::RemarkItem.new({
117
+ id: current_path
118
+ })
119
+ remark_item.parent = parent_node
110
120
 
111
- # match informal proposition id
112
- informal_proposition_id = current_path.match(/^IP\d+$/).to_a[0]
113
- return unless informal_proposition_id
114
-
115
- # find informal proposition target
116
- target_node = node.find(rest)
117
- return unless target_node and target_node.class.method_defined? :informal_propositions
118
-
119
- # create implicit informal proposition
120
- informal_proposition = Model::InformalProposition.new({
121
- id: informal_proposition_id
122
- })
123
- target_node.informal_propositions << informal_proposition
124
- informal_proposition.parent = target_node
125
- informal_proposition
121
+ # check if path can create implicit informal proposition
122
+ # see https://github.com/lutaml/expressir/issues/50
123
+ if parent_node.class.method_defined? :informal_propositions and current_path.match(/^IP\d+$/)
124
+ parent_node.informal_propositions << remark_item
125
+ else
126
+ parent_node.remark_items << remark_item
127
+ end
128
+ parent_node.reset_children_by_id
129
+
130
+ remark_item
131
+ end
126
132
  end
127
133
 
128
134
  def attach_remarks(ctx, node)
@@ -1925,8 +1931,8 @@ module Expressir
1925
1931
  entities = declarations.select{|x| x.is_a? Model::Entity}
1926
1932
  subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1927
1933
  functions = declarations.select{|x| x.is_a? Model::Function}
1928
- procedures = declarations.select{|x| x.is_a? Model::Procedure}
1929
1934
  rules = declarations.select{|x| x.is_a? Model::Rule}
1935
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1930
1936
 
1931
1937
  Model::Schema.new({
1932
1938
  id: id,
@@ -1937,8 +1943,8 @@ module Expressir
1937
1943
  entities: entities,
1938
1944
  subtype_constraints: subtype_constraints,
1939
1945
  functions: functions,
1940
- procedures: procedures,
1941
- rules: rules
1946
+ rules: rules,
1947
+ procedures: procedures
1942
1948
  })
1943
1949
  end
1944
1950
 
@@ -2149,7 +2155,7 @@ module Expressir
2149
2155
  id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2150
2156
  applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2151
2157
  abstract = ctx__subtype_constraint_body__abstract_supertype && true
2152
- total_over = visit_if(ctx__subtype_constraint_body__total_over)
2158
+ total_over = visit_if(ctx__subtype_constraint_body__total_over, [])
2153
2159
  supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2154
2160
 
2155
2161
  Model::SubtypeConstraint.new({
@@ -1,5 +1,7 @@
1
1
  require 'expressir/model/model_element'
2
2
 
3
+ require 'expressir/model/cache'
4
+
3
5
  require 'expressir/model/identifier'
4
6
 
5
7
  require 'expressir/model/attribute'
@@ -7,12 +9,12 @@ require 'expressir/model/constant'
7
9
  require 'expressir/model/entity'
8
10
  require 'expressir/model/enumeration_item'
9
11
  require 'expressir/model/function'
10
- require 'expressir/model/informal_proposition'
11
12
  require 'expressir/model/interface'
12
13
  require 'expressir/model/interface_item'
13
14
  require 'expressir/model/interfaced_item'
14
15
  require 'expressir/model/parameter'
15
16
  require 'expressir/model/procedure'
17
+ require 'expressir/model/remark_item'
16
18
  require 'expressir/model/repository'
17
19
  require 'expressir/model/rule'
18
20
  require 'expressir/model/schema'
@@ -7,15 +7,16 @@ module Expressir
7
7
  DERIVED = :DERIVED
8
8
  INVERSE = :INVERSE
9
9
 
10
- attr_accessor :kind
11
- attr_accessor :supertype_attribute
12
- attr_accessor :optional
13
- attr_accessor :type
14
- attr_accessor :expression
10
+ model_attr_accessor :kind
11
+ model_attr_accessor :supertype_attribute
12
+ model_attr_accessor :optional
13
+ model_attr_accessor :type
14
+ model_attr_accessor :expression
15
15
 
16
16
  def initialize(options = {})
17
17
  @id = options[:id]
18
18
  @remarks = options.fetch(:remarks, [])
19
+ @remark_items = options.fetch(:remark_items, [])
19
20
  @source = options[:source]
20
21
 
21
22
  @kind = options[:kind]
@@ -26,6 +27,12 @@ module Expressir
26
27
 
27
28
  super
28
29
  end
30
+
31
+ def children
32
+ [
33
+ *remark_items
34
+ ]
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -0,0 +1,13 @@
1
+ module Expressir
2
+ module Model
3
+ class Cache < ModelElement
4
+ model_attr_accessor :version
5
+ model_attr_accessor :content
6
+
7
+ def initialize(options = {})
8
+ @version = options[:version]
9
+ @content = options[:content]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,12 +3,13 @@ module Expressir
3
3
  class Constant < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :type
7
- attr_accessor :expression
6
+ model_attr_accessor :type
7
+ model_attr_accessor :expression
8
8
 
9
9
  def initialize(options = {})
10
10
  @id = options[:id]
11
11
  @remarks = options.fetch(:remarks, [])
12
+ @remark_items = options.fetch(:remark_items, [])
12
13
  @source = options[:source]
13
14
 
14
15
  @type = options[:type]
@@ -16,6 +17,12 @@ module Expressir
16
17
 
17
18
  super
18
19
  end
20
+
21
+ def children
22
+ [
23
+ *remark_items
24
+ ]
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -3,17 +3,18 @@ module Expressir
3
3
  class Entity < ModelElement
4
4
  include Identifier
5
5
 
6
- attr_accessor :abstract
7
- attr_accessor :supertype_expression
8
- attr_accessor :subtype_of
9
- attr_accessor :attributes
10
- attr_accessor :unique
11
- attr_accessor :where
12
- attr_accessor :informal_propositions
6
+ model_attr_accessor :abstract
7
+ model_attr_accessor :supertype_expression
8
+ model_attr_accessor :subtype_of
9
+ model_attr_accessor :attributes
10
+ model_attr_accessor :unique
11
+ model_attr_accessor :where
12
+ model_attr_accessor :informal_propositions
13
13
 
14
14
  def initialize(options = {})
15
15
  @id = options[:id]
16
16
  @remarks = options.fetch(:remarks, [])
17
+ @remark_items = options.fetch(:remark_items, [])
17
18
  @source = options[:source]
18
19
 
19
20
  @abstract = options[:abstract]
@@ -28,12 +29,13 @@ module Expressir
28
29
  end
29
30
 
30
31
  def children
31
- items = []
32
- items.push(*@attributes)
33
- items.push(*@unique)
34
- items.push(*@where)
35
- items.push(*@informal_propositions)
36
- items
32
+ [
33
+ *attributes,
34
+ *unique,
35
+ *where,
36
+ *informal_propositions,
37
+ *remark_items
38
+ ]
37
39
  end
38
40
  end
39
41
  end
@@ -6,10 +6,17 @@ module Expressir
6
6
  def initialize(options = {})
7
7
  @id = options[:id]
8
8
  @remarks = options.fetch(:remarks, [])
9
+ @remark_items = options.fetch(:remark_items, [])
9
10
  @source = options[:source]
10
11
 
11
12
  super
12
13
  end
14
+
15
+ def children
16
+ [
17
+ *remark_items
18
+ ]
19
+ end
13
20
  end
14
21
  end
15
22
  end
@@ -2,7 +2,7 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class AggregateInitializer < ModelElement
5
- attr_accessor :items
5
+ model_attr_accessor :items
6
6
 
7
7
  def initialize(options = {})
8
8
  @items = options.fetch(:items, [])
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class AggregateItem < ModelElement
5
- attr_accessor :expression
6
- attr_accessor :repetition
5
+ model_attr_accessor :expression
6
+ model_attr_accessor :repetition
7
7
 
8
8
  def initialize(options = {})
9
9
  @expression = options[:expression]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class AttributeReference < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :attribute
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :attribute
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]
@@ -25,9 +25,9 @@ module Expressir
25
25
  SUBTRACTION = :SUBTRACTION
26
26
  XOR = :XOR
27
27
 
28
- attr_accessor :operator
29
- attr_accessor :operand1
30
- attr_accessor :operand2
28
+ model_attr_accessor :operator
29
+ model_attr_accessor :operand1
30
+ model_attr_accessor :operand2
31
31
 
32
32
  def initialize(options = {})
33
33
  @operator = options[:operator]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class Call < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :parameters
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :parameters
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class EntityConstructor < ModelElement
5
- attr_accessor :entity
6
- attr_accessor :parameters
5
+ model_attr_accessor :entity
6
+ model_attr_accessor :parameters
7
7
 
8
8
  def initialize(options = {})
9
9
  @entity = options[:entity]
@@ -2,8 +2,8 @@ module Expressir
2
2
  module Model
3
3
  module Expressions
4
4
  class GroupReference < ModelElement
5
- attr_accessor :ref
6
- attr_accessor :entity
5
+ model_attr_accessor :ref
6
+ model_attr_accessor :entity
7
7
 
8
8
  def initialize(options = {})
9
9
  @ref = options[:ref]