expressir 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/lib/expressir/express_exp/formatter.rb +1444 -0
  4. data/lib/expressir/express_exp/visitor.rb +288 -280
  5. data/lib/expressir/model.rb +13 -42
  6. data/lib/expressir/model/{derived.rb → attribute.rb} +13 -4
  7. data/lib/expressir/model/constant.rb +2 -1
  8. data/lib/expressir/model/entity.rb +22 -17
  9. data/lib/expressir/model/enumeration_item.rb +2 -1
  10. data/lib/expressir/model/expressions/aggregate_initializer.rb +9 -9
  11. data/lib/expressir/model/expressions/aggregate_item.rb +15 -0
  12. data/lib/expressir/model/expressions/{attribute_qualifier.rb → attribute_reference.rb} +3 -1
  13. data/lib/expressir/model/expressions/binary_expression.rb +40 -0
  14. data/lib/expressir/model/expressions/{function_call.rb → call.rb} +3 -3
  15. data/lib/expressir/model/expressions/entity_constructor.rb +11 -11
  16. data/lib/expressir/model/expressions/{group_qualifier.rb → group_reference.rb} +3 -1
  17. data/lib/expressir/model/expressions/{index_qualifier.rb → index_reference.rb} +3 -1
  18. data/lib/expressir/model/expressions/interval.rb +17 -17
  19. data/lib/expressir/model/expressions/query_expression.rb +26 -0
  20. data/lib/expressir/model/expressions/simple_reference.rb +13 -0
  21. data/lib/expressir/model/expressions/{expression.rb → unary_expression.rb} +7 -3
  22. data/lib/expressir/model/function.rb +14 -6
  23. data/lib/expressir/model/{reference.rb → interface.rb} +6 -1
  24. data/lib/expressir/model/literals/logical.rb +4 -0
  25. data/lib/expressir/model/parameter.rb +4 -3
  26. data/lib/expressir/model/procedure.rb +14 -6
  27. data/lib/expressir/model/repository.rb +1 -1
  28. data/lib/expressir/model/rule.rb +16 -8
  29. data/lib/expressir/model/schema.rb +22 -6
  30. data/lib/expressir/model/statements/alias.rb +3 -2
  31. data/lib/expressir/model/statements/{procedure_call.rb → call.rb} +3 -3
  32. data/lib/expressir/model/statements/case.rb +2 -2
  33. data/lib/expressir/model/statements/case_action.rb +2 -2
  34. data/lib/expressir/model/statements/repeat.rb +3 -2
  35. data/lib/expressir/model/subtype_constraint.rb +6 -5
  36. data/lib/expressir/model/type.rb +3 -2
  37. data/lib/expressir/model/types/aggregate.rb +2 -1
  38. data/lib/expressir/model/types/generic.rb +2 -1
  39. data/lib/expressir/model/types/generic_entity.rb +2 -1
  40. data/lib/expressir/model/unique.rb +2 -1
  41. data/lib/expressir/model/{local.rb → variable.rb} +3 -2
  42. data/lib/expressir/model/where.rb +2 -1
  43. data/lib/expressir/version.rb +1 -1
  44. data/original/examples/syntax/remark.exp +126 -108
  45. data/original/examples/syntax/remark_formatted.exp +172 -0
  46. data/original/examples/syntax/syntax.exp +287 -277
  47. data/original/examples/syntax/syntax_formatted.exp +1176 -0
  48. data/spec/expressir/express_exp/format_remark_spec.rb +28 -0
  49. data/spec/expressir/express_exp/format_syntax_spec.rb +28 -0
  50. data/spec/expressir/express_exp/{remark_spec.rb → parse_remark_spec.rb} +80 -36
  51. data/spec/expressir/express_exp/parse_syntax_spec.rb +2998 -0
  52. metadata +22 -46
  53. data/lib/expressir/model/explicit.rb +0 -19
  54. data/lib/expressir/model/expressions/aggregate_element.rb +0 -15
  55. data/lib/expressir/model/expressions/qualified_ref.rb +0 -15
  56. data/lib/expressir/model/expressions/query.rb +0 -25
  57. data/lib/expressir/model/inverse.rb +0 -19
  58. data/lib/expressir/model/operators/addition.rb +0 -8
  59. data/lib/expressir/model/operators/and.rb +0 -8
  60. data/lib/expressir/model/operators/andor.rb +0 -8
  61. data/lib/expressir/model/operators/combine.rb +0 -8
  62. data/lib/expressir/model/operators/equal.rb +0 -8
  63. data/lib/expressir/model/operators/exponentiation.rb +0 -8
  64. data/lib/expressir/model/operators/greater_than.rb +0 -8
  65. data/lib/expressir/model/operators/greater_than_or_equal.rb +0 -8
  66. data/lib/expressir/model/operators/in.rb +0 -8
  67. data/lib/expressir/model/operators/instance_equal.rb +0 -8
  68. data/lib/expressir/model/operators/instance_not_equal.rb +0 -8
  69. data/lib/expressir/model/operators/integer_division.rb +0 -8
  70. data/lib/expressir/model/operators/less_than.rb +0 -8
  71. data/lib/expressir/model/operators/less_than_or_equal.rb +0 -8
  72. data/lib/expressir/model/operators/like.rb +0 -8
  73. data/lib/expressir/model/operators/modulo.rb +0 -8
  74. data/lib/expressir/model/operators/multiplication.rb +0 -8
  75. data/lib/expressir/model/operators/not.rb +0 -8
  76. data/lib/expressir/model/operators/not_equal.rb +0 -8
  77. data/lib/expressir/model/operators/oneof.rb +0 -8
  78. data/lib/expressir/model/operators/or.rb +0 -8
  79. data/lib/expressir/model/operators/real_division.rb +0 -8
  80. data/lib/expressir/model/operators/subtraction.rb +0 -8
  81. data/lib/expressir/model/operators/unary_minus.rb +0 -8
  82. data/lib/expressir/model/operators/unary_plus.rb +0 -8
  83. data/lib/expressir/model/operators/xor.rb +0 -8
  84. data/lib/expressir/model/ref.rb +0 -11
  85. data/lib/expressir/model/use.rb +0 -13
  86. data/spec/expressir/express_exp/syntax_spec.rb +0 -2992
