antlr4-native 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08bed362c4b5695e0e900adb1b9837f284d92e70b7bc2006467bc1888d39f12c'
4
- data.tar.gz: 881aac540b1395c0f3e974f4c3d8a3f747ab695deeba95bd5d40c2c7924c5015
3
+ metadata.gz: 1abe502ed412ef8d9fda78dd371448d290c10bd757c34044c881c110f11c84df
4
+ data.tar.gz: 7093d010f55d0dac4b9b4e3d9a8f0da004ed40d4595caab9623bd717b879c812
5
5
  SHA512:
6
- metadata.gz: d02e7aa15bced54e120e5bef5ff5d2be69919a83a0473e025feca86b7e2ee446e4b808a7d56959f3a6e13a2e55eb0666b805f189ad668fe66b68c49fcf2dcd30
7
- data.tar.gz: bfa38b403307ffe88aff984d1713af1e7716629c0794512a4fcee432f60199510c588345d1f1005cc1be6ce0f4f68d4a97555024b11436739e2347c1d4877fab
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/<name>, where <name> is the name of the parser as defined in the grammar file(s). In this case, PythonParser.g4 contains:
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
 
@@ -148,6 +148,11 @@ module Antlr4Native
148
148
  }
149
149
 
150
150
  auto token = ((#{parser_ns}::#{name}*)orig) -> #{token_mtd.name}(#{params});
151
+
152
+ if (token == nullptr) {
153
+ return Qnil;
154
+ }
155
+
151
156
  TerminalNodeProxy proxy(token);
152
157
  return to_ruby(proxy);
153
158
  }
@@ -63,7 +63,7 @@ module Antlr4Native
63
63
 
64
64
  def interop_code
65
65
  <<~END
66
- #include "iostream"
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 ||= begin
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
- VALUE visit(VisitorProxy* visitor) {
247
- visitor -> visit(this -> parser -> #{parser_root_method}());
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 Qnil;
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
 
@@ -1,3 +1,3 @@
1
1
  module Antlr4Native
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -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 Nil;
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 Nil;
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.2
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-05-02 00:00:00.000000000 Z
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.0.6
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: []