expressir 0.2.12-x64-mingw32 → 0.2.17-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/exe/format +57 -8
  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 +201 -147
  9. data/lib/expressir/express_exp/hyperlink_formatter.rb +6 -4
  10. data/lib/expressir/express_exp/parser.rb +31 -25
  11. data/lib/expressir/express_exp/schema_head_formatter.rb +2 -7
  12. data/lib/expressir/express_exp/visitor.rb +27 -54
  13. data/lib/expressir/model.rb +2 -1
  14. data/lib/expressir/model/entity.rb +6 -6
  15. data/lib/expressir/model/expressions/query_expression.rb +3 -3
  16. data/lib/expressir/model/function.rb +15 -11
  17. data/lib/expressir/model/informal_proposition.rb +4 -1
  18. data/lib/expressir/model/{renamed_ref.rb → interface_item.rb} +2 -2
  19. data/lib/expressir/model/interfaced_item.rb +26 -0
  20. data/lib/expressir/model/model_element.rb +20 -7
  21. data/lib/expressir/model/procedure.rb +15 -11
  22. data/lib/expressir/model/repository.rb +3 -3
  23. data/lib/expressir/model/rule.rb +16 -12
  24. data/lib/expressir/model/schema.rb +60 -17
  25. data/lib/expressir/model/statements/alias.rb +3 -3
  26. data/lib/expressir/model/statements/repeat.rb +3 -3
  27. data/lib/expressir/model/subtype_constraint.rb +1 -6
  28. data/lib/expressir/model/type.rb +9 -5
  29. data/lib/expressir/version.rb +1 -1
  30. data/original/examples/syntax/multiple.exp +23 -0
  31. data/original/examples/syntax/multiple.yaml +180 -0
  32. data/original/examples/syntax/multiple_formatted.exp +71 -0
  33. data/original/examples/syntax/multiple_hyperlink_formatted.exp +71 -0
  34. data/original/examples/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
  35. data/original/examples/syntax/remark.exp +41 -41
  36. data/original/examples/syntax/remark.yaml +445 -0
  37. data/original/examples/syntax/remark_formatted.exp +62 -50
  38. data/original/examples/syntax/{simple.exp → single.exp} +1 -1
  39. data/original/examples/syntax/single.yaml +8 -0
  40. data/original/examples/syntax/single_formatted.exp +6 -0
  41. data/original/examples/syntax/single_formatted.yaml +18 -0
  42. data/original/examples/syntax/syntax.exp +29 -19
  43. data/original/examples/syntax/syntax.yaml +3438 -0
  44. data/original/examples/syntax/syntax_formatted.exp +271 -131
  45. data/original/examples/syntax/syntax_schema_head_formatted.exp +18 -0
  46. data/spec/expressir/express_exp/formatter_spec.rb +110 -0
  47. data/spec/expressir/express_exp/parser_spec.rb +98 -0
  48. data/spec/expressir/model/{model_element/find_spec.rb → model_element_spec.rb} +93 -10
  49. metadata +19 -18
  50. data/original/examples/syntax/hyperlink.exp +0 -8
  51. data/original/examples/syntax/hyperlink_formatted.exp +0 -19
  52. data/original/examples/syntax/source.exp +0 -16
  53. data/spec/expressir/express_exp/formatter/remark_spec.rb +0 -28
  54. data/spec/expressir/express_exp/formatter/syntax_spec.rb +0 -28
  55. data/spec/expressir/express_exp/hyperlink_formatter_spec.rb +0 -24
  56. data/spec/expressir/express_exp/parser/head_source_spec.rb +0 -38
  57. data/spec/expressir/express_exp/parser/multiple_spec.rb +0 -32
  58. data/spec/expressir/express_exp/parser/remark_spec.rb +0 -411
  59. data/spec/expressir/express_exp/parser/source_spec.rb +0 -29
  60. data/spec/expressir/express_exp/parser/syntax_spec.rb +0 -3080
  61. data/spec/expressir/express_exp/schema_head_formatter_spec.rb +0 -36
  62. data/spec/expressir/model/model_element/hash_spec.rb +0 -66
@@ -1,13 +1,15 @@
1
- require "expressir/express_exp/formatter"
2
-
3
1
  module Expressir
4
2
  module ExpressExp
5
- class HyperlinkFormatter < Formatter
3
+ module HyperlinkFormatter
6
4
  def format_expressions_simple_reference(node)
7
5
  return node.id if node.parent.is_a? Model::Expressions::AttributeReference
8
6
 
9
7
  # skip hyperlink if target node can't be found
10
- target_node = node.find(node.id)
8
+ target_node = if node.parent.is_a? Model::InterfaceItem
9
+ node.find("#{node.parent.parent.schema.id}.#{node.parent.ref.id}")
10
+ else
11
+ node.find(node.id)
12
+ end
11
13
  return node.id unless target_node
