expressir 0.2.18 → 0.2.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41cb6219857821852f9629bfdabcfa181bf3109314a5961153c0290b7b413669
4
- data.tar.gz: 308cd06531ebc38203baf045d5ecaaf94d96bde14292646394fe8f8849eb9347
3
+ metadata.gz: d0941aedab1c61bc2eee8ca208e845673189c8d59ebb035e423fcb7986101396
4
+ data.tar.gz: 78f544c82051037b4fb79edeb1bec8b3f5d2a0eff9f2fdf0e44f8e0c50f039ee
5
5
  SHA512:
6
- metadata.gz: 78650bc9fd389ba9fed9611ffe7a7cea6c233311a441636b40b7f711dea54f7b0db38780db9f3d2b4156544051ed583ecf0cdaea28e3922b6b92cc71c4118ebf
7
- data.tar.gz: bfd7c87e009ee9b37f6df558754005bbe2905d48b914c02af23f06ff7b7307d7e3f9c46f9b436033937ad7c9fd28f769aefdf176bc655d5c5bd3d48e5f0c6a46
6
+ metadata.gz: '099aec57848aaee350f656e2e10416080e3d38edde09329bee8919f5ef4b0ab6a96fffdd259e8bf3b284b3c66a58144ea0b213e91ffb89f074e82d1389969637'
7
+ data.tar.gz: a8aa76b048c4957a100d893718bd9558e3dec2a162b83be78385cc271e39fa2997b767d41922f5638bd75a20a565d59dbd742c79fe7a35a9ff2853c0de386e0b
@@ -43,3 +43,8 @@ jobs:
43
43
  - run: bundle exec rake compile
44
44
 
45
45
  - run: bundle exec rake
46
+
47
+ - uses: actions/upload-artifact@v2
48
+ with:
49
+ name: express_parser-${{ matrix.os }}-${{ matrix.ruby }}
50
+ path: lib/expressir/express_exp/express_parser.so
@@ -37,6 +37,8 @@ if cross_build
37
37
  if RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
38
38
  # workaround for 'w64-mingw32-as: express_parser.o: too many sections'
39
39
  $CXXFLAGS << " -O3 -Wa,-mbig-obj"
40
+ # workaround for LoadError: 127: The specified procedure could not be found.
41
+ $DLDFLAGS << " -static -static-libgcc -static-libstdc++"
40
42
  end
41
43
  else
42
44
  require 'mkmf-rice'
@@ -5,7 +5,6 @@ rescue LoadError
5
5
  require_relative "express_parser"
6
6
  end
7
7
  require 'expressir/express_exp/visitor'
8
- require 'pathname'
9
8
 
10
9
  =begin
11
10
  char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
@@ -26,8 +25,6 @@ module Expressir
26
25
  module ExpressExp
27
26
  class Parser
28
27
  def self.from_file(file, options = {})
29
- root_path = options[:root_path]
30
-
31
28
  input = File.read(file)
32
29
 
33
30
  parser = ::ExpressParser::Parser.parse(input)
@@ -38,7 +35,7 @@ module Expressir
38
35
  repository = visitor.visit(parse_tree)
39
36
 
40
37
  repository.schemas.each do |schema|
41
- schema.file = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : File.basename(file)
38
+ schema.file = file.to_s
42
39
  end
43
40
 
44
41
  repository
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module Expressir
2
4
  module Model
3
5
  class ModelElement
@@ -99,17 +101,17 @@ module Expressir
99
101
  hash = {}
100
102
  hash[CLASS_KEY] = self.class.name
101
103
  if self.is_a? Schema and file
102
- hash[FILE_KEY] = root_path ? File.expand_path("#{root_path}/#{file}") : file
104
+ hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file
103
105
  end
104
106
 
105
- model_instance_variables.each_with_object(hash) do |variable, result|
107
+ model_instance_variables.each do |variable|
106
108
  key = variable.to_s.sub(/^@/, '')
107
109
  value = instance_variable_get(variable)
108
110
  empty = value.nil? || (value.is_a?(Array) && value.count == 0)
109
111
 