@@ -0,0 +1,13 @@
1
+ module Expressir
2
+ module Model
3
+ module Expressions
4
+ class SimpleReference
5
+ attr_accessor :id
6
+
7
+ def initialize(options = {})
8
+ @id = options[:id]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,13 +1,17 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Expressions
4
- class Expression
4
+ class UnaryExpression
5
+ MINUS = :MINUS
6
+ NOT = :NOT
7
+ PLUS = :PLUS
8
+
5
9
  attr_accessor :operator
6
- attr_accessor :operands
10
+ attr_accessor :operand
7
11
 
8
12
  def initialize(options = {})
9
13
  @operator = options[:operator]
10
- @operands = options[:operands]
14
+ @operand = options[:operand]
11
15
  end
12
16
  end
13
17
  end
@@ -6,8 +6,10 @@ module Expressir
6
6
  attr_accessor :return_type
7
7
  attr_accessor :declarations
8
8
  attr_accessor :constants
9
- attr_accessor :locals
9
+ attr_accessor :variables
10
10
  attr_accessor :statements
11
+
12
+ attr_accessor :parent
11
13
  attr_accessor :remarks
12
14
 
13
15
  def initialize(options = {})
@@ -16,9 +18,8 @@ module Expressir
16
18
  @return_type = options[:return_type]
17
19
  @declarations = options[:declarations]
18
20
  @constants = options[:constants]
19
- @locals = options[:locals]
21
+ @variables = options[:variables]
20
22
  @statements = options[:statements]
21
- @remarks = options[:remarks]
22
23
  end
23
24
 
24
25
  def types
@@ -41,12 +42,19 @@ module Expressir
41
42
  @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
42
43
  end
43
44
 
44
- def scope_items
45
+ def children
45
46
  items = []
46
47
  items.push(*@parameters) if @parameters
