ruby-ll 2.0.0-java → 2.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -4
- data/ext/c/driver.c +22 -0
- data/ext/java/org/libll/Driver.java +23 -0
- data/lib/libll.jar +0 -0
- data/lib/ll/configuration_compiler.rb +13 -3
- data/lib/ll/driver.rb +2 -0
- data/lib/ll/grammar_compiler.rb +21 -0
- data/lib/ll/lexer.rb +55 -49
- data/lib/ll/parser.rb +131 -158
- data/lib/ll/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3c66d4523120a5e1f5ef8c6c32f45915c072d8
|
4
|
+
data.tar.gz: 49d49c6a297f2e2f5a0ac1514b232e7cfa4253ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f910a5007ee6a672b5b5ac517ed70c82843ace40f44d241a22c039d984b33fea351488eae1af64bfc88d8d41236ad81fc01dae55afb58d2ae0e3fb8371dcc12b
|
7
|
+
data.tar.gz: 7f20ee290e31e4c16a08bd1c438c80cadccb722b6096a37154092eff0420e250ca2238aa5f405b4dcd412242993c13d46e15ab3f701fbe802c375e34eb120835
|
data/README.md
CHANGED
@@ -20,9 +20,10 @@ For more information on LL parsing, see
|
|
20
20
|
|
21
21
|
## Features
|
22
22
|
|
23
|
-
* Support for detecting first/first and first/follow conflicts
|
24
|
-
* clang-like error/warning messages to ease debugging parsers
|
25
|
-
* High performance and a low memory footprint
|
23
|
+
* Support for detecting first/first and first/follow conflicts.
|
24
|
+
* clang-like error/warning messages to ease debugging parsers.
|
25
|
+
* High performance and a low memory footprint.
|
26
|
+
* Support for the `*`, `+` and `?` operators.
|
26
27
|
|
27
28
|
## Requirements
|
28
29
|
|
@@ -326,7 +327,8 @@ It's also an error to re-define an existing rule.
|
|
326
327
|
### Operators
|
327
328
|
|
328
329
|
Grammars can use two operators to define a sequence of terminals/non-terminals:
|
329
|
-
the star (`*`) and plus (`+`) operators.
|
330
|
+
the star (`*`) and plus (`+`) operators. There's also the `?` (question)
|
331
|
+
operator which can be used to indicate something as being optional.
|
330
332
|
|
331
333
|
The star operator indicates that something should occur 0 or more times. Here
|
332
334
|
the "B" identifier could occur 0 times, once, twice or many more times:
|
@@ -339,6 +341,17 @@ should occur at least once but can also occur, say, 10 times:
|
|
339
341
|
|
340
342
|
A = B+;
|
341
343
|
|
344
|
+
The question operator can be used as an alternative to the following pattern:
|
345
|
+
|
346
|
+
# "A" or "A C"
|
347
|
+
A = B A_follow;
|
348
|
+
|
349
|
+
A_follow = C | _;
|
350
|
+
|
351
|
+
Using this operator you can simply write the following:
|
352
|
+
|
353
|
+
A = B C?;
|
354
|
+
|
342
355
|
Operators can be applied either to a single terminal/rule or a series of
|
343
356
|
terminals/rules grouped together using parenthesis. For example, both are
|
344
357
|
perfectly valid:
|
data/ext/c/driver.c
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
#define T_PLUS 5
|
10
10
|
#define T_ADD_VALUE_STACK 6
|
11
11
|
#define T_APPEND_VALUE_STACK 7
|
12
|
+
#define T_QUESTION 8
|
12
13
|
|
13
14
|
ID id_config_const;
|
14
15
|
ID id_each_token;
|
@@ -184,6 +185,27 @@ VALUE ll_driver_each_token(VALUE token, VALUE self)
|
|
184
185
|
}
|
185
186
|
}
|
186
187
|
}
|
188
|
+
/* "?" operator */
|
189
|
+
else if ( stack_type == T_QUESTION )
|
190
|
+
{
|
191
|
+
production_i = state->config->table[stack_value][token_id];
|
192
|
+
|
193
|
+
if ( production_i == T_EOF )
|
194
|
+
{
|
195
|
+
kv_push(VALUE, state->value_stack, Qnil);
|
196
|
+
}
|
197
|
+
else
|
198
|
+
{
|
199
|
+
FOR(rule_i, state->config->rule_lengths[production_i])
|
200
|
+
{
|
201
|
+
kv_push(
|
202
|
+
long,
|
203
|
+
state->stack,
|
204
|
+
state->config->rules[production_i][rule_i]
|
205
|
+
);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
187
209
|
/*
|
188
210
|
Adds a new array to the value stack that can be used to group operator
|
189
211
|
values together
|
@@ -36,6 +36,7 @@ public class Driver extends RubyObject
|
|
36
36
|
private static long T_PLUS = 5;
|
37
37
|
private static long T_ADD_VALUE_STACK = 6;
|
38
38
|
private static long T_APPEND_VALUE_STACK = 7;
|
39
|
+
private static long T_QUESTION = 8;
|
39
40
|
|
40
41
|
/**
|
41
42
|
* The current Ruby runtime.
|
@@ -200,6 +201,28 @@ public class Driver extends RubyObject
|
|
200
201
|
}
|
201
202
|
}
|
202
203
|
}
|
204
|
+
// "?" operator
|
205
|
+
else if ( stack_type == self.T_QUESTION )
|
206
|
+
{
|
207
|
+
Long production_i = self.config.table
|
208
|
+
.get(stack_value.intValue())
|
209
|
+
.get(token_id.intValue());
|
210
|
+
|
211
|
+
if ( production_i == self.T_EOF )
|
212
|
+
{
|
213
|
+
value_stack.push(context.nil);
|
214
|
+
}
|
215
|
+
else
|
216
|
+
{
|
217
|
+
ArrayList<Long> row = self.config.rules
|
218
|
+
.get(production_i.intValue());
|
219
|
+
|
220
|
+
for ( int index = 0; index < row.size(); index++ )
|
221
|
+
{
|
222
|
+
stack.push(row.get(index));
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
203
226
|
// Adds a new array to the value stack that can be used to
|
204
227
|
// group operator values together
|
205
228
|
else if ( stack_type == self.T_ADD_VALUE_STACK )
|
data/lib/libll.jar
CHANGED
Binary file
|
@@ -16,9 +16,17 @@ module LL
|
|
16
16
|
:star => 4,
|
17
17
|
:plus => 5,
|
18
18
|
:add_value_stack => 6,
|
19
|
-
:append_value_stack => 7
|
19
|
+
:append_value_stack => 7,
|
20
|
+
:question => 8
|
20
21
|
}.freeze
|
21
22
|
|
23
|
+
##
|
24
|
+
# Operators which don't require a value stack.
|
25
|
+
#
|
26
|
+
# @return [Array]
|
27
|
+
#
|
28
|
+
SKIP_VALUE_STACK = [:question]
|
29
|
+
|
22
30
|
##
|
23
31
|
# @return [String]
|
24
32
|
#
|
@@ -167,8 +175,10 @@ module LL
|
|
167
175
|
row << TYPES[step.type]
|
168
176
|
row << rule_indices[step.receiver]
|
169
177
|
|
170
|
-
|
171
|
-
|
178
|
+
unless SKIP_VALUE_STACK.include?(step.type)
|
179
|
+
row << TYPES[:add_value_stack]
|
180
|
+
row << 0
|
181
|
+
end
|
172
182
|
end
|
173
183
|
end
|
174
184
|
|
data/lib/ll/driver.rb
CHANGED
data/lib/ll/grammar_compiler.rb
CHANGED
@@ -362,6 +362,27 @@ module LL
|
|
362
362
|
return Operator.new(:plus, rule, node.source_line)
|
363
363
|
end
|
364
364
|
|
365
|
+
##
|
366
|
+
# Processes the "?" operator.
|
367
|
+
#
|
368
|
+
# @param [LL::AST::Node] node
|
369
|
+
# @param [LL::CompiledGrammar] compiled_grammar
|
370
|
+
# @return [LL::Operator]
|
371
|
+
#
|
372
|
+
def on_question(node, compiled_grammar)
|
373
|
+
steps = lookup_identifiers(node, compiled_grammar)
|
374
|
+
name = "_ll_question#{node.source_line.line}#{node.source_line.column}"
|
375
|
+
rule = Rule.new(name, node.source_line)
|
376
|
+
|
377
|
+
rule.add_branch(steps, node.source_line)
|
378
|
+
|
379
|
+
rule.increment_references
|
380
|
+
|
381
|
+
compiled_grammar.add_rule(rule)
|
382
|
+
|
383
|
+
return Operator.new(:question, rule, node.source_line)
|
384
|
+
end
|
385
|
+
|
365
386
|
private
|
366
387
|
|
367
388
|
##
|
data/lib/ll/lexer.rb
CHANGED
@@ -67,46 +67,46 @@ self._ll_lexer_indicies = [
|
|
67
67
|
1, 28, 1, 29, 1, 1, 30, 31,
|
68
68
|
32, 33, 1, 1, 1, 1, 25, 25,
|
69
69
|
25, 25, 25, 25, 25, 25, 25, 25,
|
70
|
-
34, 35, 1, 36, 1,
|
70
|
+
34, 35, 1, 36, 1, 37, 1, 25,
|
71
71
|
25, 25, 25, 25, 25, 25, 25, 25,
|
72
72
|
25, 25, 25, 25, 25, 25, 25, 25,
|
73
73
|
25, 25, 25, 25, 25, 25, 25, 25,
|
74
|
-
25, 1, 1, 1, 1,
|
74
|
+
25, 1, 1, 1, 1, 38, 1, 25,
|
75
75
|
25, 25, 25, 25, 25, 25, 25, 25,
|
76
76
|
25, 25, 25, 25, 25, 25, 25, 25,
|
77
77
|
25, 25, 25, 25, 25, 25, 25, 25,
|
78
|
-
25,
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
25, 39, 40, 1, 1, 1, 25, 41,
|
79
|
+
41, 41, 41, 41, 41, 41, 41, 41,
|
80
|
+
41, 41, 41, 41, 41, 41, 41, 41,
|
81
|
+
41, 41, 41, 41, 41, 41, 41, 41,
|
82
|
+
41, 41, 41, 41, 41, 41, 41, 41,
|
83
|
+
41, 41, 41, 41, 41, 41, 41, 41,
|
84
|
+
41, 41, 41, 41, 41, 41, 41, 25,
|
85
85
|
25, 25, 25, 25, 25, 25, 25, 25,
|
86
|
-
25,
|
86
|
+
25, 41, 41, 41, 41, 41, 41, 41,
|
87
87
|
25, 25, 25, 25, 25, 25, 25, 25,
|
88
88
|
25, 25, 25, 25, 25, 25, 25, 25,
|
89
89
|
25, 25, 25, 25, 25, 25, 25, 25,
|
90
|
-
25, 25,
|
90
|
+
25, 25, 41, 41, 41, 41, 25, 41,
|
91
91
|
25, 25, 25, 25, 25, 25, 25, 25,
|
92
92
|
25, 25, 25, 25, 25, 25, 25, 25,
|
93
93
|
25, 25, 25, 25, 25, 25, 25, 25,
|
94
|
-
25, 25,
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
94
|
+
25, 25, 41, 41, 41, 41, 41, 25,
|
95
|
+
42, 28, 44, 43, 43, 43, 43, 43,
|
96
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
97
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
98
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
99
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
100
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
101
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
102
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
103
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
104
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
105
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
106
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
107
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
108
|
+
43, 43, 43, 43, 43, 43, 43, 43,
|
109
|
+
43, 43, 43, 45, 43, 46, 43, 0
|
110
110
|
]
|
111
111
|
|
112
112
|
class << self
|
@@ -118,8 +118,8 @@ self._ll_lexer_trans_targs = [
|
|
118
118
|
6, 22, 8, 9, 10, 22, 12, 13,
|
119
119
|
22, 15, 16, 17, 18, 19, 20, 21,
|
120
120
|
22, 23, 22, 22, 24, 1, 22, 22,
|
121
|
-
22, 22, 22, 22, 22,
|
122
|
-
22, 22, 25, 25, 25, 25
|
121
|
+
22, 22, 22, 22, 22, 22, 23, 22,
|
122
|
+
22, 22, 22, 25, 25, 25, 25
|
123
123
|
]
|
124
124
|
|
125
125
|
class << self
|
@@ -132,7 +132,7 @@ self._ll_lexer_trans_actions = [
|
|
132
132
|
3, 0, 0, 0, 0, 0, 0, 0,
|
133
133
|
4, 7, 8, 9, 0, 0, 10, 11,
|
134
134
|
12, 13, 14, 15, 16, 17, 18, 19,
|
135
|
-
20, 21, 22, 23, 24, 25
|
135
|
+
20, 21, 22, 23, 24, 25, 26
|
136
136
|
]
|
137
137
|
|
138
138
|
class << self
|
@@ -164,8 +164,8 @@ end
|
|
164
164
|
self._ll_lexer_eof_trans = [
|
165
165
|
0, 0, 0, 0, 0, 0, 0, 0,
|
166
166
|
0, 0, 0, 0, 0, 0, 0, 0,
|
167
|
-
0, 0, 0, 0, 0, 0, 0,
|
168
|
-
|
167
|
+
0, 0, 0, 0, 0, 0, 0, 42,
|
168
|
+
43, 0
|
169
169
|
]
|
170
170
|
|
171
171
|
class << self
|
@@ -312,13 +312,13 @@ ts = p
|
|
312
312
|
cs = _ll_lexer_trans_targs[_trans]
|
313
313
|
if _ll_lexer_trans_actions[_trans] != 0
|
314
314
|
case _ll_lexer_trans_actions[_trans]
|
315
|
-
when
|
315
|
+
when 25 then
|
316
316
|
# line 188 "lib/ll/lexer.rl"
|
317
317
|
begin
|
318
318
|
te = p+1
|
319
319
|
begin brace_count += 1 end
|
320
320
|
end
|
321
|
-
when
|
321
|
+
when 26 then
|
322
322
|
# line 190 "lib/ll/lexer.rl"
|
323
323
|
begin
|
324
324
|
te = p+1
|
@@ -338,7 +338,7 @@ te = p+1
|
|
338
338
|
end
|
339
339
|
end
|
340
340
|
end
|
341
|
-
when
|
341
|
+
when 23 then
|
342
342
|
# line 206 "lib/ll/lexer.rl"
|
343
343
|
begin
|
344
344
|
te = p+1
|
@@ -385,7 +385,7 @@ te = p+1
|
|
385
385
|
te = p+1
|
386
386
|
begin emit(:T_SEMICOLON, ts, te) end
|
387
387
|
end
|
388
|
-
when
|
388
|
+
when 20 then
|
389
389
|
# line 223 "lib/ll/lexer.rl"
|
390
390
|
begin
|
391
391
|
te = p+1
|
@@ -403,20 +403,26 @@ te = p+1
|
|
403
403
|
te = p+1
|
404
404
|
begin emit(:T_STAR, ts, te) end
|
405
405
|
end
|
406
|
-
when
|
406
|
+
when 17 then
|
407
407
|
# line 227 "lib/ll/lexer.rl"
|
408
408
|
begin
|
409
|
+
te = p+1
|
410
|
+
begin emit(:T_QUESTION, ts, te) end
|
411
|
+
end
|
412
|
+
when 10 then
|
413
|
+
# line 228 "lib/ll/lexer.rl"
|
414
|
+
begin
|
409
415
|
te = p+1
|
410
416
|
begin emit(:T_LPAREN, ts, te) end
|
411
417
|
end
|
412
418
|
when 11 then
|
413
|
-
# line
|
419
|
+
# line 229 "lib/ll/lexer.rl"
|
414
420
|
begin
|
415
421
|
te = p+1
|
416
422
|
begin emit(:T_RPAREN, ts, te) end
|
417
423
|
end
|
418
|
-
when
|
419
|
-
# line
|
424
|
+
when 19 then
|
425
|
+
# line 231 "lib/ll/lexer.rl"
|
420
426
|
begin
|
421
427
|
te = p+1
|
422
428
|
begin
|
@@ -429,26 +435,26 @@ te = p+1
|
|
429
435
|
cs = 25;
|
430
436
|
end
|
431
437
|
end
|
432
|
-
when
|
438
|
+
when 22 then
|
433
439
|
# line 213 "lib/ll/lexer.rl"
|
434
440
|
begin
|
435
441
|
te = p
|
436
442
|
p = p - 1; end
|
437
|
-
when
|
443
|
+
when 21 then
|
438
444
|
# line 1 "NONE"
|
439
445
|
begin
|
440
446
|
case act
|
441
447
|
when 16 then
|
442
448
|
begin begin p = ((te))-1; end
|
443
449
|
emit(:T_EPSILON, ts, te) end
|
444
|
-
when
|
450
|
+
when 23 then
|
445
451
|
begin begin p = ((te))-1; end
|
446
452
|
|
447
453
|
emit(:T_IDENT, ts, te)
|
448
454
|
end
|
449
455
|
end
|
450
456
|
end
|
451
|
-
when
|
457
|
+
when 24 then
|
452
458
|
# line 148 "lib/ll/lexer.rl"
|
453
459
|
begin
|
454
460
|
|
@@ -482,7 +488,7 @@ te = p+1
|
|
482
488
|
begin
|
483
489
|
te = p+1
|
484
490
|
end
|
485
|
-
when
|
491
|
+
when 18 then
|
486
492
|
# line 1 "NONE"
|
487
493
|
begin
|
488
494
|
te = p+1
|
@@ -497,8 +503,8 @@ te = p+1
|
|
497
503
|
end
|
498
504
|
# line 168 "lib/ll/lexer.rl"
|
499
505
|
begin
|
500
|
-
act =
|
501
|
-
# line
|
506
|
+
act = 23; end
|
507
|
+
# line 507 "lib/ll/lexer.rb"
|
502
508
|
end
|
503
509
|
end
|
504
510
|
end
|
@@ -508,7 +514,7 @@ act = 22; end
|
|
508
514
|
# line 1 "NONE"
|
509
515
|
begin
|
510
516
|
ts = nil; end
|
511
|
-
# line
|
517
|
+
# line 517 "lib/ll/lexer.rb"
|
512
518
|
end
|
513
519
|
|
514
520
|
if cs == 0
|
@@ -600,7 +606,7 @@ end
|
|
600
606
|
end
|
601
607
|
|
602
608
|
|
603
|
-
# line
|
609
|
+
# line 243 "lib/ll/lexer.rl"
|
604
610
|
|
605
611
|
end # Lexer
|
606
612
|
end # Oga
|
data/lib/ll/parser.rb
CHANGED
@@ -21,119 +21,112 @@ class Parser < LL::Driver
|
|
21
21
|
:T_SEMICOLON, # 11
|
22
22
|
:T_STAR, # 12
|
23
23
|
:T_PLUS, # 13
|
24
|
-
:
|
25
|
-
:
|
24
|
+
:T_QUESTION, # 14
|
25
|
+
:T_LPAREN, # 15
|
26
|
+
:T_RPAREN, # 16
|
26
27
|
].freeze
|
27
28
|
|
28
29
|
CONFIG.rules = [
|
29
30
|
[3, 0, 0, 1], # 0
|
30
|
-
[3, 1,
|
31
|
-
[3, 2, 0,
|
32
|
-
[3, 3,
|
33
|
-
[3, 4, 0,
|
34
|
-
[3, 5, 0,
|
35
|
-
[3, 6, 0,
|
36
|
-
[3, 7, 0,
|
37
|
-
[3, 8, 0,
|
38
|
-
[3, 9, 1, 11, 0,
|
39
|
-
[3, 10, 0,
|
40
|
-
[3, 11,
|
41
|
-
[3, 12,
|
42
|
-
[3, 13,
|
43
|
-
[3, 14,
|
44
|
-
[3, 15, 0,
|
45
|
-
[3, 16,
|
46
|
-
[3, 17,
|
47
|
-
[3, 18, 1,
|
48
|
-
[3, 19,
|
49
|
-
[3, 20, 0,
|
50
|
-
[3, 21,
|
51
|
-
[3, 22,
|
52
|
-
[3, 23,
|
53
|
-
[3, 24, 0,
|
54
|
-
[3, 25,
|
55
|
-
[3, 26, 1,
|
56
|
-
[3, 27,
|
57
|
-
[3, 28, 0,
|
58
|
-
[3, 29, 0,
|
59
|
-
[3, 30,
|
60
|
-
[3, 31, 0,
|
61
|
-
[3, 32, 0,
|
62
|
-
[3, 33,
|
63
|
-
[3, 34, 1, 1], # 34
|
64
|
-
[3, 35, 0, 22, 0, 18], # 35
|
65
|
-
[3, 36, 0, 21, 1, 9], # 36
|
66
|
-
[3, 37, 2, 0], # 37
|
67
|
-
[3, 38, 1, 11, 0, 21, 1, 7, 0, 10], # 38
|
31
|
+
[3, 1, 4, 19, 6, 0], # 1
|
32
|
+
[3, 2, 0, 18], # 2
|
33
|
+
[3, 3, 0, 3], # 3
|
34
|
+
[3, 4, 0, 5], # 4
|
35
|
+
[3, 5, 0, 6], # 5
|
36
|
+
[3, 6, 0, 7], # 6
|
37
|
+
[3, 7, 1, 11, 4, 20, 6, 0, 0, 9, 1, 2], # 7
|
38
|
+
[3, 8, 0, 9, 1, 8, 1, 8], # 8
|
39
|
+
[3, 9, 1, 11, 0, 8, 1, 3], # 9
|
40
|
+
[3, 10, 0, 15, 1, 4], # 10
|
41
|
+
[3, 11, 0, 15, 1, 5], # 11
|
42
|
+
[3, 12, 5, 21, 6, 0], # 12
|
43
|
+
[3, 13, 1, 6], # 13
|
44
|
+
[3, 14, 8, 22, 0, 9], # 14
|
45
|
+
[3, 15, 0, 11, 1, 16, 0, 8, 1, 15], # 15
|
46
|
+
[3, 16, 1, 13], # 16
|
47
|
+
[3, 17, 1, 12], # 17
|
48
|
+
[3, 18, 1, 14], # 18
|
49
|
+
[3, 19, 5, 23, 6, 0], # 19
|
50
|
+
[3, 20, 0, 13], # 20
|
51
|
+
[3, 21, 1, 10], # 21
|
52
|
+
[3, 22, 8, 24, 0, 12], # 22
|
53
|
+
[3, 23, 1, 1], # 23
|
54
|
+
[3, 24, 4, 25, 6, 0, 0, 14], # 24
|
55
|
+
[3, 25, 0, 14, 1, 9], # 25
|
56
|
+
[3, 26, 1, 11, 0, 16, 1, 7, 0, 9], # 26
|
57
|
+
[3, 27, 0, 2], # 27
|
58
|
+
[3, 28, 0, 4], # 28
|
59
|
+
[3, 29, 0, 9], # 29
|
60
|
+
[3, 30, 0, 11], # 30
|
61
|
+
[3, 31, 0, 10], # 31
|
62
|
+
[3, 32, 0, 15], # 32
|
63
|
+
[3, 33, 0, 17], # 33
|
68
64
|
].freeze
|
69
65
|
|
70
66
|
CONFIG.table = [
|
71
|
-
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 0
|
72
|
-
[
|
73
|
-
[-1, -1,
|
74
|
-
[-1, -1,
|
75
|
-
[
|
76
|
-
[-1, -1, -1,
|
77
|
-
[-1, -1, -1, -1,
|
78
|
-
[-1, -1, -1, -1, -1,
|
79
|
-
[
|
80
|
-
[
|
81
|
-
[-1, -1, -1, -1, -1, -1,
|
82
|
-
[-1, -1, -1, -1, -1, -1,
|
83
|
-
[
|
84
|
-
[-1, -1, -1, -1, -1, -1,
|
85
|
-
[
|
86
|
-
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
87
|
-
[
|
88
|
-
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
89
|
-
[-1, -1, -1, -1, -1, -1,
|
90
|
-
[
|
91
|
-
[-1,
|
92
|
-
[-1, -1, -1, -1, -1, -1,
|
93
|
-
[
|
94
|
-
[-1, -1, -1, -1, -1, -1,
|
67
|
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 0
|
68
|
+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], # 1
|
69
|
+
[-1, -1, 3, 4, 5, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 2
|
70
|
+
[-1, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 3
|
71
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1], # 4
|
72
|
+
[-1, -1, -1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 5
|
73
|
+
[-1, -1, -1, -1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 6
|
74
|
+
[-1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 7
|
75
|
+
[12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12], # 8
|
76
|
+
[-1, -1, -1, -1, -1, -1, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 9
|
77
|
+
[-1, -1, -1, -1, -1, -1, 14, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1], # 10
|
78
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 17, 16, 18, -1, -1], # 11
|
79
|
+
[19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 19, 19, 19, 19, 19, 19], # 12
|
80
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, -1, -1, -1], # 13
|
81
|
+
[22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22], # 14
|
82
|
+
[-1, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 15
|
83
|
+
[24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24], # 16
|
84
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, -1, 25, -1, -1, -1, -1, -1, -1, -1], # 17
|
85
|
+
[-1, -1, -1, -1, -1, -1, 26, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 18
|
86
|
+
[-1, -1, 27, 27, 27, 27, 27, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 19
|
87
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, 28, -1, -1, -1, -1, -1, -1, -1, -1], # 20
|
88
|
+
[-1, -1, -1, -1, -1, -1, 29, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 21
|
89
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 30, 30, 30, -1, -1], # 22
|
90
|
+
[-1, -1, -1, -1, -1, -1, 31, -1, -1, -1, -1, -1, -1, -1, -1, 31, -1], # 23
|
91
|
+
[-1, 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], # 24
|
92
|
+
[-1, -1, -1, -1, -1, -1, -1, -1, -1, 33, -1, -1, -1, -1, -1, -1, -1], # 25
|
95
93
|
].freeze
|
96
94
|
|
97
95
|
CONFIG.actions = [
|
98
96
|
[:_rule_0, 1], # 0
|
99
|
-
[:_rule_1,
|
100
|
-
[:_rule_2,
|
101
|
-
[:_rule_3,
|
97
|
+
[:_rule_1, 1], # 1
|
98
|
+
[:_rule_2, 1], # 2
|
99
|
+
[:_rule_3, 1], # 3
|
102
100
|
[:_rule_4, 1], # 4
|
103
101
|
[:_rule_5, 1], # 5
|
104
102
|
[:_rule_6, 1], # 6
|
105
|
-
[:_rule_7,
|
106
|
-
[:_rule_8,
|
107
|
-
[:_rule_9,
|
108
|
-
[:_rule_10,
|
109
|
-
[:_rule_11,
|
110
|
-
[:_rule_12,
|
111
|
-
[:_rule_13,
|
103
|
+
[:_rule_7, 4], # 7
|
104
|
+
[:_rule_8, 3], # 8
|
105
|
+
[:_rule_9, 3], # 9
|
106
|
+
[:_rule_10, 2], # 10
|
107
|
+
[:_rule_11, 2], # 11
|
108
|
+
[:_rule_12, 1], # 12
|
109
|
+
[:_rule_13, 1], # 13
|
112
110
|
[:_rule_14, 2], # 14
|
113
|
-
[:_rule_15,
|
111
|
+
[:_rule_15, 4], # 15
|
114
112
|
[:_rule_16, 1], # 16
|
115
|
-
[:_rule_17,
|
113
|
+
[:_rule_17, 1], # 17
|
116
114
|
[:_rule_18, 1], # 18
|
117
|
-
[:_rule_19,
|
118
|
-
[:_rule_20,
|
115
|
+
[:_rule_19, 1], # 19
|
116
|
+
[:_rule_20, 1], # 20
|
119
117
|
[:_rule_21, 1], # 21
|
120
|
-
[:_rule_22,
|
121
|
-
[:_rule_23,
|
122
|
-
[:_rule_24,
|
123
|
-
[:_rule_25,
|
124
|
-
[:_rule_26,
|
118
|
+
[:_rule_22, 2], # 22
|
119
|
+
[:_rule_23, 1], # 23
|
120
|
+
[:_rule_24, 2], # 24
|
121
|
+
[:_rule_25, 2], # 25
|
122
|
+
[:_rule_26, 4], # 26
|
125
123
|
[:_rule_27, 1], # 27
|
126
124
|
[:_rule_28, 1], # 28
|
127
125
|
[:_rule_29, 1], # 29
|
128
126
|
[:_rule_30, 1], # 30
|
129
|
-
[:_rule_31,
|
127
|
+
[:_rule_31, 1], # 31
|
130
128
|
[:_rule_32, 1], # 32
|
131
|
-
[:_rule_33,
|
132
|
-
[:_rule_34, 1], # 34
|
133
|
-
[:_rule_35, 2], # 35
|
134
|
-
[:_rule_36, 2], # 36
|
135
|
-
[:_rule_37, 0], # 37
|
136
|
-
[:_rule_38, 4], # 38
|
129
|
+
[:_rule_33, 1], # 33
|
137
130
|
].freeze
|
138
131
|
|
139
132
|
##
|
@@ -181,15 +174,15 @@ class Parser < LL::Driver
|
|
181
174
|
end
|
182
175
|
|
183
176
|
def _rule_1(val)
|
184
|
-
|
177
|
+
val[0]
|
185
178
|
end
|
186
179
|
|
187
180
|
def _rule_2(val)
|
188
|
-
|
181
|
+
val[0]
|
189
182
|
end
|
190
183
|
|
191
184
|
def _rule_3(val)
|
192
|
-
val
|
185
|
+
val[0]
|
193
186
|
end
|
194
187
|
|
195
188
|
def _rule_4(val)
|
@@ -205,157 +198,137 @@ class Parser < LL::Driver
|
|
205
198
|
end
|
206
199
|
|
207
200
|
def _rule_7(val)
|
208
|
-
|
201
|
+
|
202
|
+
s(:name, [val[1], *val[2]], :source_line => val[0].source_line)
|
203
|
+
|
209
204
|
end
|
210
205
|
|
211
206
|
def _rule_8(val)
|
212
|
-
|
207
|
+
val[2]
|
213
208
|
end
|
214
209
|
|
215
210
|
def _rule_9(val)
|
216
211
|
|
217
|
-
s(:
|
212
|
+
s(:terminals, val[1], :source_line => val[0].source_line)
|
218
213
|
|
219
214
|
end
|
220
215
|
|
221
216
|
def _rule_10(val)
|
222
|
-
|
217
|
+
|
218
|
+
s(:inner, [val[1]], :source_line => val[0].source_line)
|
219
|
+
|
223
220
|
end
|
224
221
|
|
225
222
|
def _rule_11(val)
|
226
|
-
|
223
|
+
|
224
|
+
s(:header, [val[1]], :source_line => val[0].source_line)
|
225
|
+
|
227
226
|
end
|
228
227
|
|
229
228
|
def _rule_12(val)
|
230
|
-
|
231
|
-
s(:terminals, val[1], :source_line => val[0].source_line)
|
232
|
-
|
229
|
+
val[0]
|
233
230
|
end
|
234
231
|
|
235
232
|
def _rule_13(val)
|
236
233
|
|
237
|
-
s(:
|
234
|
+
s(:ident, [val[0].value], :source_line => val[0].source_line)
|
238
235
|
|
239
236
|
end
|
240
237
|
|
241
238
|
def _rule_14(val)
|
242
239
|
|
243
|
-
s(
|
240
|
+
val[1] ? s(val[1][0], [val[0]], :source_line => val[1][1]) : val[0]
|
244
241
|
|
245
242
|
end
|
246
243
|
|
247
244
|
def _rule_15(val)
|
248
|
-
|
245
|
+
|
246
|
+
s(val[3][0], val[1], :source_line => val[0].source_line)
|
247
|
+
|
249
248
|
end
|
250
249
|
|
251
250
|
def _rule_16(val)
|
252
|
-
val[0]
|
251
|
+
[:plus, val[0].source_line]
|
253
252
|
end
|
254
253
|
|
255
254
|
def _rule_17(val)
|
256
|
-
|
255
|
+
[:star, val[0].source_line]
|
257
256
|
end
|
258
257
|
|
259
258
|
def _rule_18(val)
|
260
|
-
|
261
|
-
s(:ident, [val[0].value], :source_line => val[0].source_line)
|
262
|
-
|
259
|
+
[:question, val[0].source_line]
|
263
260
|
end
|
264
261
|
|
265
262
|
def _rule_19(val)
|
266
|
-
|
263
|
+
|
264
|
+
s(:steps, val[0], :source_line => val[0][0].source_line)
|
265
|
+
|
267
266
|
end
|
268
267
|
|
269
268
|
def _rule_20(val)
|
270
269
|
|
271
|
-
|
270
|
+
s(:steps, [val[0]], :source_line => val[0].source_line)
|
272
271
|
|
273
272
|
end
|
274
273
|
|
275
274
|
def _rule_21(val)
|
276
|
-
val[0]
|
275
|
+
s(:epsilon, [], :source_line => val[0].source_line)
|
277
276
|
end
|
278
277
|
|
279
278
|
def _rule_22(val)
|
280
|
-
|
279
|
+
|
280
|
+
steps = [val[0]]
|
281
|
+
|
282
|
+
steps << val[1] if val[1]
|
283
|
+
|
284
|
+
s(:branch, steps, :source_line => val[0].source_line)
|
285
|
+
|
281
286
|
end
|
282
287
|
|
283
288
|
def _rule_23(val)
|
284
|
-
|
285
|
-
val[1] ? s(val[1][0], [val[0]], :source_line => val[1][1]) : val[0]
|
286
|
-
|
289
|
+
s(:ruby, [val[0].value], :source_line => val[0].source_line)
|
287
290
|
end
|
288
291
|
|
289
292
|
def _rule_24(val)
|
290
|
-
val[0]
|
293
|
+
[val[0], *val[1]]
|
291
294
|
end
|
292
295
|
|
293
296
|
def _rule_25(val)
|
294
|
-
|
297
|
+
val[1]
|
295
298
|
end
|
296
299
|
|
297
300
|
def _rule_26(val)
|
298
|
-
|
301
|
+
|
302
|
+
s(:rule, [val[0], *val[2]], :source_line => val[0].source_line)
|
303
|
+
|
299
304
|
end
|
300
305
|
|
301
306
|
def _rule_27(val)
|
302
|
-
|
307
|
+
val[0]
|
303
308
|
end
|
304
309
|
|
305
310
|
def _rule_28(val)
|
306
|
-
|
307
|
-
s(:steps, val[0], :source_line => val[0][0].source_line)
|
308
|
-
|
311
|
+
val[0]
|
309
312
|
end
|
310
313
|
|
311
314
|
def _rule_29(val)
|
312
|
-
|
313
|
-
s(:steps, [val[0]], :source_line => val[0].source_line)
|
314
|
-
|
315
|
+
val[0]
|
315
316
|
end
|
316
317
|
|
317
318
|
def _rule_30(val)
|
318
|
-
|
319
|
+
val[0]
|
319
320
|
end
|
320
321
|
|
321
322
|
def _rule_31(val)
|
322
|
-
|
323
|
-
steps = [val[0]]
|
324
|
-
|
325
|
-
steps << val[1] if val[1]
|
326
|
-
|
327
|
-
s(:branch, steps, :source_line => val[0].source_line)
|
328
|
-
|
323
|
+
val[0]
|
329
324
|
end
|
330
325
|
|
331
326
|
def _rule_32(val)
|
332
|
-
|
327
|
+
val[0]
|
333
328
|
end
|
334
329
|
|
335
330
|
def _rule_33(val)
|
336
|
-
|
337
|
-
end
|
338
|
-
|
339
|
-
def _rule_34(val)
|
340
|
-
s(:ruby, [val[0].value], :source_line => val[0].source_line)
|
341
|
-
end
|
342
|
-
|
343
|
-
def _rule_35(val)
|
344
|
-
[val[0], *val[1]]
|
345
|
-
end
|
346
|
-
|
347
|
-
def _rule_36(val)
|
348
|
-
val[1]
|
349
|
-
end
|
350
|
-
|
351
|
-
def _rule_37(val)
|
352
|
-
val
|
353
|
-
end
|
354
|
-
|
355
|
-
def _rule_38(val)
|
356
|
-
|
357
|
-
s(:rule, [val[0], *val[2]], :source_line => val[0].source_line)
|
358
|
-
|
331
|
+
val[0]
|
359
332
|
end
|
360
333
|
end
|
361
334
|
end
|
data/lib/ll/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Yorick Peterse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|