110
112
  # skip empty values
111
113
  if !empty or include_empty
112
- result[key] = if value.is_a? Array
114
+ hash[key] = if value.is_a? Array
113
115
  value.map do |value|
114
116
  if value.is_a? ModelElement
115
117
  value.to_hash(options)
@@ -132,21 +134,28 @@ module Expressir
132
134
  hash
133
135
  end
134
136
 
135
- def self.from_hash(hash)
137
+ def self.from_hash(hash, options = {})
138
+ root_path = options[:root_path]
139
+
136
140
  node_class = hash[CLASS_KEY]
137
- node_options = hash.select{|x| x != CLASS_KEY}.each_with_object({}) do |(variable, value), result|
141
+ node_options = {}
142
+ if node_class == 'Expressir::Model::Schema' and hash[FILE_KEY]
143
+ node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY]
144
+ end
145
+
146
+ hash.select{|x| x != CLASS_KEY && x != FILE_KEY}.each do |variable, value|
138
147
  key = variable.to_sym
139
148
 
140
- result[key] = if value.is_a? Array
149
+ node_options[key] = if value.is_a? Array
141
150
  value.map do |value|
142
151
  if value.is_a? Hash
143
- self.from_hash(value)
152
+ self.from_hash(value, options)
144
153
  else
145
154
  value
146
155
  end
147
156
  end
148
157
  elsif value.is_a? Hash
149
- self.from_hash(value)
158
+ self.from_hash(value, options)
150
159
  else
151
160
  value
152
161
  end
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "0.2.18".freeze
2
+ VERSION = "0.2.19".freeze
3
3
  end
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: multiple.exp
5
+ file: original/examples/syntax/multiple.exp
6
6
  id: multiple_schema1
7
7
  interfaces:
8
8
  - _class: Expressir::Model::Interface
@@ -147,7 +147,7 @@ schemas:
147
147
  - _class: Expressir::Model::Expressions::SimpleReference
148
148
  id: missing_entity
149
149
  - _class: Expressir::Model::Schema
150
- file: multiple.exp
150
+ file: original/examples/syntax/multiple.exp
151
151
  id: multiple_schema2
152
152
  entities:
153
153
  - _class: Expressir::Model::Entity
@@ -159,7 +159,7 @@ schemas:
159
159
  type:
160
160
  _class: Expressir::Model::Types::Boolean
161
161
  - _class: Expressir::Model::Schema
162
- file: multiple.exp
162
+ file: original/examples/syntax/multiple.exp
163
163
  id: multiple_schema3
164
164
  entities:
165
165
  - _class: Expressir::Model::Entity
@@ -171,7 +171,7 @@ schemas:
171
171
  type:
172
172
  _class: Expressir::Model::Types::Boolean
173
173
  - _class: Expressir::Model::Schema
174
- file: multiple.exp
174
+ file: original/examples/syntax/multiple.exp
175
175
  id: multiple_schema4
176
176
  entities:
177
177
  - _class: Expressir::Model::Entity
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: remark.exp
5
+ file: original/examples/syntax/remark.exp
6
6
  id: remark_schema
7
7
  remarks:
8
8
  - |-
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: single.exp
5
+ file: original/examples/syntax/single.exp
6
6
  id: single_schema
7
7
  entities:
8
8
  - _class: Expressir::Model::Entity
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: single.exp
5
+ file: original/examples/syntax/single.exp
6
6
  id: single_schema
7
7
  entities:
8
8
  - _class: Expressir::Model::Entity
@@ -2,7 +2,7 @@
2
2
  _class: Expressir::Model::Repository
3
3
  schemas:
4
4
  - _class: Expressir::Model::Schema
5
- file: syntax.exp
5
+ file: original/examples/syntax/syntax.exp
6
6
  id: syntax_schema
7
7
  version:
8
8
  _class: Expressir::Model::Literals::String
@@ -9,7 +9,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
9
9
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single.yaml")
10
10
 
11
11
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
12
- result = YAML.dump(repo.to_hash(skip_empty: true))
12
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
13
13
  # File.write(yaml_file, result)
