expressir 1.2.4-x64-mingw32 → 1.2.7-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +0 -6
  3. data/.github/workflows/rake.yml +200 -21
  4. data/.gitignore +7 -2
  5. data/.gitmodules +3 -0
  6. data/.rubocop.yml +13 -4
  7. data/README.adoc +8 -0
  8. data/Rakefile +4 -1
  9. data/bin/console +0 -1
  10. data/bin/rspec +3 -3
  11. data/exe/expressir +4 -2
  12. data/exe/format +1 -1
  13. data/exe/format-test +25 -25
  14. data/exe/generate-parser +16 -13
  15. data/expressir.gemspec +12 -10
  16. data/lib/expressir/config.rb +1 -1
  17. data/lib/expressir/express/2.7/express_parser.so +0 -0
  18. data/lib/expressir/express/3.0/express_parser.so +0 -0
  19. data/lib/expressir/express/parser.rb +3 -4
  20. data/lib/expressir/express/visitor.rb +7 -5
  21. data/lib/expressir/model.rb +78 -78
  22. data/lib/expressir/version.rb +1 -1
  23. data/rakelib/antlr4-native.rake +161 -0
  24. data/rakelib/cross-ruby.rake +213 -162
  25. data/spec/acceptance/version_spec.rb +17 -2
  26. data/spec/expressir/express/cache_spec.rb +23 -5
  27. data/spec/expressir/express/formatter_spec.rb +54 -8
  28. data/spec/expressir/express/parser_spec.rb +47 -11
  29. data/spec/expressir/model/model_element_spec.rb +198 -146
  30. data/spec/spec_helper.rb +7 -0
  31. metadata +54 -63
  32. data/demo.rb +0 -18
  33. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +0 -9589
  34. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +0 -36619
  35. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +0 -13294
  36. data/original/examples/employment/eclipse/.project +0 -17
  37. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  38. data/original/examples/employment/eclipse/Express/employment_schema.exp +0 -33
  39. data/original/examples/employment/eclipse/Express/employment_schema.xmi +0 -77
  40. data/original/examples/employment/eclipse/Express/employment_schema.xml +0 -93
  41. data/original/examples/employment/eclipse/Models/Employment.uml +0 -4
  42. data/original/examples/employment/eclipse/Models/Employment.umldi +0 -240
  43. data/original/examples/employment/eclipse/readme.txt +0 -7
  44. data/original/examples/employment/employment_schema.exp +0 -33
  45. data/original/examples/employment/employment_schema.rb +0 -232
  46. data/original/examples/employment/employment_schema.xml +0 -93
  47. data/original/examples/employment/employment_schema___module.rb +0 -46
  48. data/original/examples/employment/employment_schema___p28attr.rb +0 -126
  49. data/original/examples/employment/employment_schema___p28inst.rb +0 -26
  50. data/original/examples/employment/example_employment_data.xml +0 -1
  51. data/original/examples/employment/example_employment_data_copy.xml +0 -1
  52. data/original/examples/employment/example_employment_reader.rb +0 -30
  53. data/original/examples/employment/example_employment_writer.rb +0 -51
  54. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +0 -3710
  55. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +0 -35880
  56. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +0 -15357
  57. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +0 -9468
  58. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +0 -8404
  59. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +0 -43147
  60. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +0 -18341
  61. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +0 -11632
  62. data/original/exp2ruby.rb +0 -525
  63. data/original/expsm.rb +0 -34
  64. data/original/mapping_owl.rb +0 -1018
  65. data/original/mapping_sysml.rb +0 -2281
  66. data/original/mapping_uml2.rb +0 -599
  67. data/original/mapping_uml2_eclipse.rb +0 -433
  68. data/original/reeper.rb +0 -134
  69. data/spec/expressr_spec.rb +0 -5
@@ -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,15 +140,15 @@ module Expressir
138
140
  end
139
141
 