47
- items.push(*@declarations) if @declarations
48
+ items.push(*@declarations.flat_map do |x|
49
+ [
50
+ x,
51
+ *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
52
+ x.type.items
53
+ end
54
+ ]
55
+ end) if @declarations
48
56
  items.push(*@constants) if @constants
49
- items.push(*@locals) if @locals
57
+ items.push(*@variables) if @variables
50
58
  items
51
59
  end
52
60
  end
@@ -1,10 +1,15 @@
1
1
  module Expressir
2
2
  module Model
3
- class Reference
3
+ class Interface
4
+ USE = :USE
5
+ REFERENCE = :REFERENCE
6
+
7
+ attr_accessor :kind
4
8
  attr_accessor :schema
5
9
  attr_accessor :items
6
10
 
7
11
  def initialize(options = {})
12
+ @kind = options[:kind]
8
13
  @schema = options[:schema]
9
14
  @items = options[:items]
10
15
  end
@@ -2,6 +2,10 @@ module Expressir
2
2
  module Model
3
3
  module Literals
4
4
  class Logical
5
+ TRUE = :TRUE
6
+ FALSE = :FALSE
7
+ UNKNOWN = :UNKNOWN
8
+
5
9
  attr_accessor :value
6
10
 
7
11
  def initialize(options = {})
@@ -1,16 +1,17 @@
1
1
  module Expressir
2
2
  module Model
3
3
  class Parameter
4
+ attr_accessor :var
4
5
  attr_accessor :id
5
6
  attr_accessor :type
6
- attr_accessor :var
7
+
8
+ attr_accessor :parent
7
9
  attr_accessor :remarks
8
10
 
9
11
  def initialize(options = {})
12
+ @var = options[:var]
10
13
  @id = options[:id]
11
14
  @type = options[:type]
12
- @var = options[:var]
13
- @remarks = options[:remarks]
14
15
  end
15
16
  end
16
17
  end
@@ -5,8 +5,10 @@ module Expressir
5
5
  attr_accessor :parameters
6
6
  attr_accessor :declarations
7
7
  attr_accessor :constants
8
- attr_accessor :locals
8
+ attr_accessor :variables
9
9
  attr_accessor :statements
10
+
11
+ attr_accessor :parent
10
12
  attr_accessor :remarks
11
13
 
12
14
  def initialize(options = {})
@@ -14,9 +16,8 @@ module Expressir
14
16
  @parameters = options[:parameters]
15
17
  @declarations = options[:declarations]
16
18
  @constants = options[:constants]
17
- @locals = options[:locals]
19
+ @variables = options[:variables]
18
20
  @statements = options[:statements]
19
- @remarks = options[:remarks]
20
21
  end
21
22
 
22
23
  def types
@@ -39,12 +40,19 @@ module Expressir
39
40
  @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
40
41
  end
41
42
 
42
- def scope_items
43
+ def children
43
44
  items = []
44
45
  items.push(*@parameters) if @parameters
45
- items.push(*@declarations) if @declarations
46
+ items.push(*@declarations.flat_map do |x|
47
+ [
48
+ x,
49
+ *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
50
+ x.type.items
51
+ end
52
+ ]
53
+ end) if @declarations
46
54
  items.push(*@constants) if @constants
47
- items.push(*@locals) if @locals
55
+ items.push(*@variables) if @variables
48
56
  items
49
57
  end
50
58
  end
@@ -7,7 +7,7 @@ module Expressir
7
7
  @schemas = options[:schemas]
8
8
  end
9
9
 
10
- def scope_items
10
+ def children
11
11
  items = []
12
12
  items.push(*@schemas) if @schemas
13
13
  items
@@ -5,9 +5,11 @@ module Expressir
5
5
  attr_accessor :applies_to
6
6
  attr_accessor :declarations
7
7
  attr_accessor :constants
8
- attr_accessor :locals
9
- attr_accessor :where
8
+ attr_accessor :variables
10
9
  attr_accessor :statements
10
+ attr_accessor :where
11
+
12
+ attr_accessor :parent
11
13
  attr_accessor :remarks