14
14
  expected_result = File.read(yaml_file)
15
15
 
@@ -21,7 +21,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
21
21
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "multiple.yaml")
22
22
 
23
23
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
24
- result = YAML.dump(repo.to_hash(skip_empty: true))
24
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
25
25
  # File.write(yaml_file, result)
26
26
  expected_result = File.read(yaml_file)
27
27
 
@@ -33,7 +33,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
33
33
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "syntax.yaml")
34
34
 
35
35
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
36
- result = YAML.dump(repo.to_hash(skip_empty: true))
36
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
37
37
  # File.write(yaml_file, result)
38
38
  expected_result = File.read(yaml_file)
39
39
 
@@ -45,7 +45,7 @@ RSpec.describe Expressir::ExpressExp::Parser do
45
45
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "remark.yaml")
46
46
 
47
47
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
48
- result = YAML.dump(repo.to_hash(skip_empty: true))
48
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
49
49
  # File.write(yaml_file, result)
50
50
  expected_result = File.read(yaml_file)
51
51
 
@@ -83,38 +83,15 @@ RSpec.describe Expressir::ExpressExp::Parser do
83
83
 
84
84
  schemas = repo.schemas
85
85
  expect(schemas.count).to eq(5)
86
- expect(schemas[0].file).to eq(exp_files[0].basename.to_s)
86
+ expect(schemas[0].file).to eq(exp_files[0].to_s)
87
87
  expect(schemas[0].id).to eq("single_schema")
88
- expect(schemas[1].file).to eq(exp_files[1].basename.to_s)
88
+ expect(schemas[1].file).to eq(exp_files[1].to_s)
89
89
  expect(schemas[1].id).to eq("multiple_schema1")
90
- expect(schemas[2].file).to eq(exp_files[1].basename.to_s)
90
+ expect(schemas[2].file).to eq(exp_files[1].to_s)
91
91
  expect(schemas[2].id).to eq("multiple_schema2")
92
- expect(schemas[3].file).to eq(exp_files[1].basename.to_s)
92
+ expect(schemas[3].file).to eq(exp_files[1].to_s)
93
93
  expect(schemas[3].id).to eq("multiple_schema3")
94
- expect(schemas[4].file).to eq(exp_files[1].basename.to_s)
95
- expect(schemas[4].id).to eq("multiple_schema4")
96
- end
97
-
98
- it "parses multiple files with a root path (single.exp, multiple.exp)" do
99
- exp_files = [
100
- Expressir.root_path.join("original", "examples", "syntax", "single.exp"),
101
- Expressir.root_path.join("original", "examples", "syntax", "multiple.exp")
102
- ]
103
- root_path = Expressir.root_path
104
-
105
- repo = Expressir::ExpressExp::Parser.from_files(exp_files, root_path: root_path)
106
-
107
- schemas = repo.schemas
108
- expect(schemas.count).to eq(5)
109
- expect(schemas[0].file).to eq(exp_files[0].relative_path_from(root_path).to_s)
110
- expect(schemas[0].id).to eq("single_schema")
111
- expect(schemas[1].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
112
- expect(schemas[1].id).to eq("multiple_schema1")
113
- expect(schemas[2].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
114
- expect(schemas[2].id).to eq("multiple_schema2")
115
- expect(schemas[3].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
116
- expect(schemas[3].id).to eq("multiple_schema3")
117
- expect(schemas[4].file).to eq(exp_files[1].relative_path_from(root_path).to_s)
94
+ expect(schemas[4].file).to eq(exp_files[1].to_s)
118
95
  expect(schemas[4].id).to eq("multiple_schema4")
119
96
  end
120
97
  end
@@ -6,27 +6,13 @@ require "expressir/express_exp/formatter"
6
6
 
7
7
  RSpec.describe Expressir::Model::ModelElement do
8
8
  describe ".to_hash" do
9
- it "exports an object with a root path (single.exp)" do
10
- exp_file = Expressir.root_path.join("original", "examples", "syntax", "single.exp")
11
- yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single_root_path.yaml")
12
- root_path = Expressir.root_path
13
-
14
- repo = Expressir::ExpressExp::Parser.from_file(exp_file, root_path: root_path)
15
-
16
- result = YAML.dump(repo.to_hash(skip_empty: true))
17
- # File.write(yaml_file, result)
18
- expected_result = File.read(yaml_file)
19
-
20
- expect(result).to eq(expected_result)
21
- end
22
-
23
9
  it "exports an object with a formatter (single.exp)" do
24
10
  exp_file = Expressir.root_path.join("original", "examples", "syntax", "single.exp")
25
11
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single_formatted.yaml")
26
12
 
27
13
  repo = Expressir::ExpressExp::Parser.from_file(exp_file)
28
14
 
29
- result = YAML.dump(repo.to_hash(formatter: Expressir::ExpressExp::Formatter, skip_empty: true))
15
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, formatter: Expressir::ExpressExp::Formatter, skip_empty: true))
30
16
  # File.write(yaml_file, result)
31
17
  expected_result = File.read(yaml_file)
32
18
 
@@ -39,9 +25,9 @@ RSpec.describe Expressir::Model::ModelElement do
39
25
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single.yaml")
40
26
 
41
27
  input = YAML.load(File.read(yaml_file))
42
- repo = Expressir::Model::ModelElement.from_hash(input)
28
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
43
29
 
44
- result = YAML.dump(repo.to_hash(skip_empty: true))
30
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
45
31
  expected_result = File.read(yaml_file)
46
32
 
47
33
  expect(result).to eq(expected_result)
@@ -51,9 +37,9 @@ RSpec.describe Expressir::Model::ModelElement do
51
37
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "multiple.yaml")
52
38
 
