expressir 0.2.16-x86-mingw32 → 0.2.17-x86-mingw32

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 +51 -13
  3. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  4. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  5. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  6. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  7. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  8. data/lib/expressir/express_exp/formatter.rb +185 -135
  9. data/lib/expressir/express_exp/parser.rb +29 -29
  10. data/lib/expressir/express_exp/schema_head_formatter.rb +1 -4
  11. data/lib/expressir/express_exp/visitor.rb +11 -6
  12. data/lib/expressir/model/entity.rb +6 -6
  13. data/lib/expressir/model/expressions/query_expression.rb +3 -3
  14. data/lib/expressir/model/function.rb +15 -11
  15. data/lib/expressir/model/informal_proposition.rb +4 -1
  16. data/lib/expressir/model/interfaced_item.rb +4 -1
  17. data/lib/expressir/model/model_element.rb +20 -7
  18. data/lib/expressir/model/procedure.rb +15 -11
  19. data/lib/expressir/model/repository.rb +3 -3
  20. data/lib/expressir/model/rule.rb +16 -12
  21. data/lib/expressir/model/schema.rb +52 -45
  22. data/lib/expressir/model/statements/alias.rb +3 -3
  23. data/lib/expressir/model/statements/repeat.rb +3 -3
  24. data/lib/expressir/model/subtype_constraint.rb +1 -6
  25. data/lib/expressir/model/type.rb +9 -5
  26. data/lib/expressir/version.rb +1 -1
  27. data/original/examples/syntax/{hyperlink.exp → multiple.exp} +8 -8
  28. data/original/examples/syntax/multiple.yaml +180 -0
  29. data/original/examples/syntax/multiple_formatted.exp +71 -0
  30. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  31. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  32. data/original/examples/syntax/remark.exp +41 -41
  33. data/original/examples/syntax/remark.yaml +445 -0
  34. data/original/examples/syntax/remark_formatted.exp +62 -50
  35. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  36. data/original/examples/syntax/single.yaml +8 -0
  37. data/original/examples/syntax/single_formatted.exp +6 -0
  38. data/original/examples/syntax/single_formatted.yaml +18 -0
  39. data/original/examples/syntax/syntax.exp +29 -19
  40. data/original/examples/syntax/syntax.yaml +3438 -0
  41. data/original/examples/syntax/syntax_formatted.exp +271 -131
  42. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  43. data/spec/expressir/express_exp/formatter_spec.rb +110 -0
  44. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  45. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +93 -10
  46. metadata +17 -16
  47. data/original/examples/syntax/hyperlink_formatted.exp +0 -51
  48. data/original/examples/syntax/source.exp +0 -16
  49. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  50. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  51. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -28
  52. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -37
  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 -3086
  56. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -40
  57. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -6,54 +6,54 @@ 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{|schema| schema.file = file}
38
38
 
39
- repo
39
+ repository
40
40
  end
41
41
 
42
- def self.from_files(files)
43
- schemas = files.map{|file| self.from_file(file).schemas}.flatten
42
+ def self.from_files(files, options = {})
43
+ schemas = files.each_with_index.map do |file, i|
44
+ # start = Time.now
45
+ repository = self.from_file(file, options)
46
+ # STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}"
47
+ repository.schemas
48
+ end.flatten
44
49
 
45
- repo = Model::Repository.new({
50
+ repository = Model::Repository.new({
46
51
  schemas: schemas
47
52
  })
48
53
 
49
- repo.schemas.each{|schema| schema.parent = repo}
50
-
51
- repo
52
- end
54
+ repository.schemas.each{|schema| schema.parent = repository}
53
55
 
54
- # deprecated
55
- def self.from_exp(file)
56
- self.from_file(file)
56
+ repository
57
57
  end
58
58
  end
59
59
  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
@@ -121,6 +125,7 @@ module Expressir
121
125
  id: informal_proposition_id
122
126
  })
123
127
  target_node.informal_propositions << informal_proposition
128
+ target_node.reset_children_by_id
124
129
  informal_proposition.parent = target_node
125
130
  informal_proposition
126
131
  end
@@ -1925,8 +1930,8 @@ module Expressir
1925
1930
  entities = declarations.select{|x| x.is_a? Model::Entity}
1926
1931
  subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1927
