antlr4-native 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/lib/antlr4-native/generator.rb +17 -32
- data/lib/antlr4-native/version.rb +1 -1
- data/lib/antlr4-native/visitor_generator.rb +2 -2
- data/vendor/antlr-4.10.1-complete.jar +0 -0
- metadata +3 -3
- data/vendor/antlr4-4.8-1-complete.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bed5c4bbb574d8ad5cbef067bee9fff704a1f0bf8d5fa0b522393d5fa771be3
|
4
|
+
data.tar.gz: 44dcb2987d8f3c04bc2f9a4769853b6bdfbf390b0aebdff9fcc783b98a389896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25961945b37da84af109e20b39728f57108d3e7490165d936898c95a76bec6add1e18086609c0085f14614efcd801b31723a17032a111ec86236f31709f52ec6
|
7
|
+
data.tar.gz: 20e79181660b66a56c94ef35fccd369c7590ed676703854f91aafa7147398fea220fb26c6e7f7ccb1bc3810fcc4c64f0db0018dda887b6344f6ae97930e24f3e
|
data/README.md
CHANGED
@@ -79,9 +79,8 @@ Finally, if you override `#initialize` in your visitor subclasses, don't forget
|
|
79
79
|
|
80
80
|
## Caveats
|
81
81
|
|
82
|
-
1.
|
83
|
-
|
84
|
-
3. The description of this gem says "(almost) any ANTLR4 grammar" because many grammars contain target-specific code. For example, the Python3 grammar referenced in the examples above contains inline Java code that the C++ compiler won't understand. You'll need to port any such code to C++ before you'll be able to compile and use the native extension.
|
82
|
+
1. Due to an ANTLR limitation, parsers cannot be used in a multi-threaded environment, even if each parser instance is used entirely in the context of a single thread (i.e. parsers are not shared between threads). According to the ANTLR C++ developers, parsers should be threadsafe. Unfortunately firsthand experience has proven otherwise. Your mileage may vary.
|
83
|
+
1. The description of this gem says "(almost) any ANTLR4 grammar" because many grammars contain target-specific code. For example, the Python3 grammar referenced in the examples above contains inline Java code that the C++ compiler won't understand. You'll need to port any such code to C++ before you'll be able to compile and use the native extension.
|
85
84
|
|
86
85
|
## System Requirements
|
87
86
|
|
@@ -2,10 +2,10 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module Antlr4Native
|
4
4
|
class Generator
|
5
|
-
ANTLR_VERSION = '4.
|
5
|
+
ANTLR_VERSION = '4.10.1'.freeze
|
6
6
|
|
7
7
|
ANTLR_JAR = File.expand_path(
|
8
|
-
File.join('..', '..', 'vendor',
|
8
|
+
File.join('..', '..', 'vendor', "antlr-#{ANTLR_VERSION}-complete.jar"), __dir__
|
9
9
|
).freeze
|
10
10
|
|
11
11
|
include StringHelpers
|
@@ -16,6 +16,7 @@ module Antlr4Native
|
|
16
16
|
@grammar_files = grammar_files
|
17
17
|
@output_dir = output_dir
|
18
18
|
@parser_root_method = parser_root_method
|
19
|
+
|
19
20
|
end
|
20
21
|
|
21
22
|
def generate
|
@@ -24,7 +25,7 @@ module Antlr4Native
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def gem_name
|
27
|
-
@gem_name ||=
|
28
|
+
@gem_name ||= underscore(parser_ns)
|
28
29
|
end
|
29
30
|
|
30
31
|
def antlr_ns
|
@@ -147,39 +148,25 @@ module Antlr4Native
|
|
147
148
|
}
|
148
149
|
|
149
150
|
Array getChildren() {
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
for (auto it = orig -> children.begin(); it != orig -> children.end(); it ++) {
|
155
|
-
Object parseTree = ContextProxy::wrapParseTree(*it);
|
151
|
+
Array children;
|
152
|
+
if (orig != nullptr) {
|
153
|
+
for (auto it = orig -> children.begin(); it != orig -> children.end(); it ++) {
|
154
|
+
Object parseTree = ContextProxy::wrapParseTree(*it);
|
156
155
|
|
157
|
-
|
158
|
-
|
159
|
-
}
|
156
|
+
if (parseTree != Nil) {
|
157
|
+
children.push(parseTree);
|
160
158
|
}
|
161
159
|
}
|
162
160
|
}
|
163
|
-
|
164
|
-
return *children;
|
161
|
+
return children;
|
165
162
|
}
|
166
163
|
|
167
164
|
Object getParent() {
|
168
|
-
|
169
|
-
if (orig != nullptr) {
|
170
|
-
parent = ContextProxy::wrapParseTree(orig -> parent);
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
return parent;
|
165
|
+
return orig == nullptr ? Nil : ContextProxy::wrapParseTree(orig -> parent);
|
175
166
|
}
|
176
167
|
|
177
168
|
size_t childCount() {
|
178
|
-
|
179
|
-
return 0;
|
180
|
-
}
|
181
|
-
|
182
|
-
return getChildren().size();
|
169
|
+
return orig == nullptr ? 0 : orig -> children.size();
|
183
170
|
}
|
184
171
|
|
185
172
|
bool doubleEquals(Object other) {
|
@@ -196,8 +183,6 @@ module Antlr4Native
|
|
196
183
|
|
197
184
|
protected:
|
198
185
|
tree::ParseTree* orig = nullptr;
|
199
|
-
Array* children = nullptr;
|
200
|
-
Object parent = Nil;
|
201
186
|
};
|
202
187
|
|
203
188
|
class TerminalNodeProxy : public ContextProxy {
|
@@ -284,7 +269,7 @@ module Antlr4Native
|
|
284
269
|
this -> lexer -> reset();
|
285
270
|
this -> parser -> reset();
|
286
271
|
|
287
|
-
return result;
|
272
|
+
return std::any_cast<Object>(result);
|
288
273
|
}
|
289
274
|
|
290
275
|
~ParserProxy() {
|
@@ -331,7 +316,7 @@ module Antlr4Native
|
|
331
316
|
<<~END
|
332
317
|
extern "C"
|
333
318
|
void Init_#{ext_name}() {
|
334
|
-
Module rb_m#{parser_ns} = define_module("#{parser_ns}");
|
319
|
+
Module rb_m#{parser_ns} = define_module("#{capitalize(parser_ns)}");
|
335
320
|
|
336
321
|
rb_cToken = define_class_under<Token>(rb_m#{parser_ns}, "Token")
|
337
322
|
.define_method("text", &Token::getText)
|
@@ -361,8 +346,8 @@ module Antlr4Native
|
|
361
346
|
rb_cParser = define_class_under<ParserProxy>(rb_m#{parser_ns}, "Parser")
|
362
347
|
.define_singleton_function("parse", &ParserProxy::parse)
|
363
348
|
.define_singleton_function("parse_file", &ParserProxy::parseFile)
|
364
|
-
.define_method("#{parser_root_method}", &ParserProxy::#{parser_root_method})
|
365
|
-
.define_method("visit", &ParserProxy::visit);
|
349
|
+
.define_method("#{parser_root_method}", &ParserProxy::#{parser_root_method}, Return().keepAlive())
|
350
|
+
.define_method("visit", &ParserProxy::visit, Return().keepAlive());
|
366
351
|
|
367
352
|
#{class_wrappers_str(' ')}
|
368
353
|
}
|
@@ -48,7 +48,7 @@ module Antlr4Native
|
|
48
48
|
Object ruby_visit(ContextProxy* proxy) {
|
49
49
|
auto result = visit(proxy -> getOriginal());
|
50
50
|
try {
|
51
|
-
return
|
51
|
+
return std::any_cast<Object>(result);
|
52
52
|
} catch(std::bad_cast) {
|
53
53
|
return Qnil;
|
54
54
|
}
|
@@ -57,7 +57,7 @@ module Antlr4Native
|
|
57
57
|
Object ruby_visitChildren(ContextProxy* proxy) {
|
58
58
|
auto result = visitChildren(proxy -> getOriginal());
|
59
59
|
try {
|
60
|
-
return
|
60
|
+
return std::any_cast<Object>(result);
|
61
61
|
} catch(std::bad_cast) {
|
62
62
|
return Qnil;
|
63
63
|
}
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antlr4-native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rice
|
@@ -43,7 +43,7 @@ files:
|
|
43
43
|
- lib/antlr4-native/string_helpers.rb
|
44
44
|
- lib/antlr4-native/version.rb
|
45
45
|
- lib/antlr4-native/visitor_generator.rb
|
46
|
-
- vendor/
|
46
|
+
- vendor/antlr-4.10.1-complete.jar
|
47
47
|
homepage: http://github.com/camertron/antlr4-native-rb
|
48
48
|
licenses: []
|
49
49
|
metadata: {}
|
Binary file
|