12
14
 
13
15
  def initialize(options = {})
@@ -15,10 +17,9 @@ module Expressir
15
17
  @applies_to = options[:applies_to]
16
18
  @declarations = options[:declarations]
17
19
  @constants = options[:constants]
18
- @locals = options[:locals]
19
- @where = options[:where]
20
+ @variables = options[:variables]
20
21
  @statements = options[:statements]
21
- @remarks = options[:remarks]
22
+ @where = options[:where]
22
23
  end
23
24
 
24
25
  def types
@@ -41,11 +42,18 @@ module Expressir
41
42
  @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
42
43
  end
43
44
 
44
- def scope_items
45
+ def children
45
46
  items = []
46
- items.push(*@declarations) if @declarations
47
+ items.push(*@declarations.flat_map do |x|
48
+ [
49
+ x,
50
+ *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
51
+ x.type.items
52
+ end
53
+ ]
54
+ end) if @declarations
47
55
  items.push(*@constants) if @constants
48
- items.push(*@locals) if @locals
56
+ items.push(*@variables) if @variables
49
57
  items.push(*@where) if @where
50
58
  items
51
59
  end
@@ -6,7 +6,7 @@ module Expressir
6
6
  attr_accessor :interfaces
7
7
  attr_accessor :constants
8
8
  attr_accessor :declarations
9
- attr_accessor :rules
9
+
10
10
  attr_accessor :remarks
11
11
 
12
12
  def initialize(options = {})
@@ -15,8 +15,14 @@ module Expressir
15
15
  @interfaces = options[:interfaces]
16
16
  @constants = options[:constants]
17
17
  @declarations = options[:declarations]
18
- @rules = options[:rules]
19
- @remarks = options[:remarks]
18
+ end
19
+
20
+ def use_interfaces
21
+ @interfaces.select{|x| x.kind == Expressir::Model::Interface::USE}
22
+ end
23
+
24
+ def reference_interfaces
25
+ @interfaces.select{|x| x.kind == Expressir::Model::Interface::REFERENCE}
20
26
  end
21
27
 
22
28
  def types
@@ -39,11 +45,21 @@ module Expressir
39
45
  @declarations.select{|x| x.instance_of? Expressir::Model::Procedure}
40
46
  end
41
47
 
42
- def scope_items
48
+ def rules
49
+ @declarations.select{|x| x.instance_of? Expressir::Model::Rule}
50
+ end
51
+
52
+ def children
43
53
  items = []
44
54
  items.push(*@constants) if @constants
45
- items.push(*@declarations) if @declarations
46
- items.push(*@rules) if @rules
55
+ items.push(*@declarations.flat_map do |x|
56
+ [
57
+ x,
58
+ *if x.instance_of? Expressir::Model::Type and x.type.instance_of? Expressir::Model::Types::Enumeration
59
+ x.type.items
60
+ end
61
+ ]
62
+ end) if @declarations
47
63
  items
48
64
  end
49
65
  end
@@ -5,16 +5,17 @@ module Expressir
5
5
  attr_accessor :id
6
6
  attr_accessor :expression
7
7
  attr_accessor :statements
8
+
9
+ attr_accessor :parent
8
10
  attr_accessor :remarks
9
11
 
10
12
  def initialize(options = {})
11
13
  @id = options[:id]
12
14
  @expression = options[:expression]
13
15
  @statements = options[:statements]
14
- @remarks = options[:remarks]
15
16
  end
16
17
 
17
- def scope_items
18
+ def children
18
19
  items = []
19
20
  items.push(self)
20
21
  items
@@ -1,12 +1,12 @@
1
1
  module Expressir
2
2
  module Model
3
3
  module Statements
4
- class ProcedureCall
5
- attr_accessor :procedure
4
+ class Call
5
+ attr_accessor :ref
6
6
  attr_accessor :parameters
7
7
 
8
8
  def initialize(options = {})
9
- @procedure = options[:procedure]
9
+ @ref = options[:ref]
10
10
  @parameters = options[:parameters]
11
11
  end
