expressir 1.2.1-x86_64-linux → 1.2.5-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cross_rubies +3 -6
- data/.github/workflows/rake.yml +223 -19
- data/.github/workflows/release.yml +1 -0
- data/.gitignore +7 -1
- data/.gitmodules +4 -1
- data/.rubocop.yml +13 -4
- data/Rakefile +4 -1
- data/bin/console +0 -1
- data/bin/rspec +3 -3
- data/exe/expressir +4 -2
- data/exe/format +1 -1
- data/exe/format-test +25 -25
- data/exe/generate-parser +16 -13
- data/expressir.gemspec +13 -11
- data/lib/expressir/config.rb +1 -1
- data/lib/expressir/express/2.7/express_parser.so +0 -0
- data/lib/expressir/express/3.0/express_parser.so +0 -0
- data/lib/expressir/express/3.1/express_parser.so +0 -0
- data/lib/expressir/express/parser.rb +18 -15
- data/lib/expressir/express/visitor.rb +7 -3
- data/lib/expressir/model.rb +78 -78
- data/lib/expressir/version.rb +1 -1
- data/rakelib/antlr4-native.rake +63 -0
- data/rakelib/cross-ruby.rake +216 -157
- data/spec/acceptance/version_spec.rb +7 -2
- data/spec/expressir/express/cache_spec.rb +8 -5
- data/spec/expressir/express/formatter_spec.rb +16 -8
- data/spec/expressir/express/parser_spec.rb +17 -11
- data/spec/expressir/model/model_element_spec.rb +154 -146
- metadata +55 -63
- data/demo.rb +0 -18
- data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +0 -9589
- data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +0 -36619
- data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +0 -13294
- data/original/examples/employment/eclipse/.project +0 -17
- data/original/examples/employment/eclipse/Export/Employment.png +0 -0
- data/original/examples/employment/eclipse/Express/employment_schema.exp +0 -33
- data/original/examples/employment/eclipse/Express/employment_schema.xmi +0 -77
- data/original/examples/employment/eclipse/Express/employment_schema.xml +0 -93
- data/original/examples/employment/eclipse/Models/Employment.uml +0 -4
- data/original/examples/employment/eclipse/Models/Employment.umldi +0 -240
- data/original/examples/employment/eclipse/readme.txt +0 -7
- data/original/examples/employment/employment_schema.exp +0 -33
- data/original/examples/employment/employment_schema.rb +0 -232
- data/original/examples/employment/employment_schema.xml +0 -93
- data/original/examples/employment/employment_schema___module.rb +0 -46
- data/original/examples/employment/employment_schema___p28attr.rb +0 -126
- data/original/examples/employment/employment_schema___p28inst.rb +0 -26
- data/original/examples/employment/example_employment_data.xml +0 -1
- data/original/examples/employment/example_employment_data_copy.xml +0 -1
- data/original/examples/employment/example_employment_reader.rb +0 -30
- data/original/examples/employment/example_employment_writer.rb +0 -51
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +0 -3710
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +0 -35880
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +0 -15357
- data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +0 -9468
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +0 -8404
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +0 -43147
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +0 -18341
- data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +0 -11632
- data/original/exp2ruby.rb +0 -525
- data/original/expsm.rb +0 -34
- data/original/mapping_owl.rb +0 -1018
- data/original/mapping_sysml.rb +0 -2281
- data/original/mapping_uml2.rb +0 -599
- data/original/mapping_uml2_eclipse.rb +0 -433
- data/original/reeper.rb +0 -134
- data/spec/expressr_spec.rb +0 -5
@@ -31,25 +31,28 @@ module Expressir
|
|
31
31
|
# @param [Boolean] include_source attach original source code to model elements
|
32
32
|
# @return [Model::Repository]
|
33
33
|
def self.from_file(file, skip_references: nil, include_source: nil)
|
34
|
-
input = File.read(file)
|
34
|
+
@input = File.read(file)
|
35
35
|
|
36
|
-
|
36
|
+
# An important note re memory management
|
37
|
+
# parse, syntax, visitor methods return complex tree structures created in netive (C++) extension
|
38
|
+
# visit method references nodes and leaves of this structures but it is totally untransparent for Ruby GarbageCllector
|
39
|
+
# so in this class we keep those C++ structure marked for GC so theu are not freed
|
40
|
+
@parser = ::ExpressParser::Parser.parse(@input)
|
41
|
+
@parse_tree = @parser.syntax()
|
37
42
|
|
38
|
-
|
43
|
+
@visitor = Visitor.new(@parser.tokens, include_source: include_source)
|
44
|
+
@repository = @visitor.visit(@parse_tree)
|
39
45
|
|
40
|
-
|
41
|
-
repository = visitor.visit(parse_tree)
|
42
|
-
|
43
|
-
repository.schemas.each do |schema|
|
46
|
+
@repository.schemas.each do |schema|
|
44
47
|
schema.file = file.to_s
|
45
48
|
end
|
46
49
|
|
47
50
|
unless skip_references
|
48
|
-
resolve_references_model_visitor = ResolveReferencesModelVisitor.new
|
49
|
-
resolve_references_model_visitor.visit(repository)
|
51
|
+
@resolve_references_model_visitor = ResolveReferencesModelVisitor.new
|
52
|
+
@resolve_references_model_visitor.visit(@repository)
|
50
53
|
end
|
51
54
|
|
52
|
-
repository
|
55
|
+
@repository
|
53
56
|
end
|
54
57
|
|
55
58
|
# Parses Express files into an Express model
|
@@ -65,16 +68,16 @@ module Expressir
|
|
65
68
|
repository.schemas
|
66
69
|
end.flatten
|
67
70
|
|
68
|
-
repository = Model::Repository.new(
|
71
|
+
@repository = Model::Repository.new(
|
69
72
|
schemas: schemas
|
70
73
|
)
|
71
74
|
|
72
|
-
unless skip_references
|
73
|
-
resolve_references_model_visitor = ResolveReferencesModelVisitor.new
|
74
|
-
resolve_references_model_visitor.visit(repository)
|
75
|
+
unless @skip_references
|
76
|
+
@resolve_references_model_visitor = ResolveReferencesModelVisitor.new
|
77
|
+
@resolve_references_model_visitor.visit(@repository)
|
75
78
|
end
|
76
79
|
|
77
|
-
repository
|
80
|
+
@repository
|
78
81
|
end
|
79
82
|
end
|
80
83
|
end
|
@@ -31,6 +31,8 @@ require "set"
|
|
31
31
|
# - prevents segfault in ANTLR4 C++ runtime, not sure why they are caused
|
32
32
|
# - e.g. see visit_schema_decl
|
33
33
|
|
34
|
+
require 'objspace'
|
35
|
+
|
34
36
|
module Expressir
|
35
37
|
module Express
|
36
38
|
class Visitor < ::ExpressParser::Visitor
|
@@ -138,13 +140,15 @@ module Expressir
|
|
138
140
|
end
|
139
141
|
|
140
142
|
def attach_remarks(ctx, node)
|
141
|
-
remark_tokens = get_tokens(ctx)
|
143
|
+
@remark_tokens = get_tokens(ctx)
|
144
|
+
@remark_tokens = @remark_tokens.select{ |x| x.channel == REMARK_CHANNEL
|
145
|
+
}
|
142
146
|
|
143
147
|
# skip already attached remarks
|
144
|
-
remark_tokens = remark_tokens.select{|x| !@attached_remark_tokens.include?(x)}
|
148
|
+
@remark_tokens = @remark_tokens.select{|x| !@attached_remark_tokens.include?(x)}
|
145
149
|
|
146
150
|
# parse remarks, find remark targets
|
147
|
-
tagged_remark_tokens = remark_tokens.map do |remark_token|
|
151
|
+
tagged_remark_tokens = @remark_tokens.map do |remark_token|
|
148
152
|
_, remark_tag, remark_text = if remark_token.text.start_with?('--')
|
149
153
|
remark_token.text.match(/^--"([^"]*)"(.*)$/).to_a
|
150
154
|
else
|
data/lib/expressir/model.rb
CHANGED
@@ -1,79 +1,79 @@
|
|
1
|
-
require
|
1
|
+
require "expressir/model/model_element"
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
58
|
-
require
|
59
|
-
require
|
60
|
-
require
|
61
|
-
require
|
62
|
-
require
|
63
|
-
require
|
64
|
-
require
|
65
|
-
require
|
66
|
-
require
|
67
|
-
require
|
68
|
-
require
|
69
|
-
require
|
70
|
-
require
|
71
|
-
require
|
72
|
-
require
|
73
|
-
require
|
74
|
-
require
|
75
|
-
require
|
76
|
-
require
|
77
|
-
require
|
78
|
-
require
|
79
|
-
require
|
3
|
+
require "expressir/model/cache"
|
4
|
+
require "expressir/model/data_type"
|
5
|
+
require "expressir/model/declaration"
|
6
|
+
require "expressir/model/expression"
|
7
|
+
require "expressir/model/identifier"
|
8
|
+
require "expressir/model/literal"
|
9
|
+
require "expressir/model/reference"
|
10
|
+
require "expressir/model/repository"
|
11
|
+
require "expressir/model/statement"
|
12
|
+
require "expressir/model/supertype_expression"
|
13
|
+
require "expressir/model/data_types/aggregate"
|
14
|
+
require "expressir/model/data_types/array"
|
15
|
+
require "expressir/model/data_types/bag"
|
16
|
+
require "expressir/model/data_types/binary"
|
17
|
+
require "expressir/model/data_types/boolean"
|
18
|
+
require "expressir/model/data_types/enumeration"
|
19
|
+
require "expressir/model/data_types/enumeration_item"
|
20
|
+
require "expressir/model/data_types/generic_entity"
|
21
|
+
require "expressir/model/data_types/generic"
|
22
|
+
require "expressir/model/data_types/integer"
|
23
|
+
require "expressir/model/data_types/list"
|
24
|
+
require "expressir/model/data_types/logical"
|
25
|
+
require "expressir/model/data_types/number"
|
26
|
+
require "expressir/model/data_types/real"
|
27
|
+
require "expressir/model/data_types/set"
|
28
|
+
require "expressir/model/data_types/select"
|
29
|
+
require "expressir/model/data_types/string"
|
30
|
+
require "expressir/model/declarations/attribute"
|
31
|
+
require "expressir/model/declarations/constant"
|
32
|
+
require "expressir/model/declarations/entity"
|
33
|
+
require "expressir/model/declarations/function"
|
34
|
+
require "expressir/model/declarations/interface"
|
35
|
+
require "expressir/model/declarations/interface_item"
|
36
|
+
require "expressir/model/declarations/interfaced_item"
|
37
|
+
require "expressir/model/declarations/parameter"
|
38
|
+
require "expressir/model/declarations/procedure"
|
39
|
+
require "expressir/model/declarations/remark_item"
|
40
|
+
require "expressir/model/declarations/rule"
|
41
|
+
require "expressir/model/declarations/schema"
|
42
|
+
require "expressir/model/declarations/schema_version"
|
43
|
+
require "expressir/model/declarations/schema_version_item"
|
44
|
+
require "expressir/model/declarations/subtype_constraint"
|
45
|
+
require "expressir/model/declarations/type"
|
46
|
+
require "expressir/model/declarations/unique_rule"
|
47
|
+
require "expressir/model/declarations/variable"
|
48
|
+
require "expressir/model/declarations/where_rule"
|
49
|
+
require "expressir/model/expressions/aggregate_initializer"
|
50
|
+
require "expressir/model/expressions/aggregate_initializer_item"
|
51
|
+
require "expressir/model/expressions/binary_expression"
|
52
|
+
require "expressir/model/expressions/entity_constructor"
|
53
|
+
require "expressir/model/expressions/function_call"
|
54
|
+
require "expressir/model/expressions/interval"
|
55
|
+
require "expressir/model/expressions/query_expression"
|
56
|
+
require "expressir/model/expressions/unary_expression"
|
57
|
+
require "expressir/model/literals/binary"
|
58
|
+
require "expressir/model/literals/integer"
|
59
|
+
require "expressir/model/literals/logical"
|
60
|
+
require "expressir/model/literals/real"
|
61
|
+
require "expressir/model/literals/string"
|
62
|
+
require "expressir/model/references/attribute_reference"
|
63
|
+
require "expressir/model/references/group_reference"
|
64
|
+
require "expressir/model/references/index_reference"
|
65
|
+
require "expressir/model/references/simple_reference"
|
66
|
+
require "expressir/model/statements/alias"
|
67
|
+
require "expressir/model/statements/assignment"
|
68
|
+
require "expressir/model/statements/case"
|
69
|
+
require "expressir/model/statements/case_action"
|
70
|
+
require "expressir/model/statements/compound"
|
71
|
+
require "expressir/model/statements/escape"
|
72
|
+
require "expressir/model/statements/if"
|
73
|
+
require "expressir/model/statements/null"
|
74
|
+
require "expressir/model/statements/procedure_call"
|
75
|
+
require "expressir/model/statements/repeat"
|
76
|
+
require "expressir/model/statements/return"
|
77
|
+
require "expressir/model/statements/skip"
|
78
|
+
require "expressir/model/supertype_expressions/binary_supertype_expression"
|
79
|
+
require "expressir/model/supertype_expressions/oneof_supertype_expression"
|
data/lib/expressir/version.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "antlr4-native"
|
3
|
+
require "rake"
|
4
|
+
|
5
|
+
def create_tokens_api(parser_source_lines)
|
6
|
+
# - add ParserProxy tokens method, simple compensation for missing exposed BufferedTokenStream
|
7
|
+
i = parser_source_lines.index { |x| x == " Object syntax() {" }
|
8
|
+
parser_source_lines[i + 6] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n")
|
9
|
+
|
10
|
+
Array getTokens() {
|
11
|
+
Array a;
|
12
|
+
|
13
|
+
std::vector<Token*> tokens = this -> tokens -> getTokens();
|
14
|
+
|
15
|
+
for (auto &token : tokens) {
|
16
|
+
a.push(token);
|
17
|
+
}
|
18
|
+
|
19
|
+
return a;
|
20
|
+
}
|
21
|
+
|
22
|
+
CPP
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_tokens_method(parser_source_lines)
|
26
|
+
i = parser_source_lines.index { |x| x == ' .define_method("syntax", &ParserProxy::syntax, Return().keepAlive())' }
|
27
|
+
parser_source_lines[i] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n")
|
28
|
+
|
29
|
+
.define_method("tokens", &ParserProxy::getTokens)
|
30
|
+
CPP
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Generate parser (Usage: 'rake generate <grammar_file>')"
|
34
|
+
task "generate" do
|
35
|
+
grammar_file = ARGV[1]
|
36
|
+
if grammar_file.nil?
|
37
|
+
grammar_file = File.expand_path(File.join("..", "ext", "express-grammar", "Express.g4"), __dir__)
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "Generating parser from '#{grammar_file}'"
|
41
|
+
|
42
|
+
# ANTLR does weird things if the grammar file isn't in the current working directory
|
43
|
+
temp_grammar_file = File.join(FileUtils.pwd, File.basename(grammar_file))
|
44
|
+
FileUtils.cp(grammar_file, temp_grammar_file)
|
45
|
+
|
46
|
+
# generate parser
|
47
|
+
generator = Antlr4Native::Generator.new(
|
48
|
+
grammar_files: [File.basename(temp_grammar_file)],
|
49
|
+
output_dir: "ext",
|
50
|
+
parser_root_method: "syntax",
|
51
|
+
)
|
52
|
+
generator.generate
|
53
|
+
|
54
|
+
# fix issues with generated parser
|
55
|
+
parser_source_file = File.join("ext", "express-parser", "express_parser.cpp")
|
56
|
+
parser_source_lines = File.read(parser_source_file).split("\n")
|
57
|
+
create_tokens_api(parser_source_lines)
|
58
|
+
create_tokens_method(parser_source_lines)
|
59
|
+
File.write(parser_source_file, "#{parser_source_lines.join("\n")}\n")
|
60
|
+
|
61
|
+
# cleanup
|
62
|
+
FileUtils.rm(temp_grammar_file)
|
63
|
+
end
|