lutaml-uml 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/lutaml-wsd2uml +1 -1
- data/lib/lutaml/uml/package.rb +1 -1
- data/lib/lutaml/uml/parsers/dsl.rb +13 -6
- data/lib/lutaml/uml/parsers/dsl_preprocessor.rb +19 -4
- data/lib/lutaml/uml/version.rb +1 -1
- data/lutaml-uml.gemspec +1 -1
- data/spec/fixtures/dsl/broken_diagram.lutaml +34 -0
- data/spec/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
- data/spec/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
- data/spec/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
- data/spec/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
- data/spec/lutaml/uml/parsers/dsl_spec.rb +52 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9fee04e0d3f8bf1a741dcce56ebfac843c1207d5f9f4dc8b9f42869db728f6
|
4
|
+
data.tar.gz: 58b0ed6fb1e66d0a34aed9fefcf6d4625f52234bf100c93ad06f62297ec3e2cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df205676bcafcb09265a81491fbca4b78b2a1dfc59d18f080e20e4ddf633a3aed9601d09cd78b32fbd297c283027681b94276e5ceb68e1613dc8cb8dcd036243
|
7
|
+
data.tar.gz: 9191a9ba6db3db78aa785a685e4c75c4cd69f84441cb3420dde4fbc02dec885ddcaf18c12f263aa5852439721609bb3e11930b7cbfcaf8c20b461b517a1bc84c
|
data/exe/lutaml-wsd2uml
CHANGED
@@ -27,7 +27,7 @@ ASSOCIATION_MAPPINGS = {
|
|
27
27
|
in_comment_block = false
|
28
28
|
|
29
29
|
def transform_line(line)
|
30
|
-
line = line.gsub(/^\s*'/, '** ').gsub(/\|[\sa-zA-Z]+$/, '')
|
30
|
+
line = line.gsub(/^\s*'/, '** ').gsub(/\|[\sa-zA-Z]+$/, '').gsub(/\r/, '')
|
31
31
|
return sync_puts(line, 2) if ASSOCIATION_MAPPINGS.keys.none? { |key| line =~ key }
|
32
32
|
|
33
33
|
owner_type, member_type = ASSOCIATION_MAPPINGS.detect { |(key, _value)| line =~ key }.last.split(",")
|
data/lib/lutaml/uml/package.rb
CHANGED
@@ -10,7 +10,7 @@ module Lutaml
|
|
10
10
|
|
11
11
|
def initialize(attributes)
|
12
12
|
update_attributes(attributes)
|
13
|
-
@children_packages ||= packages.map { |pkg| [pkg, pkg.packages.map(&:children_packages)] }.flatten
|
13
|
+
@children_packages ||= packages.map { |pkg| [pkg, pkg.packages, pkg.packages.map(&:children_packages)] }.flatten.uniq
|
14
14
|
end
|
15
15
|
|
16
16
|
def classes=(value)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "parslet"
|
4
|
+
require "parslet/convenience"
|
4
5
|
require "lutaml/uml/parsers/dsl_preprocessor"
|
5
6
|
require "lutaml/uml/parsers/dsl_transform"
|
6
7
|
require "lutaml/uml/node/document"
|
@@ -8,6 +9,7 @@ require "lutaml/uml/node/document"
|
|
8
9
|
module Lutaml
|
9
10
|
module Uml
|
10
11
|
module Parsers
|
12
|
+
class ParsingError < StandardError; end
|
11
13
|
# Class for parsing LutaML dsl into Lutaml::Uml::Document
|
12
14
|
class Dsl < Parslet::Parser
|
13
15
|
# @param [String] io - LutaML string representation
|
@@ -20,7 +22,15 @@ module Lutaml
|
|
20
22
|
|
21
23
|
def parse(input_file, _options = {})
|
22
24
|
data = Lutaml::Uml::Parsers::DslPreprocessor.call(input_file)
|
23
|
-
|
25
|
+
# https://kschiess.github.io/parslet/tricks.html#Reporter engines
|
26
|
+
# Parslet::ErrorReporter::Deepest allows more
|
27
|
+
# detailed display of error
|
28
|
+
reporter = Parslet::ErrorReporter::Deepest.new
|
29
|
+
::Lutaml::Uml::Document
|
30
|
+
.new(DslTransform.new.apply(super(data, reporter: reporter)))
|
31
|
+
rescue Parslet::ParseFailed => e
|
32
|
+
raise(ParsingError,
|
33
|
+
"#{e.message}\ncause: #{e.parse_failure_cause.ascii_tree}")
|
24
34
|
end
|
25
35
|
|
26
36
|
KEYWORDS = %w[
|
@@ -292,9 +302,7 @@ module Lutaml
|
|
292
302
|
str("definition") >>
|
293
303
|
whitespace? >>
|
294
304
|
str("{") >>
|
295
|
-
|
296
|
-
(match("[\n\s]}").absent? >> any).repeat.as(:definition) >>
|
297
|
-
whitespace? >>
|
305
|
+
((str("\\") >> any) | (str("}").absent? >> any)).repeat.maybe.as(:definition) >>
|
298
306
|
str('}')
|
299
307
|
end
|
300
308
|
|
@@ -387,12 +395,11 @@ module Lutaml
|
|
387
395
|
diagram_inner_definition.repeat.as(:members) >>
|
388
396
|
str("}")
|
389
397
|
end
|
390
|
-
rule(:diagram_body?) { diagram_body.maybe }
|
391
398
|
rule(:diagram_definition) do
|
392
399
|
diagram_keyword >>
|
393
400
|
spaces? >>
|
394
401
|
class_name.as(:name) >>
|
395
|
-
diagram_body
|
402
|
+
diagram_body >>
|
396
403
|
whitespace?
|
397
404
|
end
|
398
405
|
rule(:diagram_definitions) { diagram_definition >> whitespace? }
|
@@ -5,16 +5,28 @@ module Lutaml
|
|
5
5
|
module Parsers
|
6
6
|
# Class for preprocessing dsl ascii file special directives:
|
7
7
|
# - include
|
8
|
-
|
9
|
-
|
8
|
+
class DslPreprocessor
|
9
|
+
attr_reader :input_file
|
10
10
|
|
11
|
-
def
|
11
|
+
def initialize(input_file)
|
12
|
+
@input_file = input_file
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def call(input_file)
|
17
|
+
new(input_file).call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
12
22
|
include_root = File.dirname(input_file.path)
|
13
23
|
input_file.read.split("\n").reduce([]) do |res, line|
|
14
24
|
res.push(*process_dsl_line(include_root, line))
|
15
25
|
end.join("\n")
|
16
26
|
end
|
17
27
|
|
28
|
+
private
|
29
|
+
|
18
30
|
def process_dsl_line(include_root, line)
|
19
31
|
process_include_line(include_root, process_comment_line(line))
|
20
32
|
end
|
@@ -28,7 +40,7 @@ module Lutaml
|
|
28
40
|
|
29
41
|
def process_include_line(include_root, line)
|
30
42
|
include_path_match = line.match(/^\s*include\s+(.+)/)
|
31
|
-
return line if include_path_match.nil?
|
43
|
+
return line if include_path_match.nil? || line =~ /^\s\*\*/
|
32
44
|
|
33
45
|
path_to_file = include_path_match[1].strip
|
34
46
|
path_to_file = if path_to_file.match?(/^\//)
|
@@ -37,6 +49,9 @@ module Lutaml
|
|
37
49
|
File.join(include_root, path_to_file)
|
38
50
|
end
|
39
51
|
File.read(path_to_file).split("\n")
|
52
|
+
rescue Errno::ENOENT
|
53
|
+
puts("No such file or directory @ rb_sysopen - #{path_to_file}, \
|
54
|
+
include file paths need to be supplied relative to the main document")
|
40
55
|
end
|
41
56
|
end
|
42
57
|
end
|
data/lib/lutaml/uml/version.rb
CHANGED
data/lutaml-uml.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = %w[lutaml-wsd2uml lutaml-yaml2uml]
|
26
26
|
|
27
27
|
spec.add_runtime_dependency "hashie", "~> 4.1.0"
|
28
|
-
spec.add_runtime_dependency "parslet", "~>
|
28
|
+
spec.add_runtime_dependency "parslet", "~> 2.0.0"
|
29
29
|
spec.add_runtime_dependency "ruby-graphviz", "~> 1.2"
|
30
30
|
spec.add_runtime_dependency "thor", "~> 1.0"
|
31
31
|
spec.add_runtime_dependency "nokogiri", "~> 1.10"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
diagram MyView {
|
2
|
+
title "my diagram"
|
3
|
+
|
4
|
+
class AddressClassProfile {
|
5
|
+
addressClassProfile
|
6
|
+
}
|
7
|
+
class AttributeProfile {
|
8
|
+
attributeProfile
|
9
|
+
}
|
10
|
+
|
11
|
+
association BidirectionalAsscoiation {
|
12
|
+
owner_type aggregation
|
13
|
+
member_type direct
|
14
|
+
owner AddressClassProfile#addressClassProfile
|
15
|
+
member AttributeProfile#attributeProfile [0..*]
|
16
|
+
}
|
17
|
+
|
18
|
+
association DirectAsscoiation {
|
19
|
+
member_type direct
|
20
|
+
owner AddressClassProfile
|
21
|
+
member AttributeProfile#attributeProfile
|
22
|
+
}
|
23
|
+
|
24
|
+
class Foo {
|
25
|
+
+structuredidentifier[0..*]: StructuredIdentifierType
|
26
|
+
+technicalcommittee[1..*]: TechnicalCommitteeType
|
27
|
+
}
|
28
|
+
|
29
|
+
association ReverseAsscoiation {
|
30
|
+
owner_type aggregation
|
31
|
+
owner AddressClassProfile#addressClassProfile
|
32
|
+
member AttributeProfile
|
33
|
+
}
|
34
|
+
}
|
@@ -287,5 +287,57 @@ RSpec.describe Lutaml::Uml::Parsers::Dsl do
|
|
287
287
|
|
288
288
|
it_behaves_like "the correct graphviz formatting"
|
289
289
|
end
|
290
|
+
|
291
|
+
context "when defninition is blank" do
|
292
|
+
let(:content) do
|
293
|
+
File.new(fixtures_path("dsl/diagram_blank_definion.lutaml"))
|
294
|
+
end
|
295
|
+
|
296
|
+
it "successfully renders" do
|
297
|
+
expect { parse }.to_not(raise_error)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context "when there are blank definitions" do
|
302
|
+
let(:content) do
|
303
|
+
File.new(fixtures_path("dsl/diagram_blank_entities.lutaml"))
|
304
|
+
end
|
305
|
+
|
306
|
+
it "successfully renders" do
|
307
|
+
expect { parse }.to_not(raise_error)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context "when its a non existing include file" do
|
312
|
+
let(:content) do
|
313
|
+
File.new(fixtures_path("dsl/diagram_non_existing_include.lutaml"))
|
314
|
+
end
|
315
|
+
|
316
|
+
it "successfully renders" do
|
317
|
+
expect { parse }.to_not(raise_error)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context "when there are commented preprocessor lines" do
|
322
|
+
let(:content) do
|
323
|
+
File.new(fixtures_path("dsl/diagram_commented_includes.lutaml"))
|
324
|
+
end
|
325
|
+
|
326
|
+
it "successfully renders" do
|
327
|
+
expect { parse }.to_not(raise_error)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context "when broken lutaml file passed" do
|
332
|
+
let(:content) do
|
333
|
+
File.new(fixtures_path("dsl/broken_diagram.lutaml"))
|
334
|
+
end
|
335
|
+
|
336
|
+
it "returns error object and prints line number" do
|
337
|
+
expect { described_class.parse(content, {}) }
|
338
|
+
.to(raise_error(Lutaml::Uml::Parsers::ParsingError,
|
339
|
+
/but got ":" at line 25 char 32/))
|
340
|
+
end
|
341
|
+
end
|
290
342
|
end
|
291
343
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lutaml-uml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ruby-graphviz
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -279,16 +279,21 @@ files:
|
|
279
279
|
- spec/fixtures/datamodel/views/AddressProfile.yml
|
280
280
|
- spec/fixtures/datamodel/views/CommonModels.yml
|
281
281
|
- spec/fixtures/datamodel/views/TopDown.yml
|
282
|
+
- spec/fixtures/dsl/broken_diagram.lutaml
|
282
283
|
- spec/fixtures/dsl/diagram.lutaml
|
283
284
|
- spec/fixtures/dsl/diagram_attributes.lutaml
|
285
|
+
- spec/fixtures/dsl/diagram_blank_definion.lutaml
|
286
|
+
- spec/fixtures/dsl/diagram_blank_entities.lutaml
|
284
287
|
- spec/fixtures/dsl/diagram_class_assocation.lutaml
|
285
288
|
- spec/fixtures/dsl/diagram_class_fields.lutaml
|
289
|
+
- spec/fixtures/dsl/diagram_commented_includes.lutaml
|
286
290
|
- spec/fixtures/dsl/diagram_comments.lutaml
|
287
291
|
- spec/fixtures/dsl/diagram_concept_model.lutaml
|
288
292
|
- spec/fixtures/dsl/diagram_data_types.lutaml
|
289
293
|
- spec/fixtures/dsl/diagram_definitions.lutaml
|
290
294
|
- spec/fixtures/dsl/diagram_includes.lutaml
|
291
295
|
- spec/fixtures/dsl/diagram_multiply_classes.lutaml
|
296
|
+
- spec/fixtures/dsl/diagram_non_existing_include.lutaml
|
292
297
|
- spec/fixtures/dsl/shared.lutaml
|
293
298
|
- spec/fixtures/dsl/shared1.lutaml
|
294
299
|
- spec/fixtures/generated_dot/AddressClassProfile.dot
|