antlr4-native 2.2.0 → 2.3.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 +1 -0
- data/antlr4-native.gemspec +1 -1
- data/lib/antlr4-native/context.rb +4 -4
- data/lib/antlr4-native/generator.rb +22 -9
- data/lib/antlr4-native/version.rb +1 -1
- data/spec/lua-parser-rb/Gemfile +12 -0
- data/spec/lua-parser-rb/Lua.g4 +335 -0
- data/spec/lua-parser-rb/Rakefile +28 -0
- data/spec/lua-parser-rb/ext/lua_parser/extconf.rb +38 -0
- data/spec/lua-parser-rb/lib/lua_parser/version.rb +3 -0
- data/spec/lua-parser-rb/lib/lua_parser.rb +2 -0
- data/spec/lua-parser-rb/lua_parser.gemspec +31 -0
- data/spec/lua-parser-rb/parse_test.rb +20 -0
- data/spec/run-lua-test.sh +5 -0
- metadata +14 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e0ba82bae327f0b02ac099beab9b01d8efef600b21dd1f0bac9438303af8d9fc
|
|
4
|
+
data.tar.gz: f840a00ac13adf1282c77fc2b2376da1b9c986cc32d9affa2232ab0d01c6ae57
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9aec0e46b565763c2e77c6e7af5108e24b7c348afda4d0073a5f99a52813feeb8204b8a554ed3dc500898aa4bb6a023c5646d5f0965c7d0bb25f2acb831889a
|
|
7
|
+
data.tar.gz: 508ed703bf98e7584c998cbed39b73f788a99cf5b65469b9c82d0adba5467c6bc1bed458ad26bde81dc5d32a73ef755a89a9516c9aa36ee5a550a3516dd30a7f
|
data/README.md
CHANGED
|
@@ -79,6 +79,7 @@ Finally, if you override `#initialize` in your visitor subclasses, don't forget
|
|
|
79
79
|
|
|
80
80
|
## Caveats
|
|
81
81
|
|
|
82
|
+
1. Avoid retaining references to contexts, tokens, etc anywhere in your Ruby code. Contexts (i.e. the `ctx` variables in the examples above) and other objects that are created by ANTLR's C++ runtime are automatically cleaned up without the Ruby interpreter's knowledge. You'll almost surely see a segfault if you retain a reference to one of these objects and try to use it after the call to `Parser#visit`.
|
|
82
83
|
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
84
|
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.
|
|
84
85
|
|
data/antlr4-native.gemspec
CHANGED
|
@@ -56,7 +56,7 @@ module Antlr4Native
|
|
|
56
56
|
class To_Ruby<#{parser_ns}::#{name}*> {
|
|
57
57
|
public:
|
|
58
58
|
VALUE convert(#{parser_ns}::#{name}* const &x) {
|
|
59
|
-
if (!x) return
|
|
59
|
+
if (!x) return Qnil;
|
|
60
60
|
return Data_Object<#{parser_ns}::#{name}>(x, false, #{proxy_class_variable});
|
|
61
61
|
}
|
|
62
62
|
};
|
|
@@ -65,7 +65,7 @@ module Antlr4Native
|
|
|
65
65
|
class To_Ruby<#{name}Proxy*> {
|
|
66
66
|
public:
|
|
67
67
|
VALUE convert(#{name}Proxy* const &x) {
|
|
68
|
-
if (!x) return
|
|
68
|
+
if (!x) return Qnil;
|
|
69
69
|
return Data_Object<#{name}Proxy>(x, false, #{proxy_class_variable});
|
|
70
70
|
}
|
|
71
71
|
};
|
|
@@ -114,11 +114,11 @@ module Antlr4Native
|
|
|
114
114
|
|
|
115
115
|
for (auto child : getChildren()) {
|
|
116
116
|
if (ctx == detail::From_Ruby<ContextProxy>().convert(child.value()).getOriginal()) {
|
|
117
|
-
return child;
|
|
117
|
+
return Rice::Object(child);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
return
|
|
121
|
+
return Qnil;
|
|
122
122
|
}
|
|
123
123
|
END
|
|
124
124
|
end
|
|
@@ -97,7 +97,7 @@ module Antlr4Native
|
|
|
97
97
|
class To_Ruby<Token*> {
|
|
98
98
|
public:
|
|
99
99
|
VALUE convert(Token* const &x) {
|
|
100
|
-
if (!x) return
|
|
100
|
+
if (!x) return Qnil;
|
|
101
101
|
return Data_Object<Token>(x, false, rb_cToken);
|
|
102
102
|
}
|
|
103
103
|
};
|
|
@@ -106,7 +106,7 @@ module Antlr4Native
|
|
|
106
106
|
class To_Ruby<tree::ParseTree*> {
|
|
107
107
|
public:
|
|
108
108
|
VALUE convert(tree::ParseTree* const &x) {
|
|
109
|
-
if (!x) return
|
|
109
|
+
if (!x) return Qnil;
|
|
110
110
|
return Data_Object<tree::ParseTree>(x, false, rb_cParseTree);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
@@ -115,7 +115,7 @@ module Antlr4Native
|
|
|
115
115
|
class To_Ruby<tree::TerminalNode*> {
|
|
116
116
|
public:
|
|
117
117
|
VALUE convert(tree::TerminalNode* const &x) {
|
|
118
|
-
if (!x) return
|
|
118
|
+
if (!x) return Qnil;
|
|
119
119
|
return Data_Object<tree::TerminalNode>(x, false, rb_cTerminalNode);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
@@ -153,7 +153,7 @@ module Antlr4Native
|
|
|
153
153
|
for (auto it = orig -> children.begin(); it != orig -> children.end(); it ++) {
|
|
154
154
|
Object parseTree = ContextProxy::wrapParseTree(*it);
|
|
155
155
|
|
|
156
|
-
if (parseTree
|
|
156
|
+
if (!parseTree.is_nil()) {
|
|
157
157
|
children.push(parseTree);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -162,7 +162,7 @@ module Antlr4Native
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
Object getParent() {
|
|
165
|
-
return orig == nullptr ?
|
|
165
|
+
return orig == nullptr ? Rice::Object(Qnil) : ContextProxy::wrapParseTree(orig -> parent);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
size_t childCount() {
|
|
@@ -300,13 +300,26 @@ module Antlr4Native
|
|
|
300
300
|
};
|
|
301
301
|
|
|
302
302
|
namespace Rice::detail {
|
|
303
|
+
template <>
|
|
304
|
+
struct Type<ParserProxy*> {
|
|
305
|
+
static bool verify() {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
303
310
|
template <>
|
|
304
311
|
class To_Ruby<ParserProxy*> {
|
|
305
312
|
public:
|
|
313
|
+
To_Ruby() = default;
|
|
314
|
+
|
|
315
|
+
explicit To_Ruby(Arg* arg) : arg_(arg) {}
|
|
316
|
+
|
|
306
317
|
VALUE convert(ParserProxy* const &x) {
|
|
307
|
-
if (!x) return
|
|
318
|
+
if (!x) return Qnil;
|
|
308
319
|
return Data_Object<ParserProxy>(x, false, rb_cParser);
|
|
309
320
|
}
|
|
321
|
+
private:
|
|
322
|
+
Arg* arg_ = nullptr;
|
|
310
323
|
};
|
|
311
324
|
}
|
|
312
325
|
END
|
|
@@ -346,8 +359,8 @@ module Antlr4Native
|
|
|
346
359
|
rb_cParser = define_class_under<ParserProxy>(rb_m#{parser_ns}, "Parser")
|
|
347
360
|
.define_singleton_function("parse", &ParserProxy::parse)
|
|
348
361
|
.define_singleton_function("parse_file", &ParserProxy::parseFile)
|
|
349
|
-
.define_method("#{parser_root_method}", &ParserProxy::#{parser_root_method}
|
|
350
|
-
.define_method("visit", &ParserProxy::visit
|
|
362
|
+
.define_method("#{parser_root_method}", &ParserProxy::#{parser_root_method})
|
|
363
|
+
.define_method("visit", &ParserProxy::visit);
|
|
351
364
|
|
|
352
365
|
#{class_wrappers_str(' ')}
|
|
353
366
|
}
|
|
@@ -372,7 +385,7 @@ module Antlr4Native
|
|
|
372
385
|
TerminalNodeProxy proxy(node);
|
|
373
386
|
return detail::To_Ruby<TerminalNodeProxy>().convert(proxy);
|
|
374
387
|
} else {
|
|
375
|
-
return
|
|
388
|
+
return Qnil;
|
|
376
389
|
}
|
|
377
390
|
}
|
|
378
391
|
END
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/*
|
|
2
|
+
BSD License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2013, Kazunori Sakamoto
|
|
5
|
+
Copyright (c) 2016, Alexander Alexeev
|
|
6
|
+
All rights reserved.
|
|
7
|
+
|
|
8
|
+
Redistribution and use in source and binary forms, with or without
|
|
9
|
+
modification, are permitted provided that the following conditions
|
|
10
|
+
are met:
|
|
11
|
+
|
|
12
|
+
1. Redistributions of source code must retain the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
3. Neither the NAME of Rainer Schuster nor the NAMEs of its contributors
|
|
18
|
+
may be used to endorse or promote products derived from this software
|
|
19
|
+
without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
22
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
23
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
24
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
25
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
27
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
28
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
29
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
30
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
31
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
|
+
|
|
33
|
+
This grammar file derived from:
|
|
34
|
+
|
|
35
|
+
Lua 5.3 Reference Manual
|
|
36
|
+
http://www.lua.org/manual/5.3/manual.html
|
|
37
|
+
|
|
38
|
+
Lua 5.2 Reference Manual
|
|
39
|
+
http://www.lua.org/manual/5.2/manual.html
|
|
40
|
+
|
|
41
|
+
Lua 5.1 grammar written by Nicolai Mainiero
|
|
42
|
+
http://www.antlr3.org/grammar/1178608849736/Lua.g
|
|
43
|
+
|
|
44
|
+
Tested by Kazunori Sakamoto with Test suite for Lua 5.2 (http://www.lua.org/tests/5.2/)
|
|
45
|
+
|
|
46
|
+
Tested by Alexander Alexeev with Test suite for Lua 5.3 http://www.lua.org/tests/lua-5.3.2-tests.tar.gz
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
grammar Lua;
|
|
50
|
+
|
|
51
|
+
chunk
|
|
52
|
+
: block EOF
|
|
53
|
+
;
|
|
54
|
+
|
|
55
|
+
block
|
|
56
|
+
: stat* retstat?
|
|
57
|
+
;
|
|
58
|
+
|
|
59
|
+
stat
|
|
60
|
+
: ';'
|
|
61
|
+
| varlist '=' explist
|
|
62
|
+
| functioncall
|
|
63
|
+
| label
|
|
64
|
+
| 'break'
|
|
65
|
+
| 'goto' NAME
|
|
66
|
+
| 'do' block 'end'
|
|
67
|
+
| 'while' exp 'do' block 'end'
|
|
68
|
+
| 'repeat' block 'until' exp
|
|
69
|
+
| 'if' exp 'then' block ('elseif' exp 'then' block)* ('else' block)? 'end'
|
|
70
|
+
| 'for' NAME '=' exp ',' exp (',' exp)? 'do' block 'end'
|
|
71
|
+
| 'for' namelist 'in' explist 'do' block 'end'
|
|
72
|
+
| 'function' funcname funcbody
|
|
73
|
+
| 'local' 'function' NAME funcbody
|
|
74
|
+
| 'local' namelist ('=' explist)?
|
|
75
|
+
;
|
|
76
|
+
|
|
77
|
+
retstat
|
|
78
|
+
: 'return' explist? ';'?
|
|
79
|
+
;
|
|
80
|
+
|
|
81
|
+
label
|
|
82
|
+
: '::' NAME '::'
|
|
83
|
+
;
|
|
84
|
+
|
|
85
|
+
funcname
|
|
86
|
+
: NAME ('.' NAME)* (':' NAME)?
|
|
87
|
+
;
|
|
88
|
+
|
|
89
|
+
varlist
|
|
90
|
+
: var (',' var)*
|
|
91
|
+
;
|
|
92
|
+
|
|
93
|
+
namelist
|
|
94
|
+
: NAME (',' NAME)*
|
|
95
|
+
;
|
|
96
|
+
|
|
97
|
+
explist
|
|
98
|
+
: exp (',' exp)*
|
|
99
|
+
;
|
|
100
|
+
|
|
101
|
+
exp
|
|
102
|
+
: 'nil' | 'false' | 'true'
|
|
103
|
+
| number
|
|
104
|
+
| string
|
|
105
|
+
| '...'
|
|
106
|
+
| functiondef
|
|
107
|
+
| prefixexp
|
|
108
|
+
| tableconstructor
|
|
109
|
+
| <assoc=right> exp operatorPower exp
|
|
110
|
+
| operatorUnary exp
|
|
111
|
+
| exp operatorMulDivMod exp
|
|
112
|
+
| exp operatorAddSub exp
|
|
113
|
+
| <assoc=right> exp operatorStrcat exp
|
|
114
|
+
| exp operatorComparison exp
|
|
115
|
+
| exp operatorAnd exp
|
|
116
|
+
| exp operatorOr exp
|
|
117
|
+
| exp operatorBitwise exp
|
|
118
|
+
;
|
|
119
|
+
|
|
120
|
+
prefixexp
|
|
121
|
+
: varOrExp nameAndArgs*
|
|
122
|
+
;
|
|
123
|
+
|
|
124
|
+
functioncall
|
|
125
|
+
: varOrExp nameAndArgs+
|
|
126
|
+
;
|
|
127
|
+
|
|
128
|
+
varOrExp
|
|
129
|
+
: var | '(' exp ')'
|
|
130
|
+
;
|
|
131
|
+
|
|
132
|
+
var
|
|
133
|
+
: (NAME | '(' exp ')' varSuffix) varSuffix*
|
|
134
|
+
;
|
|
135
|
+
|
|
136
|
+
varSuffix
|
|
137
|
+
: nameAndArgs* ('[' exp ']' | '.' NAME)
|
|
138
|
+
;
|
|
139
|
+
|
|
140
|
+
nameAndArgs
|
|
141
|
+
: (':' NAME)? args
|
|
142
|
+
;
|
|
143
|
+
|
|
144
|
+
/*
|
|
145
|
+
var
|
|
146
|
+
: NAME | prefixexp '[' exp ']' | prefixexp '.' NAME
|
|
147
|
+
;
|
|
148
|
+
|
|
149
|
+
prefixexp
|
|
150
|
+
: var | functioncall | '(' exp ')'
|
|
151
|
+
;
|
|
152
|
+
|
|
153
|
+
functioncall
|
|
154
|
+
: prefixexp args | prefixexp ':' NAME args
|
|
155
|
+
;
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
args
|
|
159
|
+
: '(' explist? ')' | tableconstructor | string
|
|
160
|
+
;
|
|
161
|
+
|
|
162
|
+
functiondef
|
|
163
|
+
: 'function' funcbody
|
|
164
|
+
;
|
|
165
|
+
|
|
166
|
+
funcbody
|
|
167
|
+
: '(' parlist? ')' block 'end'
|
|
168
|
+
;
|
|
169
|
+
|
|
170
|
+
parlist
|
|
171
|
+
: namelist (',' '...')? | '...'
|
|
172
|
+
;
|
|
173
|
+
|
|
174
|
+
tableconstructor
|
|
175
|
+
: '{' fieldlist? '}'
|
|
176
|
+
;
|
|
177
|
+
|
|
178
|
+
fieldlist
|
|
179
|
+
: field (fieldsep field)* fieldsep?
|
|
180
|
+
;
|
|
181
|
+
|
|
182
|
+
field
|
|
183
|
+
: '[' exp ']' '=' exp | NAME '=' exp | exp
|
|
184
|
+
;
|
|
185
|
+
|
|
186
|
+
fieldsep
|
|
187
|
+
: ',' | ';'
|
|
188
|
+
;
|
|
189
|
+
|
|
190
|
+
operatorOr
|
|
191
|
+
: 'or';
|
|
192
|
+
|
|
193
|
+
operatorAnd
|
|
194
|
+
: 'and';
|
|
195
|
+
|
|
196
|
+
operatorComparison
|
|
197
|
+
: '<' | '>' | '<=' | '>=' | '~=' | '==';
|
|
198
|
+
|
|
199
|
+
operatorStrcat
|
|
200
|
+
: '..';
|
|
201
|
+
|
|
202
|
+
operatorAddSub
|
|
203
|
+
: '+' | '-';
|
|
204
|
+
|
|
205
|
+
operatorMulDivMod
|
|
206
|
+
: '*' | '/' | '%' | '//';
|
|
207
|
+
|
|
208
|
+
operatorBitwise
|
|
209
|
+
: '&' | '|' | '~' | '<<' | '>>';
|
|
210
|
+
|
|
211
|
+
operatorUnary
|
|
212
|
+
: 'not' | '#' | '-' | '~';
|
|
213
|
+
|
|
214
|
+
operatorPower
|
|
215
|
+
: '^';
|
|
216
|
+
|
|
217
|
+
number
|
|
218
|
+
: INT | HEX | FLOAT | HEX_FLOAT
|
|
219
|
+
;
|
|
220
|
+
|
|
221
|
+
string
|
|
222
|
+
: NORMALSTRING | CHARSTRING | LONGSTRING
|
|
223
|
+
;
|
|
224
|
+
|
|
225
|
+
// LEXER
|
|
226
|
+
|
|
227
|
+
NAME
|
|
228
|
+
: [a-zA-Z_][a-zA-Z_0-9]*
|
|
229
|
+
;
|
|
230
|
+
|
|
231
|
+
NORMALSTRING
|
|
232
|
+
: '"' ( EscapeSequence | ~('\\'|'"') )* '"'
|
|
233
|
+
;
|
|
234
|
+
|
|
235
|
+
CHARSTRING
|
|
236
|
+
: '\'' ( EscapeSequence | ~('\''|'\\') )* '\''
|
|
237
|
+
;
|
|
238
|
+
|
|
239
|
+
LONGSTRING
|
|
240
|
+
: '[' NESTED_STR ']'
|
|
241
|
+
;
|
|
242
|
+
|
|
243
|
+
fragment
|
|
244
|
+
NESTED_STR
|
|
245
|
+
: '=' NESTED_STR '='
|
|
246
|
+
| '[' .*? ']'
|
|
247
|
+
;
|
|
248
|
+
|
|
249
|
+
INT
|
|
250
|
+
: Digit+
|
|
251
|
+
;
|
|
252
|
+
|
|
253
|
+
HEX
|
|
254
|
+
: '0' [xX] HexDigit+
|
|
255
|
+
;
|
|
256
|
+
|
|
257
|
+
FLOAT
|
|
258
|
+
: Digit+ '.' Digit* ExponentPart?
|
|
259
|
+
| '.' Digit+ ExponentPart?
|
|
260
|
+
| Digit+ ExponentPart
|
|
261
|
+
;
|
|
262
|
+
|
|
263
|
+
HEX_FLOAT
|
|
264
|
+
: '0' [xX] HexDigit+ '.' HexDigit* HexExponentPart?
|
|
265
|
+
| '0' [xX] '.' HexDigit+ HexExponentPart?
|
|
266
|
+
| '0' [xX] HexDigit+ HexExponentPart
|
|
267
|
+
;
|
|
268
|
+
|
|
269
|
+
fragment
|
|
270
|
+
ExponentPart
|
|
271
|
+
: [eE] [+-]? Digit+
|
|
272
|
+
;
|
|
273
|
+
|
|
274
|
+
fragment
|
|
275
|
+
HexExponentPart
|
|
276
|
+
: [pP] [+-]? Digit+
|
|
277
|
+
;
|
|
278
|
+
|
|
279
|
+
fragment
|
|
280
|
+
EscapeSequence
|
|
281
|
+
: '\\' [abfnrtvz"'\\]
|
|
282
|
+
| '\\' '\r'? '\n'
|
|
283
|
+
| DecimalEscape
|
|
284
|
+
| HexEscape
|
|
285
|
+
| UtfEscape
|
|
286
|
+
;
|
|
287
|
+
|
|
288
|
+
fragment
|
|
289
|
+
DecimalEscape
|
|
290
|
+
: '\\' Digit
|
|
291
|
+
| '\\' Digit Digit
|
|
292
|
+
| '\\' [0-2] Digit Digit
|
|
293
|
+
;
|
|
294
|
+
|
|
295
|
+
fragment
|
|
296
|
+
HexEscape
|
|
297
|
+
: '\\' 'x' HexDigit HexDigit
|
|
298
|
+
;
|
|
299
|
+
|
|
300
|
+
fragment
|
|
301
|
+
UtfEscape
|
|
302
|
+
: '\\' 'u{' HexDigit+ '}'
|
|
303
|
+
;
|
|
304
|
+
|
|
305
|
+
fragment
|
|
306
|
+
Digit
|
|
307
|
+
: [0-9]
|
|
308
|
+
;
|
|
309
|
+
|
|
310
|
+
fragment
|
|
311
|
+
HexDigit
|
|
312
|
+
: [0-9a-fA-F]
|
|
313
|
+
;
|
|
314
|
+
|
|
315
|
+
COMMENT
|
|
316
|
+
: '--[' NESTED_STR ']' -> channel(HIDDEN)
|
|
317
|
+
;
|
|
318
|
+
|
|
319
|
+
LINE_COMMENT
|
|
320
|
+
: '--'
|
|
321
|
+
( // --
|
|
322
|
+
| '[' '='* // --[==
|
|
323
|
+
| '[' '='* ~('='|'['|'\r'|'\n') ~('\r'|'\n')* // --[==AA
|
|
324
|
+
| ~('['|'\r'|'\n') ~('\r'|'\n')* // --AAA
|
|
325
|
+
) ('\r\n'|'\r'|'\n'|EOF)
|
|
326
|
+
-> channel(HIDDEN)
|
|
327
|
+
;
|
|
328
|
+
|
|
329
|
+
WS
|
|
330
|
+
: [ \t\u000C\r\n]+ -> skip
|
|
331
|
+
;
|
|
332
|
+
|
|
333
|
+
SHEBANG
|
|
334
|
+
: '#' '!' ~('\n'|'\r')* -> channel(HIDDEN)
|
|
335
|
+
;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
require 'antlr4-native'
|
|
4
|
+
require 'etc'
|
|
5
|
+
|
|
6
|
+
def ruby_installer?
|
|
7
|
+
Object.const_defined?(:RubyInstaller)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
Bundler::GemHelper.install_tasks
|
|
11
|
+
|
|
12
|
+
task :generate do
|
|
13
|
+
generator = Antlr4Native::Generator.new(
|
|
14
|
+
grammar_files: ["./Lua.g4"],
|
|
15
|
+
output_dir: 'ext/',
|
|
16
|
+
parser_root_method: 'chunk'
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
generator.generate
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
task :compile do
|
|
23
|
+
Dir.chdir(File.join(%w(ext lua_parser))) do
|
|
24
|
+
load 'extconf.rb'
|
|
25
|
+
RubyInstaller::Runtime.enable_msys_apps if ruby_installer?
|
|
26
|
+
exec "make -j #{Etc.nprocessors}"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'mkmf-rice'
|
|
2
|
+
|
|
3
|
+
extension_name = 'lua_parser'
|
|
4
|
+
dir_config(extension_name)
|
|
5
|
+
|
|
6
|
+
have_library('stdc++')
|
|
7
|
+
|
|
8
|
+
$CFLAGS << ' -std=c++14'
|
|
9
|
+
|
|
10
|
+
if enable_config('static')
|
|
11
|
+
$defs.push '-DANTLR4CPP_STATIC' unless $defs.include?('-DANTLR4CPP_STATIC')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
include_paths = [
|
|
15
|
+
'.',
|
|
16
|
+
'antlrgen',
|
|
17
|
+
'antlr4-upstream/runtime/Cpp/runtime/src',
|
|
18
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/atn',
|
|
19
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/dfa',
|
|
20
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/misc',
|
|
21
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/support',
|
|
22
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/tree',
|
|
23
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern',
|
|
24
|
+
'antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath'
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
$srcs = []
|
|
28
|
+
|
|
29
|
+
include_paths.each do |include_path|
|
|
30
|
+
$INCFLAGS << " -I#{include_path}"
|
|
31
|
+
$VPATH << include_path
|
|
32
|
+
|
|
33
|
+
Dir.glob("#{include_path}/*.cpp").each do |path|
|
|
34
|
+
$srcs << path
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
create_makefile(extension_name)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
|
2
|
+
require 'lua_parser/version'
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = 'lua_parser'
|
|
6
|
+
s.version = ::LuaParser::VERSION
|
|
7
|
+
s.authors = ['Mickey Mouse']
|
|
8
|
+
s.email = ['mickey@disney.com']
|
|
9
|
+
s.homepage = 'https://github.com/mickeymouse/lua-parser-rb'
|
|
10
|
+
|
|
11
|
+
s.description = s.summary = 'A Lua parser for Ruby'
|
|
12
|
+
|
|
13
|
+
s.platform = Gem::Platform::RUBY
|
|
14
|
+
|
|
15
|
+
s.add_dependency 'rice', '~> 4.0'
|
|
16
|
+
|
|
17
|
+
s.extensions = File.join(*%w(ext lua_parser extconf.rb))
|
|
18
|
+
|
|
19
|
+
s.require_path = 'lib'
|
|
20
|
+
s.files = Dir[
|
|
21
|
+
'{lib,spec}/**/*',
|
|
22
|
+
'ext/lua_parser/*.{cpp,h}',
|
|
23
|
+
'ext/lua_parser/extconf.rb',
|
|
24
|
+
'ext/lua_parser/antlrgen/*',
|
|
25
|
+
'ext/lua_parser/antlr4-upstream/runtime/Cpp/runtime/src/**/*.{cpp,h}',
|
|
26
|
+
'Gemfile',
|
|
27
|
+
'README.md',
|
|
28
|
+
'Rakefile',
|
|
29
|
+
'lua_parser.gemspec'
|
|
30
|
+
]
|
|
31
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lua_parser"
|
|
4
|
+
|
|
5
|
+
class FuncVisitor < LuaParser::Visitor
|
|
6
|
+
def visit_functioncall(ctx)
|
|
7
|
+
puts ctx.var_or_exp.text
|
|
8
|
+
visit_children(ctx)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
Dir.glob('lua/**/*.lua').each do |file_name|
|
|
13
|
+
# this file contains some weird non-UTF8 strings, so let's just skip it
|
|
14
|
+
next if File.basename(file_name) == "strings.lua"
|
|
15
|
+
|
|
16
|
+
lua_code = File.read(file_name)
|
|
17
|
+
parser = LuaParser::Parser.parse(lua_code)
|
|
18
|
+
visitor = FuncVisitor.new
|
|
19
|
+
parser.visit(visitor)
|
|
20
|
+
end
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#! /bin/bash
|
|
2
|
+
|
|
3
|
+
antlr_version=$(bundle exec ruby -Ilib -rantlr4-native -e "puts Antlr4Native::Generator::ANTLR_VERSION")
|
|
4
|
+
docker build --build-arg ANTLR_VERSION="${antlr_version}" -t antlr4-native-rb:latest .
|
|
5
|
+
docker run -t antlr4-native-rb:latest bundle exec ruby parse_test.rb
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: antlr4-native
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cameron Dutro
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rice
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '4.
|
|
18
|
+
version: '4.11'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '4.
|
|
25
|
+
version: '4.11'
|
|
27
26
|
description: Create a Ruby native extension from any ANTLR4 grammar.
|
|
28
27
|
email:
|
|
29
28
|
- camertron@gmail.com
|
|
@@ -43,11 +42,19 @@ files:
|
|
|
43
42
|
- lib/antlr4-native/string_helpers.rb
|
|
44
43
|
- lib/antlr4-native/version.rb
|
|
45
44
|
- lib/antlr4-native/visitor_generator.rb
|
|
45
|
+
- spec/lua-parser-rb/Gemfile
|
|
46
|
+
- spec/lua-parser-rb/Lua.g4
|
|
47
|
+
- spec/lua-parser-rb/Rakefile
|
|
48
|
+
- spec/lua-parser-rb/ext/lua_parser/extconf.rb
|
|
49
|
+
- spec/lua-parser-rb/lib/lua_parser.rb
|
|
50
|
+
- spec/lua-parser-rb/lib/lua_parser/version.rb
|
|
51
|
+
- spec/lua-parser-rb/lua_parser.gemspec
|
|
52
|
+
- spec/lua-parser-rb/parse_test.rb
|
|
53
|
+
- spec/run-lua-test.sh
|
|
46
54
|
- vendor/antlr-4.10.1-complete.jar
|
|
47
55
|
homepage: http://github.com/camertron/antlr4-native-rb
|
|
48
56
|
licenses: []
|
|
49
57
|
metadata: {}
|
|
50
|
-
post_install_message:
|
|
51
58
|
rdoc_options: []
|
|
52
59
|
require_paths:
|
|
53
60
|
- lib
|
|
@@ -62,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
62
69
|
- !ruby/object:Gem::Version
|
|
63
70
|
version: '0'
|
|
64
71
|
requirements: []
|
|
65
|
-
rubygems_version: 3.
|
|
66
|
-
signing_key:
|
|
72
|
+
rubygems_version: 3.6.7
|
|
67
73
|
specification_version: 4
|
|
68
74
|
summary: Create a Ruby native extension from any ANTLR4 grammar.
|
|
69
75
|
test_files: []
|