12
14
 
13
15
  # skip hyperlink for implicit scopes
@@ -6,48 +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
37
+ repository.schemas.each{|schema| schema.file = file}
38
+
39
+ repository
38
40
  end
39
41
 
40
- def self.from_files(files)
41
- 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
42
49
 
43
- Model::Repository.new({
50
+ repository = Model::Repository.new({
44
51
  schemas: schemas
45
52
  })
46
- end
47
53
 
48
- # deprecated
49
- def self.from_exp(file)
50
- self.from_file(file)
54
+ repository.schemas.each{|schema| schema.parent = repository}
55
+
56
+ repository
51
57
  end
52
58
  end
53
59
  end
@@ -1,13 +1,8 @@
1
- require "expressir/express_exp/formatter"
2
-
3
1
  module Expressir
4
2
  module ExpressExp
5
- class SchemaHeadFormatter < Formatter
3
+ module SchemaHeadFormatter
6
4
  def format_schema(node)
7
- [
8
- "SCHEMA #{node.id}#{node.version ? " #{format(node.version)}" : ""};",
9
- *node.interfaces.map{|x| format(x)}
10
- ].join("\n")
5
+ format_schema_head(node)
11
6
  end
12
7
  end
13
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
@@ -92,35 +96,11 @@ module Expressir
92
96
  @tokens[start_index..stop_index]
93
97
  end
94
98
 
95
- def get_head_tokens(ctx)
96
- start_index, stop_index = if ctx.is_a? ::ExpressParser::SchemaDeclContext
97
- start_index = ctx.start.token_index
98
- stop_index = if ctx.schema_body.interface_specification.length > 0
99
- ctx.schema_body.interface_specification.last.stop.token_index
100
- elsif ctx.schema_version_id
101
- ctx.schema_version_id.stop.token_index + 1
102
- else
103
- ctx.schema_id.stop.token_index + 1
104
- end
105
-
106
- [start_index, stop_index]
107
- end
108
-
109
- if start_index and stop_index
110
- @tokens[start_index..stop_index]
111
- end
112
- end
113
-
114
99
  def attach_source(ctx, node)
115
100
  if node.class.method_defined? :source
116
101
  tokens = get_tokens(ctx)
117
102
  node.source = get_tokens_source(tokens)
118
103
  end
119
-
120
- if node.class.method_defined? :head_source
121
- tokens = get_head_tokens(ctx)
122
- node.head_source = get_tokens_source(tokens)
123
- end
124
104
  end
125
105
 
126
106
  def find_remark_target(node, path)
@@ -145,6 +125,7 @@ module Expressir
145
125
  id: informal_proposition_id
146
126
  })
147
127
  target_node.informal_propositions << informal_proposition
128
+ target_node.reset_children_by_id
148
129
  informal_proposition.parent = target_node
149
130
  informal_proposition
150
131
  end
@@ -691,9 +672,9 @@ module Expressir
691
672
  expression = visit_if(ctx__expression)
692
673
 
693
674
  Model::Attribute.new({
694
- id: attribute.id,
675
+ id: attribute.id, # reuse
695
676
  kind: Model::Attribute::DERIVED,
696
- supertype_attribute: attribute.supertype_attribute,
677
+ supertype_attribute: attribute.supertype_attribute, # reuse
697
678
  type: type,
698
679
  expression: expression
699
680
  })
@@ -879,9 +860,9 @@ module Expressir
879
860
 
880
861
  attributes.map do |attribute|
881
862
  Model::Attribute.new({
882
- id: attribute.id,
863
+ id: attribute.id, # reuse
883
864
  kind: Model::Attribute::EXPLICIT,
884
- supertype_attribute: attribute.supertype_attribute,
865
+ supertype_attribute: attribute.supertype_attribute, # reuse
885
866
  optional: optional,
886
867
  type: type
887
868
  })
@@ -1306,9 +1287,9 @@ module Expressir
1306
1287
  end
1307
1288
 
1308
1289
  Model::Attribute.new({
1309
- id: attribute.id,
1290
+ id: attribute.id, # reuse
1310
1291
  kind: Model::Attribute::INVERSE,
1311
- supertype_attribute: attribute.supertype_attribute,
1292
+ supertype_attribute: attribute.supertype_attribute, # reuse
1312
1293
  type: type,
1313
1294
  expression: expression
1314
1295
  })
@@ -1490,14 +1471,10 @@ module Expressir
1490
1471
  ref = visit_if(ctx__named_types)
1491
1472
  id = visit_if(ctx__entity_id || ctx__type_id)
1492
1473
 