140
142
  def attach_remarks(ctx, node)
141
- remark_tokens = get_tokens(ctx)
142
- remark_tokens = remark_tokens.select{ |x| x.channel == REMARK_CHANNEL
143
- }
143
+ @remark_tokens = get_tokens(ctx)
144
+ @remark_tokens = @remark_tokens.select{ |x| x.channel == REMARK_CHANNEL
145
+ }
144
146
 
145
147
  # skip already attached remarks
146
- remark_tokens = remark_tokens.select{|x| !@attached_remark_tokens.include?(x)}
148
+ @remark_tokens = @remark_tokens.select{|x| !@attached_remark_tokens.include?(x)}
147
149
 
148
150
  # parse remarks, find remark targets
149
- tagged_remark_tokens = remark_tokens.map do |remark_token|
151
+ tagged_remark_tokens = @remark_tokens.map do |remark_token|
150
152
  _, remark_tag, remark_text = if remark_token.text.start_with?('--')
151
153
  remark_token.text.match(/^--"([^"]*)"(.*)$/).to_a
152
154
  else
@@ -1,79 +1,79 @@
1
- require 'expressir/model/model_element'
1
+ require "expressir/model/model_element"
2
2
 
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'
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"
@@ -1,3 +1,3 @@
1
1
  module Expressir
2
- VERSION = "1.2.4".freeze
2
+ VERSION = "1.2.7".freeze
3
3
  end