12
12
  end
@@ -2,12 +2,12 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class Case
5
- attr_accessor :selector
5
+ attr_accessor :expression
6
6
  attr_accessor :actions
7
7
  attr_accessor :otherwise_statement
8
8
 
9
9
  def initialize(options = {})
10
- @selector = options[:selector]
10
+ @expression = options[:expression]
11
11
  @actions = options[:actions]
12
12
  @otherwise_statement = options[:otherwise_statement]
13
13
  end
@@ -2,11 +2,11 @@ module Expressir
2
2
  module Model
3
3
  module Statements
4
4
  class CaseAction
5
- attr_accessor :expression
5
+ attr_accessor :labels
6
6
  attr_accessor :statement
7
7
 
8
8
  def initialize(options = {})
9
- @expression = options[:expression]
9
+ @labels = options[:labels]
10
10
  @statement = options[:statement]
11
11
  end
12
12
  end
@@ -9,6 +9,8 @@ module Expressir
9
9
  attr_accessor :while_expression
10
10
  attr_accessor :until_expression
11
11
  attr_accessor :statements
12
+
13
+ attr_accessor :parent
12
14
  attr_accessor :remarks
13
15
 
14
16
  def initialize(options = {})
@@ -19,10 +21,9 @@ module Expressir
19
21
  @while_expression = options[:while_expression]
20
22
  @until_expression = options[:until_expression]
21
23
  @statements = options[:statements]
22
- @remarks = options[:remarks]
23
24
  end
24
25
 
25
- def scope_items
26
+ def children
26
27
  items = []
27
28
  items.push(self)
28
29
  items
@@ -3,18 +3,19 @@ module Expressir
3
3
  class SubtypeConstraint
4
4
  attr_accessor :id
5
5
  attr_accessor :applies_to
6
- attr_accessor :abstract_supertype
6
+ attr_accessor :abstract
7
7
  attr_accessor :total_over
8
- attr_accessor :subtype_expression
8
+ attr_accessor :supertype_expression
9
+
10
+ attr_accessor :parent
9
11
  attr_accessor :remarks
10
12
 
11
13
  def initialize(options = {})
12
14
  @id = options[:id]
13
15
  @applies_to = options[:applies_to]
14
- @abstract_supertype = options[:abstract_supertype]
16
+ @abstract = options[:abstract]
15
17
  @total_over = options[:total_over]
16
- @subtype_expression = options[:subtype_expression]
17
- @remarks = options[:remarks]
18
+ @supertype_expression = options[:supertype_expression]
18
19
  end
19
20
  end
20
21
  end
@@ -4,16 +4,17 @@ module Expressir
4
4
  attr_accessor :id
5
5
  attr_accessor :type
6
6
  attr_accessor :where
7
+
8
+ attr_accessor :parent
7
9
  attr_accessor :remarks
8
10
 
9
11
  def initialize(options = {})
10
12
  @id = options[:id]
11
13
  @type = options[:type]
12
14
  @where = options[:where]
13
- @remarks = options[:remarks]
14
15
  end
15
16
 
16
- def scope_items
17
+ def children
17
18
  items = []
18
19
  items.push(*@where) if @where
19
20
  items
@@ -4,12 +4,13 @@ module Expressir
4
4
  class Aggregate
5
5
  attr_accessor :label
6
6
  attr_accessor :base_type
7
+
8
+ attr_accessor :parent
7
9
  attr_accessor :remarks
8
10
 
9
11
  def initialize(options = {})
10
12
  @label = options[:label]
11
13
  @base_type = options[:base_type]
12
- @remarks = options[:remarks]
13
14
  end
14
15
  end
15
16
  end
@@ -3,11 +3,12 @@ module Expressir
3
3
  module Types
4
4
  class Generic
5
5
  attr_accessor :label
6
+
7
+ attr_accessor :parent
6
8
  attr_accessor :remarks
7
9
 
8
10
  def initialize(options = {})
9
11
  @label = options[:label]
10
- @remarks = options[:remarks]
11
12
  end
12
13
  end
13
14
  end