1493
- if id
1494
- Model::RenamedRef.new({
1495
- ref: ref,
1496
- id: id
1497
- })
1498
- else
1499
- ref
1500
- end
1474
+ Model::InterfaceItem.new({
1475
+ ref: ref,
1476
+ id: id
1477
+ })
1501
1478
  end
1502
1479
 
1503
1480
  def visit_null_stmt(ctx)
@@ -1674,9 +1651,9 @@ module Expressir
1674
1651
  ref: Model::Expressions::SimpleReference.new({
1675
1652
  id: id
1676
1653
  }),
1677
- entity: group_reference.entity
1654
+ entity: group_reference.entity # reuse
1678
1655
  }),
1679
- attribute: attribute_reference.attribute
1656
+ attribute: attribute_reference.attribute # reuse
1680
1657
  })
1681
1658
  end
1682
1659
 
@@ -1844,14 +1821,10 @@ module Expressir
1844
1821
  ref = visit_if(ctx__resource_ref)
1845
1822
  id = visit_if(ctx__rename_id)
1846
1823
 
1847
- if id
1848
- Model::RenamedRef.new({
1849
- ref: ref,
1850
- id: id
1851
- })
1852
- else
1853
- ref
1854
- end
1824
+ Model::InterfaceItem.new({
1825
+ ref: ref,
1826
+ id: id
1827
+ })
1855
1828
  end
1856
1829
 
1857
1830
  def visit_resource_ref(ctx)
@@ -1957,8 +1930,8 @@ module Expressir
1957
1930
  entities = declarations.select{|x| x.is_a? Model::Entity}
1958
1931
  subtype_constraints = declarations.select{|x| x.is_a? Model::SubtypeConstraint}
1959
1932
  functions = declarations.select{|x| x.is_a? Model::Function}
1960
- procedures = declarations.select{|x| x.is_a? Model::Procedure}
1961
1933
  rules = declarations.select{|x| x.is_a? Model::Rule}
1934
+ procedures = declarations.select{|x| x.is_a? Model::Procedure}
1962
1935
 
1963
1936
  Model::Schema.new({
1964
1937
  id: id,
@@ -1969,8 +1942,8 @@ module Expressir
1969
1942
  entities: entities,
1970
1943
  subtype_constraints: subtype_constraints,
1971
1944
  functions: functions,
1972
- procedures: procedures,
1973
- rules: rules
1945
+ rules: rules,
1946
+ procedures: procedures
1974
1947
  })
1975
1948
  end
1976
1949
 
@@ -2181,7 +2154,7 @@ module Expressir
2181
2154
  id = visit_if(ctx__subtype_constraint_head__subtype_constraint_id)
2182
2155
  applies_to = visit_if(ctx__subtype_constraint_head__entity_ref)
2183
2156
  abstract = ctx__subtype_constraint_body__abstract_supertype && true
2184
- total_over = visit_if(ctx__subtype_constraint_body__total_over)
2157
+ total_over = visit_if(ctx__subtype_constraint_body__total_over, [])
2185
2158
  supertype_expression = visit_if(ctx__subtype_constraint_body__supertype_expression)
2186
2159
 
2187
2160
  Model::SubtypeConstraint.new({
@@ -9,9 +9,10 @@ require 'expressir/model/enumeration_item'
9
9
  require 'expressir/model/function'
10
10
  require 'expressir/model/informal_proposition'
11
11
  require 'expressir/model/interface'
12
+ require 'expressir/model/interface_item'
13
+ require 'expressir/model/interfaced_item'
12
14
  require 'expressir/model/parameter'
13
15
  require 'expressir/model/procedure'
14
- require 'expressir/model/renamed_ref'
15
16
  require 'expressir/model/repository'
16
17
  require 'expressir/model/rule'
17
18
  require 'expressir/model/schema'
@@ -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?(Expressir::Model::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
@@ -1,11 +1,11 @@
1
1
  module Expressir
2
2
  module Model
3
- class RenamedRef < ModelElement
3
+ class InterfaceItem < ModelElement
4
4
  attr_accessor :ref
5
5
  attr_accessor :id
6
6
 
7
7
  def initialize(options = {})
8
- @ref = options[:ref]
8
+ @ref = options[:ref]
9
9
  @id = options[:id]
10
10
 
11
11
  super
@@ -0,0 +1,26 @@
1
+ module Expressir
2
+ module Model
3
+ class InterfacedItem < ModelElement
4
+ include Identifier
5
+
6
+ undef :source
7
+ undef :source=
8
+
9
+ attr_accessor :base_item
10
+
11
+ def initialize(options = {})
12
+ @id = options[:id]
13
+ @remarks = options.fetch(:remarks, [])
14
+ # @source = options[:source]
15
+
16
+ @base_item = options[:base_item]
17
+
18
+ super
19
+ end
20
+
21
+ def path
22
+ base_item.path
23
+ end
24
+ end
25
+ end
26
+ end
@@ -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