expressir 0.2.17-arm64-darwin → 0.2.18-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/expressir/express_exp/2.4/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/2.5/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/2.6/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/2.7/express_parser.bundle +0 -0
- data/lib/expressir/express_exp/parser.rb +9 -2
- data/lib/expressir/model/model_element.rb +10 -2
- data/lib/expressir/version.rb +1 -1
- data/original/examples/syntax/multiple.yaml +4 -0
- data/original/examples/syntax/remark.yaml +1 -0
- data/original/examples/syntax/single.yaml +1 -0
- data/original/examples/syntax/single_formatted.yaml +1 -0
- data/original/examples/syntax/single_root_path.yaml +9 -0
- data/original/examples/syntax/syntax.yaml +1 -0
- data/spec/expressir/express_exp/formatter_spec.rb +1 -0
- data/spec/expressir/express_exp/parser_spec.rb +28 -5
- data/spec/expressir/model/model_element_spec.rb +18 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fc925e9e40f5ff197b2886575187dcd59b26df7bb5949c7337a8b2769dffcc8
|
4
|
+
data.tar.gz: a6fd20f728d03289f341415f1e240585d3b79df85cc25f74ca6e59a9f07a8deb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0ebb243ba8ac2bd49240464ab71d3df7888e40113dd0f89165a4e176984eb5fb10733e86bdb73f62d3e9913002378362b42915f48c0a4d97836b4d77c13de05
|
7
|
+
data.tar.gz: 8389c687c263565a7ea98181d8bcc9c0864cfb2920fac776a96b39716d6ba42fdbd977355a4f9f6017f4e61702823ff8b48f7254944ab6ec331c83663117c315
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -5,6 +5,7 @@ rescue LoadError
|
|
5
5
|
require_relative "express_parser"
|
6
6
|
end
|
7
7
|
require 'expressir/express_exp/visitor'
|
8
|
+
require 'pathname'
|
8
9
|
|
9
10
|
=begin
|
10
11
|
char_stream = Antlr4::Runtime::CharStreams.from_string(input, 'String')
|
@@ -25,6 +26,8 @@ module Expressir
|
|
25
26
|
module ExpressExp
|
26
27
|
class Parser
|
27
28
|
def self.from_file(file, options = {})
|
29
|
+
root_path = options[:root_path]
|
30
|
+
|
28
31
|
input = File.read(file)
|
29
32
|
|
30
33
|
parser = ::ExpressParser::Parser.parse(input)
|
@@ -34,7 +37,9 @@ module Expressir
|
|
34
37
|
visitor = Visitor.new(parser.tokens, options)
|
35
38
|
repository = visitor.visit(parse_tree)
|
36
39
|
|
37
|
-
repository.schemas.each
|
40
|
+
repository.schemas.each do |schema|
|
41
|
+
schema.file = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : File.basename(file)
|
42
|
+
end
|
38
43
|
|
39
44
|
repository
|
40
45
|
end
|
@@ -51,7 +56,9 @@ module Expressir
|
|
51
56
|
schemas: schemas
|
52
57
|
})
|
53
58
|
|
54
|
-
repository.schemas.each
|
59
|
+
repository.schemas.each do |schema|
|
60
|
+
schema.parent = repository
|
61
|
+
end
|
55
62
|
|
56
63
|
repository
|
57
64
|
end
|
@@ -2,6 +2,9 @@ module Expressir
|
|
2
2
|
module Model
|
3
3
|
class ModelElement
|
4
4
|
CLASS_KEY = '_class'
|
5
|
+
FILE_KEY = 'file'
|
6
|
+
PARENT_KEY = 'parent'
|
7
|
+
CHILDREN_BY_ID_KEY = 'children_by_id'
|
5
8
|
SOURCE_KEY = 'source'
|
6
9
|
|
7
10
|
attr_accessor :parent
|
@@ -11,7 +14,8 @@ module Expressir
|
|
11
14
|
end
|
12
15
|
|
13
16
|
def model_instance_variables
|
14
|
-
|
17
|
+
skip_variables = [FILE_KEY, PARENT_KEY, CHILDREN_BY_ID_KEY].map{|x| "@#{x}".to_sym}
|
18
|
+
instance_variables.select{|x| !skip_variables.include?(x)}
|
15
19
|
end
|
16
20
|
|
17
21
|
def path
|
@@ -88,11 +92,15 @@ module Expressir
|
|
88
92
|
end
|
89
93
|
|
90
94
|
def to_hash(options = {})
|
91
|
-
|
95
|
+
root_path = options[:root_path]
|
92
96
|
formatter = options[:formatter]
|
97
|
+
include_empty = options[:include_empty] || !options[:skip_empty] # TODO: remove skip_empty
|
93
98
|
|
94
99
|
hash = {}
|
95
100
|
hash[CLASS_KEY] = self.class.name
|
101
|
+
if self.is_a? Schema and file
|
102
|
+
hash[FILE_KEY] = root_path ? File.expand_path("#{root_path}/#{file}") : file
|
103
|
+
end
|
96
104
|
|
97
105
|
model_instance_variables.each_with_object(hash) do |variable, result|
|
98
106
|
key = variable.to_s.sub(/^@/, '')
|
data/lib/expressir/version.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
_class: Expressir::Model::Repository
|
3
3
|
schemas:
|
4
4
|
- _class: Expressir::Model::Schema
|
5
|
+
file: multiple.exp
|
5
6
|
id: multiple_schema1
|
6
7
|
interfaces:
|
7
8
|
- _class: Expressir::Model::Interface
|
@@ -146,6 +147,7 @@ schemas:
|
|
146
147
|
- _class: Expressir::Model::Expressions::SimpleReference
|
147
148
|
id: missing_entity
|
148
149
|
- _class: Expressir::Model::Schema
|
150
|
+
file: multiple.exp
|
149
151
|
id: multiple_schema2
|
150
152
|
entities:
|
151
153
|
- _class: Expressir::Model::Entity
|
@@ -157,6 +159,7 @@ schemas:
|
|
157
159
|
type:
|
158
160
|
_class: Expressir::Model::Types::Boolean
|
159
161
|
- _class: Expressir::Model::Schema
|
162
|
+
file: multiple.exp
|
160
163
|
id: multiple_schema3
|
161
164
|
entities:
|
162
165
|
- _class: Expressir::Model::Entity
|
@@ -168,6 +171,7 @@ schemas:
|
|
168
171
|
type:
|
169
172
|
_class: Expressir::Model::Types::Boolean
|
170
173
|
- _class: Expressir::Model::Schema
|
174
|
+
file: multiple.exp
|
171
175
|
id: multiple_schema4
|
172
176
|
entities:
|
173
177
|
- _class: Expressir::Model::Entity
|
@@ -83,15 +83,38 @@ 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])
|
86
|
+
expect(schemas[0].file).to eq(exp_files[0].basename.to_s)
|
87
87
|
expect(schemas[0].id).to eq("single_schema")
|
88
|
-
expect(schemas[1].file).to eq(exp_files[1])
|
88
|
+
expect(schemas[1].file).to eq(exp_files[1].basename.to_s)
|
89
89
|
expect(schemas[1].id).to eq("multiple_schema1")
|
90
|
-
expect(schemas[2].file).to eq(exp_files[1])
|
90
|
+
expect(schemas[2].file).to eq(exp_files[1].basename.to_s)
|
91
91
|
expect(schemas[2].id).to eq("multiple_schema2")
|
92
|
-
expect(schemas[3].file).to eq(exp_files[1])
|
92
|
+
expect(schemas[3].file).to eq(exp_files[1].basename.to_s)
|
93
93
|
expect(schemas[3].id).to eq("multiple_schema3")
|
94
|
-
expect(schemas[4].file).to eq(exp_files[1])
|
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)
|
95
118
|
expect(schemas[4].id).to eq("multiple_schema4")
|
96
119
|
end
|
97
120
|
end
|
@@ -1,15 +1,32 @@
|
|
1
|
+
|
2
|
+
require "yaml"
|
1
3
|
require "spec_helper"
|
2
4
|
require "expressir/express_exp/parser"
|
5
|
+
require "expressir/express_exp/formatter"
|
3
6
|
|
4
7
|
RSpec.describe Expressir::Model::ModelElement do
|
5
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
|
+
|
6
23
|
it "exports an object with a formatter (single.exp)" do
|
7
24
|
exp_file = Expressir.root_path.join("original", "examples", "syntax", "single.exp")
|
8
25
|
yaml_file = Expressir.root_path.join("original", "examples", "syntax", "single_formatted.yaml")
|
9
26
|
|
10
27
|
repo = Expressir::ExpressExp::Parser.from_file(exp_file)
|
11
28
|
|
12
|
-
result = YAML.dump(repo.to_hash(
|
29
|
+
result = YAML.dump(repo.to_hash(formatter: Expressir::ExpressExp::Formatter, skip_empty: true))
|
13
30
|
# File.write(yaml_file, result)
|
14
31
|
expected_result = File.read(yaml_file)
|
15
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expressir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.18
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -332,6 +332,7 @@ files:
|
|
332
332
|
- original/examples/syntax/single.yaml
|
333
333
|
- original/examples/syntax/single_formatted.exp
|
334
334
|
- original/examples/syntax/single_formatted.yaml
|
335
|
+
- original/examples/syntax/single_root_path.yaml
|
335
336
|
- original/examples/syntax/syntax.exp
|
336
337
|
- original/examples/syntax/syntax.yaml
|
337
338
|
- original/examples/syntax/syntax_formatted.exp
|