53
39
  input = YAML.load(File.read(yaml_file))
54
- repo = Expressir::Model::ModelElement.from_hash(input)
40
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
55
41
 
56
- result = YAML.dump(repo.to_hash(skip_empty: true))
42
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
57
43
  expected_result = File.read(yaml_file)
58
44
 
59
45
  expect(result).to eq(expected_result)
@@ -63,9 +49,9 @@ RSpec.describe Expressir::Model::ModelElement do
63
49
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "syntax.yaml")
64
50
 
65
51
  input = YAML.load(File.read(yaml_file))
66
- repo = Expressir::Model::ModelElement.from_hash(input)
52
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
67
53
 
68
- result = YAML.dump(repo.to_hash(skip_empty: true))
54
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
69
55
  expected_result = File.read(yaml_file)
70
56
 
71
57
  expect(result).to eq(expected_result)
@@ -75,9 +61,9 @@ RSpec.describe Expressir::Model::ModelElement do
75
61
  yaml_file = Expressir.root_path.join("original", "examples", "syntax", "remark.yaml")
76
62
 
77
63
  input = YAML.load(File.read(yaml_file))
78
- repo = Expressir::Model::ModelElement.from_hash(input)
64
+ repo = Expressir::Model::ModelElement.from_hash(input, root_path: Expressir.root_path)
79
65
 
80
- result = YAML.dump(repo.to_hash(skip_empty: true))
66
+ result = YAML.dump(repo.to_hash(root_path: Expressir.root_path, skip_empty: true))
81
67
  expected_result = File.read(yaml_file)
82
68
 
83
69
  expect(result).to eq(expected_result)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expressir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -685,7 +685,6 @@ files:
685
685
  - original/examples/syntax/single.yaml
686
686
  - original/examples/syntax/single_formatted.exp
687
687
  - original/examples/syntax/single_formatted.yaml
688
- - original/examples/syntax/single_root_path.yaml
689
688
  - original/examples/syntax/syntax.exp
690
689
  - original/examples/syntax/syntax.yaml
691
690
  - original/examples/syntax/syntax_formatted.exp
@@ -1,9 +0,0 @@
1
- ---
2
- _class: Expressir::Model::Repository
3
- schemas:
4
- - _class: Expressir::Model::Schema
5
- file: original/examples/syntax/single.exp
6
- id: single_schema
7
- entities:
8
- - _class: Expressir::Model::Entity
9
- id: empty_entity