1932
  functions = declarations.select{|x| x.is_a? Model::Function}
1928
- procedures = declarations.select{|x| x.is_a? Model::Procedure}
1929
1933
  rules = declarations.select{|x| x.is_a? Model::Rule}
1934
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1930
1935
 
1931
1936
  Model::Schema.new({
1932
1937
  id: id,
@@ -1937,8 +1942,8 @@ module Expressir
1937
1942
  entities: entities,
1938
1943
  subtype_constraints: subtype_constraints,
1939
1944
  functions: functions,
1940
- procedures: procedures,
1941
- rules: rules
1945
+ rules: rules,
1946
+ procedures: procedures
1942
1947
  })
1943
1948
  end
1944
1949
 
@@ -2149,7 +2154,7 @@ module Expressir
2149
2154
  id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2150
2155
  applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2151
2156
  abstract = ctx__subtype_constraint_body__abstract_supertype && true
2152
- total_over = visit_if(ctx__subtype_constraint_body__total_over)
2157
+ total_over = visit_if(ctx__subtype_constraint_body__total_over, [])
2153
2158
  supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2154
2159
 
2155
2160
  Model::SubtypeConstraint.new({
@@ -28,12 +28,12 @@ module Expressir
28
28
  end
29
29
 
30
30
  def children
31
- items = []
32
- items.push(*@attributes)
33
- items.push(*@unique)
34
- items.push(*@where)
35
- items.push(*@informal_propositions)
36
- items
31
+ [
32
+ *attributes,
33
+ *unique,
34
+ *where,
35
+ *informal_propositions
36
+ ]
37
37
  end
38
38
  end
39
39
  end
@@ -19,9 +19,9 @@ module Expressir
19
19
  end
20
20
 
21
21
  def children
22
- items = []
23
- items.push(self)
24
- items
22
+ [
23
+ self
24
+ ]
25
25
  end
26
26
  end
27
27
  end
@@ -33,18 +33,22 @@ module Expressir
33
33
  super
34
34
  end
35
35
 
36
+ def enumeration_items
37
+ types.flat_map{|x| x.enumeration_items}
38
+ end
39
+
36
40
  def children
37
- items = []
38
- items.push(*@parameters)
39
- items.push(*@types)
40
- items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
41
- items.push(*@entities)
42
- items.push(*@subtype_constraints)
43
- items.push(*@functions)
44
- items.push(*@procedures)
45
- items.push(*@constants)
46
- items.push(*@variables)
47
- items
41
+ [
42
+ *parameters,
43
+ *types,
44
+ *enumeration_items,
45
+ *entities,
46
+ *subtype_constraints,
47
+ *functions,
48
+ *procedures,
49
+ *constants,
50
+ *variables
51
+ ]
48
52
  end
49
53
  end
50
54
  end
@@ -3,10 +3,13 @@ module Expressir
3
3
  class InformalProposition < ModelElement
4
4
  include Identifier
5
5
 
6
+ undef :source
7
+ undef :source=
8
+
6
9
  def initialize(options = {})
7
10
  @id = options[:id]
8
11
  @remarks = options.fetch(:remarks, [])
9
- @source = options[:source]
12
+ # @source = options[:source]
10
13
 
11
14
  super
12
15
  end
@@ -3,12 +3,15 @@ module Expressir
3
3
  class InterfacedItem < ModelElement
4
4
  include Identifier
5
5
 
6
+ undef :source
7
+ undef :source=
8
+
6
9
  attr_accessor :base_item
7
10
 
8
11
  def initialize(options = {})
9
12
  @id = options[:id]
10
13
  @remarks = options.fetch(:remarks, [])
11
- @source = options[:source]
14
+ # @source = options[:source]
12
15
 
13
16
  @base_item = options[:base_item]
14
17
 
@@ -10,6 +10,10 @@ module Expressir
10
10
  attach_parent_to_children
11
11
  end
12
12
 
13
+ def model_instance_variables
14
+ instance_variables.select{|x| x != :@file && x != :@parent && x != :@children_by_id}
15
+ end
16
+
13
17
  def path
14
18
  return id if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression
15
19
 
@@ -28,7 +32,7 @@ module Expressir
28
32
  end
29
33
 
30
34
  def attach_parent_to_children
31
- instance_variables.select{|x| x != :@parent}.each do |variable|
35
+ model_instance_variables.each do |variable|
32
36
  value = instance_variable_get(variable)
33
37
 
34
38
  if value.is_a? Array
@@ -57,7 +61,7 @@ module Expressir
57
61
  # find in current scope
58
62
  current_node = current_scope
59
63
  path_parts.each do |current_path|
60
- current_node = current_node.children.find{|x| x.id and x.id.downcase == current_path}
64
+ current_node = current_node.children_by_id[current_path]
61
65
  break unless current_node
62
66
  end
63
67
  target_node = current_node
@@ -75,19 +79,28 @@ module Expressir
75
79
  []
76
80
  end
77
81
 
82
+ def children_by_id
83
+ @children_by_id ||= children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
84
+ end
85
+
86
+ def reset_children_by_id
87
+ @children_by_id = nil
88
+ end
89
+
78
90
  def to_hash(options = {})
79
- skip_empty = options[:skip_empty]
91
+ include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
80
92
  formatter = options[:formatter]
81
93
 
82
94
  hash = {}
83
95
  hash[CLASS_KEY] = self.class.name
84
96
 
85
- instance_variables.select{|x| x != :@parent}.each_with_object(hash) do |variable, result|
97
+ model_instance_variables.each_with_object(hash) do |variable, result|
86
98
  key = variable.to_s.sub(/^@/, '')
87
99
  value = instance_variable_get(variable)
100
+ empty = value.nil? || (value.is_a?(Array) && value.count == 0)
88
101
 
89
- # skip empty values (nil, empty array)
90
- if !skip_empty or !(value.nil? or (value.is_a? Array and value.count == 0))
102
+ # skip empty values
103
+ if !empty or include_empty
91
104
  result[key] = if value.is_a? Array
92
105
  value.map do |value|
93
106
  if value.is_a? ModelElement
@@ -104,7 +117,7 @@ module Expressir
104
117
  end
105
118
  end
106
119
 
107
- if formatter
120
+ if self.class.method_defined? :source and formatter
108
121
  hash[SOURCE_KEY] = formatter.format(self)
109
122
  end
110
123
 
@@ -31,18 +31,22 @@ module Expressir
31
31
  super
32
32
  end
33
33
 
34
+ def enumeration_items
35
+ types.flat_map{|x| x.enumeration_items}
36
+ end
37
+
34
38
  def children
35
- items = []
36
- items.push(*@parameters)
37
- items.push(*@types)
38
- items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
39
- items.push(*@entities)
40
- items.push(*@subtype_constraints)
41
- items.push(*@functions)
42
- items.push(*@procedures)
43
- items.push(*@constants)
44
- items.push(*@variables)
45
- items
39
+ [
40
+ *parameters,
41
+ *types,
42
+ *enumeration_items,
43
+ *entities,
44
+ *subtype_constraints,
45
+ *functions,
46
+ *procedures,
47
+ *constants,
48
+ *variables
49
+ ]
46
50
  end
47
51
  end
48
52
  end
@@ -10,9 +10,9 @@ module Expressir
10
10
  end
11
11
 
12
12
  def children
13
- items = []
14
- items.push(*@schemas)
15
- items
13
+ [
14
+ *schemas
15
+ ]
16
16
  end
17
17
  end
18
18
  end
@@ -35,19 +35,23 @@ module Expressir
35
35
  super
36
36
  end
37
37
 
38
+ def enumeration_items
39
+ types.flat_map{|x| x.enumeration_items}
40
+ end
41
+
38
42
  def children
39
- items = []
40
- items.push(*@types)
41
- items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
42
- items.push(*@entities)
43
- items.push(*@subtype_constraints)
44
- items.push(*@functions)
45
- items.push(*@procedures)
46
- items.push(*@constants)
47
- items.push(*@variables)
48
- items.push(*@where)
49
- items.push(*@informal_propositions)
50
- items
43
+ [
44
+ *types,
45
+ *enumeration_items,
46
+ *entities,
47
+ *subtype_constraints,
48
+ *functions,
49
+ *procedures,
50
+ *constants,
51
+ *variables,
52
+ *where,
53
+ *informal_propositions
54
+ ]
51
55
  end
52
56
  end
53
57
  end
@@ -12,8 +12,8 @@ module Expressir
12
12
  attr_accessor :entities
13
13
  attr_accessor :subtype_constraints
14
14
  attr_accessor :functions
15
- attr_accessor :procedures
16
15
  attr_accessor :rules
16
+ attr_accessor :procedures
17
17
 
18
18
  def initialize(options = {})
19
19
  @file = options[:file]
@@ -29,60 +29,67 @@ module Expressir
29
29
  @entities = options.fetch(:entities, [])
30
30
  @subtype_constraints = options.fetch(:subtype_constraints, [])
31
31
  @functions = options.fetch(:functions, [])
32
- @procedures = options.fetch(:procedures, [])
33
32
  @rules = options.fetch(:rules, [])
33
+ @procedures = options.fetch(:procedures, [])
34
34
 
35
35
  super
36
36
  end
37
37
 
38
- def children(skip_references = false)
39
- items = []
40
- unless skip_references
41
- items.push(*@interfaces.flat_map do |interface|
42
- schema_id = interface.schema.id.downcase
43
- schema = parent.schemas.find{|x| x.id.downcase == schema_id}
44
- if schema
45
- schema_children = schema.children(true) # prevent infinite recursion
46
- if interface.items.length > 0
47
- interface.items.map do |item|
48
- ref_id = item.ref.id.downcase
49
- id = item.id || ref_id
50
- base_item = schema_children.find{|x| x.id and x.id.downcase == ref_id}
51
-
52
- interfaced_item = InterfacedItem.new({
53
- id: id
54
- })
55
- interfaced_item.base_item = base_item # skip overriding parent
56
- interfaced_item.parent = self
57
- interfaced_item
58
- end
59
- else
60
- schema_children.map do |item|
61
- id = item.id
62
- base_item = item
38
+ def create_interfaced_item(id, base_item)
39
+ interfaced_item = InterfacedItem.new({
40
+ id: id
41
+ })
42
+ interfaced_item.base_item = base_item # skip overriding parent
43
+ interfaced_item.parent = self
44
+ interfaced_item
45
+ end
63
46
 
64
- interfaced_item = InterfacedItem.new({
65
- id: id
66
- })
67
- interfaced_item.base_item = base_item # skip overriding parent
68
- interfaced_item.parent = self
69
- interfaced_item
47
+ def interfaced_items
48
+ interfaces.flat_map do |interface|
49
+ schema = parent.children_by_id[interface.schema.id.downcase]
50
+ if schema
51
+ schema_safe_children = schema.safe_children
52
+ schema_safe_children_by_id = schema_safe_children.select{|x| x.id}.map{|x| [x.id.downcase, x]}.to_h
53
+ if interface.items.length > 0
54
+ interface.items.map do |interface_item|
55
+ base_item = schema_safe_children_by_id[interface_item.ref.id.downcase]
56
+ if base_item
57
+ id = interface_item.id || base_item.id
58
+ create_interfaced_item(id, base_item)
70
59
  end
71
60
  end
72
61
  else
73
- []
62
+ schema_safe_children.map do |base_item|
63
+ id = base_item.id
64
+ create_interfaced_item(id, base_item)
65
+ end
74
66
  end
75
- end)
76
- end
77
- items.push(*@constants)
78
- items.push(*@types)
79
- items.push(*@types.flat_map{|x| x.type.is_a?(Types::Enumeration) ? x.type.items : []})
80
- items.push(*@entities)
81
- items.push(*@subtype_constraints)
82
- items.push(*@functions)
83
- items.push(*@procedures)
84
- items.push(*@rules)
85
- items
67
+ end
68
+ end.select{|x| x}
69
+ end
70
+
71
+ def enumeration_items
72
+ types.flat_map{|x| x.enumeration_items}
73
+ end
74
+
75
+ def safe_children
76
+ [
77
+ *constants,
78
+ *types,
79
+ *enumeration_items,
80
+ *entities,
81
+ *subtype_constraints,
82
+ *functions,
83
+ *rules,
84
+ *procedures
85
+ ]
86
+ end
87
+
88
+ def children
89
+ [
90
+ *interfaced_items,
91
+ *safe_children
92
+ ]
86
93
  end
87
94
  end
88
95
  end