antlr4-native 1.0.2 → 1.1.0
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.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/antlr4-native/context.rb +5 -0
- data/lib/antlr4-native/generator.rb +56 -30
- data/lib/antlr4-native/version.rb +1 -1
- data/lib/antlr4-native/visitor_generator.rb +4 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1abe502ed412ef8d9fda78dd371448d290c10bd757c34044c881c110f11c84df
|
4
|
+
data.tar.gz: 7093d010f55d0dac4b9b4e3d9a8f0da004ed40d4595caab9623bd717b879c812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2498b8804a2ba13e8fbc6e90ff0c3b209962712ec7005142d59a3ebe656123d28396a0a278a634bc228304bd9160beff49dd11985db6d5249ebed7857127b5
|
7
|
+
data.tar.gz: 738c3abb9486de9819faaab462a9f65e0823803f382180f3b32347e51d9d330c1072bfe9c1df239e48fc5c82c4f99f8db1e9bb3c6584752b6607b78ae4173c4a
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ generator = Antlr4Native::Generator.new(
|
|
28
28
|
generator.generate
|
29
29
|
```
|
30
30
|
|
31
|
-
In the example above, the output directory is set to the standard Ruby native extensions directory, 'ext'. Antlr4-native will generate code into ext
|
31
|
+
In the example above, the output directory is set to the standard Ruby native extensions directory, 'ext'. Antlr4-native will generate code into ext/\<name\>, where \<name\> is the name of the parser as defined in the grammar file(s). In this case, PythonParser.g4 contains:
|
32
32
|
|
33
33
|
```antlr
|
34
34
|
parser grammar Python3Parser;
|
@@ -85,12 +85,13 @@ Finally, if you override `#initialize` in your visitor subclasses, don't forget
|
|
85
85
|
|
86
86
|
## System Requirements
|
87
87
|
|
88
|
-
* A Java runtime (version 1.6 or higher) is required to generate parsers, since ANTLR is a Java tool. The ANTLR .jar file is distributed inside the antlr4-native gem, so there's no need to download it separately.
|
88
|
+
* A Java runtime (version 1.6 or higher) is required to generate parsers, since ANTLR is a Java tool. The ANTLR .jar file is distributed inside the antlr4-native gem, so there's no need to download it separately. You can download a Java runtime [here](https://www.java.com/en/download/).
|
89
89
|
* Ruby >= 2.3.
|
90
|
+
* A C compiler (like gcc or clang) that supports C++14. If Ruby is working on your machine then you likely already have this.
|
90
91
|
|
91
92
|
## License
|
92
93
|
|
93
|
-
Licensed under the MIT license. See LICENSE for details.
|
94
|
+
Licensed under the MIT license. See LICENSE.txt for details.
|
94
95
|
|
95
96
|
## Authors
|
96
97
|
|
@@ -63,7 +63,7 @@ module Antlr4Native
|
|
63
63
|
|
64
64
|
def interop_code
|
65
65
|
<<~END
|
66
|
-
#include
|
66
|
+
#include <iostream>
|
67
67
|
|
68
68
|
#include "antlr4-runtime.h"
|
69
69
|
|
@@ -76,12 +76,38 @@ module Antlr4Native
|
|
76
76
|
#include "rice/Constructor.hpp"
|
77
77
|
#include "rice/Director.hpp"
|
78
78
|
|
79
|
+
#ifdef _WIN32
|
80
|
+
#undef FALSE
|
81
|
+
#undef TRUE
|
82
|
+
#undef OPTIONAL
|
83
|
+
#undef IN
|
84
|
+
#undef OUT
|
85
|
+
#endif
|
86
|
+
|
79
87
|
using namespace std;
|
80
88
|
using namespace Rice;
|
81
89
|
using namespace antlr4;
|
82
90
|
|
83
91
|
#{proxy_class_declarations}
|
84
92
|
|
93
|
+
template <>
|
94
|
+
Object to_ruby<Token*>(Token* const &x) {
|
95
|
+
if (!x) return Nil;
|
96
|
+
return Data_Object<Token>(x, rb_cToken, nullptr, nullptr);
|
97
|
+
}
|
98
|
+
|
99
|
+
template <>
|
100
|
+
Object to_ruby<tree::ParseTree*>(tree::ParseTree* const &x) {
|
101
|
+
if (!x) return Nil;
|
102
|
+
return Data_Object<tree::ParseTree>(x, rb_cParseTree, nullptr, nullptr);
|
103
|
+
}
|
104
|
+
|
105
|
+
template <>
|
106
|
+
Object to_ruby<tree::TerminalNode*>(tree::TerminalNode* const &x) {
|
107
|
+
if (!x) return Nil;
|
108
|
+
return Data_Object<tree::TerminalNode>(x, rb_cTerminalNode, nullptr, nullptr);
|
109
|
+
}
|
110
|
+
|
85
111
|
class ContextProxy {
|
86
112
|
public:
|
87
113
|
ContextProxy(tree::ParseTree* orig) {
|
@@ -96,6 +122,18 @@ module Antlr4Native
|
|
96
122
|
return orig -> getText();
|
97
123
|
}
|
98
124
|
|
125
|
+
Object getStart() {
|
126
|
+
auto token = ((ParserRuleContext*) orig) -> getStart();
|
127
|
+
|
128
|
+
return to_ruby(token);
|
129
|
+
}
|
130
|
+
|
131
|
+
Object getStop() {
|
132
|
+
auto token = ((ParserRuleContext*) orig) -> getStop();
|
133
|
+
|
134
|
+
return to_ruby(token);
|
135
|
+
}
|
136
|
+
|
99
137
|
Array getChildren() {
|
100
138
|
if (children == nullptr) {
|
101
139
|
children = new Array();
|
@@ -191,31 +229,7 @@ module Antlr4Native
|
|
191
229
|
end
|
192
230
|
|
193
231
|
def conversions
|
194
|
-
@conversions ||=
|
195
|
-
context_conversions = contexts.map(&:conversions).join("\n")
|
196
|
-
|
197
|
-
<<~END
|
198
|
-
template <>
|
199
|
-
Object to_ruby<Token*>(Token* const &x) {
|
200
|
-
if (!x) return Nil;
|
201
|
-
return Data_Object<Token>(x, rb_cToken, nullptr, nullptr);
|
202
|
-
}
|
203
|
-
|
204
|
-
template <>
|
205
|
-
Object to_ruby<tree::ParseTree*>(tree::ParseTree* const &x) {
|
206
|
-
if (!x) return Nil;
|
207
|
-
return Data_Object<tree::ParseTree>(x, rb_cParseTree, nullptr, nullptr);
|
208
|
-
}
|
209
|
-
|
210
|
-
template <>
|
211
|
-
Object to_ruby<tree::TerminalNode*>(tree::TerminalNode* const &x) {
|
212
|
-
if (!x) return Nil;
|
213
|
-
return Data_Object<tree::TerminalNode>(x, rb_cTerminalNode, nullptr, nullptr);
|
214
|
-
}
|
215
|
-
|
216
|
-
#{context_conversions}
|
217
|
-
END
|
218
|
-
end
|
232
|
+
@conversions ||= contexts.map(&:conversions).join("\n")
|
219
233
|
end
|
220
234
|
|
221
235
|
def proxy_class_methods
|
@@ -243,14 +257,21 @@ module Antlr4Native
|
|
243
257
|
return parser;
|
244
258
|
}
|
245
259
|
|
246
|
-
|
247
|
-
|
260
|
+
Object #{parser_root_method}() {
|
261
|
+
auto ctx = this -> parser -> #{parser_root_method}();
|
262
|
+
|
263
|
+
#{capitalize(parser_root_method)}ContextProxy proxy((#{parser_ns}::#{capitalize(parser_root_method)}Context*) ctx);
|
264
|
+
return to_ruby(proxy);
|
265
|
+
}
|
266
|
+
|
267
|
+
Object visit(VisitorProxy* visitor) {
|
268
|
+
auto result = visitor -> visit(this -> parser -> #{parser_root_method}());
|
248
269
|
|
249
270
|
// reset for the next visit call
|
250
271
|
this -> lexer -> reset();
|
251
272
|
this -> parser -> reset();
|
252
273
|
|
253
|
-
return
|
274
|
+
return result;
|
254
275
|
}
|
255
276
|
|
256
277
|
~ParserProxy() {
|
@@ -296,12 +317,15 @@ module Antlr4Native
|
|
296
317
|
|
297
318
|
rb_cToken = rb_m#{parser_ns}
|
298
319
|
.define_class<Token>("Token")
|
299
|
-
.define_method("text", &Token::getText)
|
320
|
+
.define_method("text", &Token::getText)
|
321
|
+
.define_method("channel", &Token::getChannel)
|
322
|
+
.define_method("token_index", &Token::getTokenIndex);
|
300
323
|
|
301
324
|
rb_cParser = rb_m#{parser_ns}
|
302
325
|
.define_class<ParserProxy>("Parser")
|
303
326
|
.define_singleton_method("parse", &ParserProxy::parse)
|
304
327
|
.define_singleton_method("parse_file", &ParserProxy::parseFile)
|
328
|
+
.define_method("#{parser_root_method}", &ParserProxy::#{parser_root_method})
|
305
329
|
.define_method("visit", &ParserProxy::visit);
|
306
330
|
|
307
331
|
rb_cParseTree = rb_m#{parser_ns}
|
@@ -312,6 +336,8 @@ module Antlr4Native
|
|
312
336
|
.define_method("children", &ContextProxy::getChildren)
|
313
337
|
.define_method("child_count", &ContextProxy::childCount)
|
314
338
|
.define_method("text", &ContextProxy::getText)
|
339
|
+
.define_method("start", &ContextProxy::getStart)
|
340
|
+
.define_method("stop", &ContextProxy::getStop)
|
315
341
|
.define_method("parent", &ContextProxy::getParent)
|
316
342
|
.define_method("==", &ContextProxy::doubleEquals);
|
317
343
|
|
@@ -46,13 +46,13 @@ module Antlr4Native
|
|
46
46
|
#{cpp_class_name}(Object self) : Director(self) { }
|
47
47
|
|
48
48
|
Object ruby_visit(ContextProxy* proxy) {
|
49
|
-
visit(proxy -> getOriginal());
|
50
|
-
return
|
49
|
+
auto result = visit(proxy -> getOriginal());
|
50
|
+
return result.as<Object>();
|
51
51
|
}
|
52
52
|
|
53
53
|
Object ruby_visitChildren(ContextProxy* proxy) {
|
54
|
-
visitChildren(proxy -> getOriginal());
|
55
|
-
return
|
54
|
+
auto result = visitChildren(proxy -> getOriginal());
|
55
|
+
return result.as<Object>();
|
56
56
|
}
|
57
57
|
|
58
58
|
#{vms.join("\n")}
|
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: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Create a Ruby native extension from any ANTLR4 grammar.
|
14
14
|
email:
|
@@ -33,7 +33,7 @@ files:
|
|
33
33
|
homepage: http://github.com/camertron/antlr4-native-rb
|
34
34
|
licenses: []
|
35
35
|
metadata: {}
|
36
|
-
post_install_message:
|
36
|
+
post_install_message:
|
37
37
|
rdoc_options: []
|
38
38
|
require_paths:
|
39
39
|
- lib
|
@@ -48,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|
51
|
-
rubygems_version: 3.
|
52
|
-
signing_key:
|
51
|
+
rubygems_version: 3.1.2
|
52
|
+
signing_key:
|
53
53
|
specification_version: 4
|
54
54
|
summary: Create a Ruby native extension from any ANTLR4 grammar.
|
55
55
|
test_files: []
|