@@ -0,0 +1,161 @@
1
+ require "fileutils"
2
+ require "antlr4-native"
3
+ require "rake"
4
+
5
+ def create_class_declarations(parser_source_lines)
6
+ i = parser_source_lines.index { |x| x == "Class rb_cContextProxy;" }
7
+ parser_source_lines[i] += <<~CPP.split("\n").map { |x| x == "" ? x : x.to_s }.join("\n")
8
+
9
+ Class rb_cParserExt;
10
+ Class rb_cTokenExt;
11
+
12
+ CPP
13
+ end
14
+
15
+ def create_tp_class_definition(parser_source_lines)
16
+ i = parser_source_lines.index { |x| x == "class ContextProxy {" }
17
+ parser_source_lines[i - 2] += <<~CPP.split("\n").map { |x| x == "" ? x : x.to_s }.join("\n")
18
+
19
+
20
+ class TokenProxy : public Object {
21
+ public:
22
+ TokenProxy(Token* orig) {
23
+ this -> orig = orig;
24
+ }
25
+
26
+ std::string getText() {
27
+ return orig->getText();
28
+ }
29
+
30
+ size_t getChannel() {
31
+ return orig->getChannel();
32
+ }
33
+
34
+ size_t getTokenIndex() {
35
+ return orig->getTokenIndex();
36
+ }
37
+
38
+ private:
39
+ Token * orig = nullptr;
40
+ };
41
+
42
+ CPP
43
+ end
44
+
45
+ def create_pp_class_definition(parser_source_lines)
46
+ i = parser_source_lines.index { |x| x == "extern \"C\"" }
47
+ parser_source_lines[i - 2] += <<~CPP.split("\n").map { |x| x == "" ? x : x.to_s }.join("\n")
48
+
49
+ class ParserProxyExt : public Object {
50
+ public:
51
+ ParserProxyExt(Object self, string file) {
52
+ ifstream stream;
53
+ stream.open(file);
54
+ input = new ANTLRInputStream(stream);
55
+ lexer = new ExpressLexer(input);
56
+ tokens = new CommonTokenStream(lexer);
57
+ parser = new ExpressParser(tokens);
58
+ stream.close();
59
+ };
60
+
61
+ ~ParserProxyExt() {
62
+ delete parser;
63
+ delete tokens;
64
+ delete lexer;
65
+ delete input;
66
+ }
67
+
68
+ Object syntax() {
69
+ auto ctx = parser -> syntax();
70
+
71
+ SyntaxContextProxy proxy((ExpressParser::SyntaxContext*) ctx);
72
+ return detail::To_Ruby<SyntaxContextProxy>().convert(proxy);
73
+ }
74
+
75
+ Array getTokens() {
76
+ Array a;
77
+ for (auto token : tokens -> getTokens()) {
78
+ a.push(new TokenProxy(token));
79
+ }
80
+ return a;
81
+ }
82
+
83
+ Object visit(VisitorProxy* visitor) {
84
+ auto result = visitor -> visit(parser -> syntax());
85
+
86
+ lexer -> reset();
87
+ parser -> reset();
88
+
89
+ try {
90
+ return std::any_cast<Object>(result);
91
+ } catch(std::bad_cast) {
92
+ return Qnil;
93
+ }
94
+ }
95
+
96
+ private:
97
+ ANTLRInputStream* input;
98
+ ExpressLexer* lexer;
99
+ CommonTokenStream* tokens;
100
+ ExpressParser* parser;
101
+ };
102
+
103
+
104
+ CPP
105
+ end
106
+
107
+ def create_class_api(parser_source_lines)
108
+ i = parser_source_lines.index { |x| x == " .define_method(\"visit\", &ParserProxy::visit, Return().keepAlive());" }
109
+ parser_source_lines[i] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n")
110
+
111
+
112
+ rb_cTokenExt = define_class_under<TokenProxy>(rb_mExpressParser, "TokenExt")
113
+ .define_method("text", &TokenProxy::getText)
114
+ .define_method("channel", &TokenProxy::getChannel)
115
+ .define_method("token_index", &TokenProxy::getTokenIndex);
116
+
117
+ rb_cParserExt = define_class_under<ParserProxyExt>(rb_mExpressParser, "ParserExt")
118
+ .define_constructor(Constructor<ParserProxyExt, Object, string>())
119
+ .define_method("syntax", &ParserProxyExt::syntax, Return().keepAlive())
120
+ .define_method("tokens", &ParserProxyExt::getTokens)
121
+ .define_method("visit", &ParserProxyExt::visit, Return().keepAlive());
122
+
123
+ CPP
124
+ end
125
+
126
+ def generate_extended_parser
127
+ # Generate extended parser that provide Ruby access to token stream
128
+ parser_source_file = File.join("ext", "express-parser", "express_parser.cpp")
129
+ parser_source_lines = File.read(parser_source_file).split("\n")
130
+ create_class_declarations(parser_source_lines)
131
+ create_tp_class_definition(parser_source_lines)
132
+ create_pp_class_definition(parser_source_lines)
133
+ create_class_api(parser_source_lines)
134
+ File.write(parser_source_file, "#{parser_source_lines.join("\n")}\n")
135
+ end
136
+
137
+ desc "Generate parser (Usage: 'rake generate <grammar_file>')"
138
+ task "generate" do
139
+ grammar_file = ARGV[1]
140
+ if grammar_file.nil?
141
+ grammar_file = File.expand_path(File.join("..", "ext", "express-grammar", "Express.g4"), __dir__)
142
+ end
143
+
144
+ puts "Generating parser from '#{grammar_file}'"
145
+ # ANTLR does weird things if the grammar file isn't in the current working directory
146
+ temp_grammar_file = File.join(FileUtils.pwd, File.basename(grammar_file))
147
+ FileUtils.cp(grammar_file, temp_grammar_file)
148
+
149
+ # generate parser
150
+ generator = Antlr4Native::Generator.new(
151
+ grammar_files: [File.basename(temp_grammar_file)],
152
+ output_dir: "ext",
153
+ parser_root_method: "syntax",
154
+ )
155
+ generator.generate
156
+
157
+ puts "Generating extended parser"
158
+ generate_extended_parser
159
+ # cleanup
160
+ FileUtils.rm(temp_grammar_file)
161
+ end