rley 0.8.03 → 0.8.05
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/.rubocop.yml +28 -8
- data/CHANGELOG.md +10 -0
- data/examples/data_formats/JSON/README.md +34 -0
- data/examples/data_formats/JSON/sample01.json +3 -0
- data/examples/data_formats/JSON/sample01.svg +36 -0
- data/examples/data_formats/JSON/sample02.json +6 -0
- data/examples/data_formats/JSON/sample02.svg +128 -0
- data/examples/data_formats/JSON/sample03.json +88 -0
- data/examples/general/calc_iter1/README.md +26 -0
- data/examples/general/calc_iter2/README.md +55 -0
- data/examples/general/general_examples.md +37 -0
- data/examples/tokenizer/README.md +46 -0
- data/examples/tokenizer/loxxy_raw_scanner.rex +98 -0
- data/examples/tokenizer/loxxy_raw_scanner.rex.rb +256 -0
- data/examples/tokenizer/loxxy_tokenizer.rb +94 -0
- data/examples/tokenizer/run_tokenizer.rb +29 -0
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/lexical/literal.rb +29 -0
- data/lib/rley/lexical/token.rb +7 -4
- data/lib/rley/syntax/base_grammar_builder.rb +0 -2
- data/lib/rley.rb +1 -1
- data/spec/rley/lexical/literal_spec.rb +33 -0
- data/spec/rley/lexical/token_spec.rb +15 -4
- data/spec/rley/notation/grammar_builder_spec.rb +2 -2
- data/spec/rley/parser/dangling_else_spec.rb +5 -7
- data/spec/rley/parser/gfg_chart_spec.rb +0 -1
- data/spec/rley/parser/gfg_earley_parser_spec.rb +131 -134
- data/spec/rley/parser/gfg_parsing_spec.rb +1 -2
- data/spec/rley/syntax/base_grammar_builder_spec.rb +7 -7
- data/spec/rley/syntax/grammar_spec.rb +6 -9
- metadata +19 -9
- data/lib/rley/parser/parse_tracer.rb +0 -103
- data/lib/rley/syntax/literal.rb +0 -20
- data/lib/rley/syntax/verbatim_symbol.rb +0 -27
- data/spec/rley/syntax/literal_spec.rb +0 -31
- data/spec/rley/syntax/verbatim_symbol_spec.rb +0 -38
@@ -9,6 +9,7 @@ require_relative '../../../lib/rley/syntax/base_grammar_builder'
|
|
9
9
|
require_relative '../../../lib/rley/lexical/token'
|
10
10
|
require_relative '../../../lib/rley/base/dotted_item'
|
11
11
|
require_relative '../../../lib/rley/parser/gfg_parsing'
|
12
|
+
require_relative '../../../lib/rley/notation/grammar_builder'
|
12
13
|
|
13
14
|
require_relative '../support/expectation_helper'
|
14
15
|
|
@@ -63,7 +64,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
63
64
|
context 'Ambiguous parse: ' do
|
64
65
|
# Factory method. Creates a grammar builder for a simple grammar.
|
65
66
|
def grammar_if_else_amb
|
66
|
-
builder = Rley::
|
67
|
+
builder = Rley::Notation::GrammarBuilder.new do
|
67
68
|
add_terminals('IF', 'THEN', 'ELSE')
|
68
69
|
add_terminals('FALSE', 'TRUE', 'INTEGER')
|
69
70
|
|
@@ -289,7 +290,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
289
290
|
|
290
291
|
# Factory method. Creates a grammar builder for a simple grammar.
|
291
292
|
def grammar_if_else
|
292
|
-
builder = Rley::
|
293
|
+
builder = Rley::Notation::GrammarBuilder.new do
|
293
294
|
add_terminals('IF', 'THEN', 'ELSE')
|
294
295
|
add_terminals('FALSE', 'TRUE', 'INTEGER')
|
295
296
|
|
@@ -298,7 +299,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
298
299
|
|
299
300
|
# To prevent dangling else issue, the ELSE must match the closest preceding IF
|
300
301
|
# rule 'stmt' => 'IF boolean THEN stmt ELSE{closest IF} stmt'
|
301
|
-
rule 'stmt' => 'IF boolean THEN stmt ELSE stmt'
|
302
|
+
rule 'stmt' => 'IF boolean THEN stmt ELSE { match_closest: "IF" } stmt'
|
302
303
|
rule 'stmt' => 'literal'
|
303
304
|
rule 'literal' => 'boolean'
|
304
305
|
rule 'literal' => 'INTEGER'
|
@@ -306,10 +307,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
306
307
|
rule 'boolean' => 'TRUE'
|
307
308
|
end
|
308
309
|
|
309
|
-
|
310
|
-
match_else_with_if(grm)
|
311
|
-
|
312
|
-
grm
|
310
|
+
builder.grammar
|
313
311
|
end
|
314
312
|
|
315
313
|
subject { GFGEarleyParser.new(grammar_if_else) }
|
@@ -7,7 +7,6 @@ require_relative '../../../lib/rley/syntax/terminal'
|
|
7
7
|
require_relative '../../../lib/rley/lexical/token'
|
8
8
|
require_relative '../../../lib/rley/gfg/start_vertex'
|
9
9
|
require_relative '../../../lib/rley/parser/parse_entry'
|
10
|
-
require_relative '../../../lib/rley/parser/parse_tracer'
|
11
10
|
require_relative '../../../lib/rley/base/grm_items_builder'
|
12
11
|
require_relative '../../../lib/rley/gfg/grm_flow_graph'
|
13
12
|
require_relative '../support/grammar_abc_helper'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative '../../spec_helper'
|
4
4
|
require 'stringio'
|
5
|
-
require_relative '../../../lib/rley/syntax/
|
5
|
+
require_relative '../../../lib/rley/syntax/terminal'
|
6
6
|
require_relative '../../../lib/rley/syntax/non_terminal'
|
7
7
|
require_relative '../../../lib/rley/syntax/production'
|
8
8
|
require_relative '../../../lib/rley/syntax/base_grammar_builder'
|
@@ -54,12 +54,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
54
54
|
let(:nt_S) { Syntax::NonTerminal.new('S') }
|
55
55
|
let(:nt_M) { Syntax::NonTerminal.new('M') }
|
56
56
|
let(:nt_T) { Syntax::NonTerminal.new('T') }
|
57
|
-
let(:plus) { Syntax::
|
58
|
-
let(:star) { Syntax::
|
59
|
-
let(:integer)
|
60
|
-
integer_pattern = /[-+]?[0-9]+/ # Decimal notation
|
61
|
-
Syntax::Literal.new('integer', integer_pattern)
|
62
|
-
end
|
57
|
+
let(:plus) { Syntax::Terminal.new('+') }
|
58
|
+
let(:star) { Syntax::Terminal.new('*') }
|
59
|
+
let(:integer) { Syntax::Terminal.new('integer') }
|
63
60
|
let(:prod_P) { Syntax::Production.new(nt_P, [nt_S]) }
|
64
61
|
let(:prod_S1) { Syntax::Production.new(nt_S, [nt_S, plus, nt_M]) }
|
65
62
|
let(:prod_S2) { Syntax::Production.new(nt_S, [nt_M]) }
|
@@ -197,16 +194,16 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
197
194
|
###################### S(0): . 2 + 3 * 4
|
198
195
|
# Expectation chart[0]:
|
199
196
|
expected = [
|
200
|
-
'.P | 0',
|
201
|
-
'P => . S | 0',
|
202
|
-
'.S | 0',
|
203
|
-
|
204
|
-
'S => . M | 0',
|
205
|
-
'.M | 0',
|
206
|
-
|
207
|
-
'M => . T | 0',
|
208
|
-
'.T | 0',
|
209
|
-
'T => . integer | 0'
|
197
|
+
'.P | 0', # Initialization
|
198
|
+
'P => . S | 0', # start rule
|
199
|
+
'.S | 0', # call rule
|
200
|
+
'S => . S + M | 0', # start rule
|
201
|
+
'S => . M | 0', # start rule
|
202
|
+
'.M | 0', # call rule
|
203
|
+
'M => . M * T | 0', # start rule
|
204
|
+
'M => . T | 0', # start rule
|
205
|
+
'.T | 0', # call rule
|
206
|
+
'T => . integer | 0' # start rule
|
210
207
|
]
|
211
208
|
compare_entry_texts(parse_result.chart[0], expected)
|
212
209
|
|
@@ -214,16 +211,16 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
214
211
|
###################### S(1): 2 . + 3 * 4
|
215
212
|
# Expectation chart[1]:
|
216
213
|
expected = [
|
217
|
-
'T => integer . | 0',
|
218
|
-
'T. | 0',
|
219
|
-
'M => T . | 0',
|
220
|
-
'M. | 0',
|
221
|
-
'S => M . | 0',
|
222
|
-
|
223
|
-
'S. | 0',
|
224
|
-
'P => S . | 0',
|
225
|
-
|
226
|
-
'P. | 0'
|
214
|
+
'T => integer . | 0', # scan '2'
|
215
|
+
'T. | 0', # exit rule
|
216
|
+
'M => T . | 0', # end rule
|
217
|
+
'M. | 0', # exit rule
|
218
|
+
'S => M . | 0', # end rule
|
219
|
+
'M => M . * T | 0', # end rule
|
220
|
+
'S. | 0', # exit rule
|
221
|
+
'P => S . | 0', # end rule
|
222
|
+
'S => S . + M | 0', # end rule
|
223
|
+
'P. | 0' # exit rule
|
227
224
|
]
|
228
225
|
compare_entry_texts(parse_result.chart[1], expected)
|
229
226
|
|
@@ -231,12 +228,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
231
228
|
###################### S(2): 2 + . 3 * 4
|
232
229
|
# Expectation chart[2]:
|
233
230
|
expected = [
|
234
|
-
|
235
|
-
'.M | 2',
|
236
|
-
|
237
|
-
'M => . T | 2',
|
238
|
-
'.T | 2',
|
239
|
-
'T => . integer | 2'
|
231
|
+
'S => S + . M | 0', # scan '+'
|
232
|
+
'.M | 2', # call rule
|
233
|
+
'M => . M * T | 2', # start rule
|
234
|
+
'M => . T | 2', # start rule
|
235
|
+
'.T | 2', # call rule
|
236
|
+
'T => . integer | 2' # start rule
|
240
237
|
]
|
241
238
|
compare_entry_texts(parse_result.chart[2], expected)
|
242
239
|
|
@@ -244,41 +241,41 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
244
241
|
###################### S(3): 2 + 3 . * 4
|
245
242
|
# Expectation chart[3]:
|
246
243
|
expected = [
|
247
|
-
'T => integer . | 2',
|
248
|
-
'T. | 2',
|
249
|
-
'M => T . | 2',
|
250
|
-
'M. | 2',
|
251
|
-
|
252
|
-
|
253
|
-
'S. | 0',
|
254
|
-
'P => S . | 0',
|
255
|
-
|
256
|
-
'P. | 0'
|
244
|
+
'T => integer . | 2', # scan '3'
|
245
|
+
'T. | 2', # exit rule
|
246
|
+
'M => T . | 2', # end rule
|
247
|
+
'M. | 2', # exit rule
|
248
|
+
'S => S + M . | 0', # end rule
|
249
|
+
'M => M . * T | 2', # end rule
|
250
|
+
'S. | 0', # exit rule
|
251
|
+
'P => S . | 0', # end rule
|
252
|
+
'S => S . + M | 0', # end rule
|
253
|
+
'P. | 0' # exit rule
|
257
254
|
]
|
258
255
|
compare_entry_texts(parse_result.chart[3], expected)
|
259
256
|
|
260
257
|
###################### S(4): 2 + 3 * . 4
|
261
258
|
# Expectation chart[4]:
|
262
259
|
expected = [
|
263
|
-
|
264
|
-
'.T | 4',
|
265
|
-
'T => . integer | 4'
|
260
|
+
'M => M * . T | 2', # scan '*'
|
261
|
+
'.T | 4', # call rule
|
262
|
+
'T => . integer | 4' # entry rule
|
266
263
|
]
|
267
264
|
compare_entry_texts(parse_result.chart[4], expected)
|
268
265
|
|
269
266
|
###################### S(5): 2 + 3 * 4 .
|
270
267
|
# Expectation chart[5]:
|
271
268
|
expected = [
|
272
|
-
'T => integer . | 4',
|
273
|
-
'T. | 4',
|
274
|
-
|
275
|
-
'M. | 2',
|
276
|
-
|
277
|
-
|
278
|
-
'S. | 0',
|
279
|
-
'P => S . | 0',
|
280
|
-
|
281
|
-
'P. | 0'
|
269
|
+
'T => integer . | 4', # scan '4'
|
270
|
+
'T. | 4', # exit rule
|
271
|
+
'M => M * T . | 2', # end rule
|
272
|
+
'M. | 2', # exit rule
|
273
|
+
'S => S + M . | 0', # end rule
|
274
|
+
'M => M . * T | 2', # end rule
|
275
|
+
'S. | 0', # exit rule
|
276
|
+
'P => S . | 0', # end rule
|
277
|
+
'S => S . + M | 0', # end rule
|
278
|
+
'P. | 0' # end rule
|
282
279
|
]
|
283
280
|
compare_entry_texts(parse_result.chart[5], expected)
|
284
281
|
end
|
@@ -373,7 +370,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
373
370
|
# (based on example in D. Grune, C. Jacobs "Parsing Techniques" book)
|
374
371
|
# Ss => A A 'x';
|
375
372
|
# A => ;
|
376
|
-
t_x = Syntax::
|
373
|
+
t_x = Syntax::Terminal.new('x')
|
377
374
|
|
378
375
|
builder = Notation::GrammarBuilder.new do
|
379
376
|
add_terminals(t_x)
|
@@ -390,21 +387,21 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
390
387
|
###################### S(0): . x
|
391
388
|
# Expectation chart[0]:
|
392
389
|
expected = [
|
393
|
-
'.Ss | 0',
|
394
|
-
|
395
|
-
'.A | 0',
|
396
|
-
'A => . | 0',
|
397
|
-
'A. | 0',
|
398
|
-
|
399
|
-
|
390
|
+
'.Ss | 0', # Initialization
|
391
|
+
'Ss => . A A x | 0', # start rule
|
392
|
+
'.A | 0', # call rule
|
393
|
+
'A => . | 0', # start rule
|
394
|
+
'A. | 0', # exit rule
|
395
|
+
'Ss => A . A x | 0', # end rule
|
396
|
+
'Ss => A A . x | 0' # end rule
|
400
397
|
]
|
401
398
|
compare_entry_texts(parse_result.chart[0], expected)
|
402
399
|
|
403
400
|
###################### S(1): x .
|
404
401
|
# Expectation chart[1]:
|
405
402
|
expected = [
|
406
|
-
|
407
|
-
'Ss. | 0'
|
403
|
+
'Ss => A A x . | 0', # scan 'x'
|
404
|
+
'Ss. | 0' # exit rule
|
408
405
|
]
|
409
406
|
compare_entry_texts(parse_result.chart[1], expected)
|
410
407
|
end
|
@@ -417,9 +414,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
417
414
|
# S => S "*" S.
|
418
415
|
# S => L.
|
419
416
|
# L => an integer number token.
|
420
|
-
t_int = Syntax::
|
421
|
-
t_plus = Syntax::
|
422
|
-
t_star = Syntax::
|
417
|
+
t_int = Syntax::Terminal.new('integer')
|
418
|
+
t_plus = Syntax::Terminal.new('+')
|
419
|
+
t_star = Syntax::Terminal.new('*')
|
423
420
|
|
424
421
|
builder = Syntax::BaseGrammarBuilder.new do
|
425
422
|
add_terminals(t_int, t_plus, t_star)
|
@@ -449,8 +446,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
449
446
|
'.P | 0', # Initialization
|
450
447
|
'P => . S | 0', # start rule
|
451
448
|
'.S | 0', # call rule
|
452
|
-
|
453
|
-
|
449
|
+
'S => . S + S | 0', # entry rule
|
450
|
+
'S => . S * S | 0', # entry rule
|
454
451
|
'S => . L | 0', # entry rule
|
455
452
|
'.L | 0', # call rule
|
456
453
|
'L => . integer | 0' # entry rule
|
@@ -465,8 +462,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
465
462
|
'S => L . | 0', # end rule
|
466
463
|
'S. | 0', # exit rule
|
467
464
|
'P => S . | 0', # end rule
|
468
|
-
|
469
|
-
|
465
|
+
'S => S . + S | 0', # end rule
|
466
|
+
'S => S . * S | 0', # end rule
|
470
467
|
'P. | 0' # exit rule
|
471
468
|
]
|
472
469
|
compare_entry_texts(parse_result.chart[1], expected)
|
@@ -474,10 +471,10 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
474
471
|
###################### S(2): 2 + . 3 * 4
|
475
472
|
# Expectation chart[2]:
|
476
473
|
expected = [
|
477
|
-
|
474
|
+
'S => S + . S | 0', # scan '+'
|
478
475
|
'.S | 2', # call rule
|
479
|
-
|
480
|
-
|
476
|
+
'S => . S + S | 2', # entry rule
|
477
|
+
'S => . S * S | 2', # entry rule
|
481
478
|
'S => . L | 2', # entry rule
|
482
479
|
'.L | 2', # call rule
|
483
480
|
'L => . integer | 2' # entry rule
|
@@ -491,13 +488,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
491
488
|
'L. | 2', # exit rule
|
492
489
|
'S => L . | 2', # end rule
|
493
490
|
'S. | 2', # exit rule
|
494
|
-
|
495
|
-
|
496
|
-
|
491
|
+
'S => S + S . | 0', # end rule
|
492
|
+
'S => S . + S | 2', # end rule
|
493
|
+
'S => S . * S | 2', # end rule
|
497
494
|
'S. | 0', # exit rule
|
498
495
|
'P => S . | 0', # end rule
|
499
|
-
|
500
|
-
|
496
|
+
'S => S . + S | 0', # end rule
|
497
|
+
'S => S . * S | 0', # end rule
|
501
498
|
'P. | 0' # exit rule
|
502
499
|
]
|
503
500
|
compare_entry_texts(parse_result.chart[3], expected)
|
@@ -505,11 +502,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
505
502
|
###################### S(4): 2 + 3 * . 4
|
506
503
|
# Expectation chart[4]:
|
507
504
|
expected = [
|
508
|
-
|
509
|
-
|
505
|
+
'S => S * . S | 2', # scan '*'
|
506
|
+
'S => S * . S | 0', # scan '*'
|
510
507
|
'.S | 4', # call rule
|
511
|
-
|
512
|
-
|
508
|
+
'S => . S + S | 4', # entry rule
|
509
|
+
'S => . S * S | 4', # entry rule
|
513
510
|
'S => . L | 4', # entry rule
|
514
511
|
'.L | 4', # call rule
|
515
512
|
'L => . integer | 4' # entry rule
|
@@ -523,18 +520,18 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
523
520
|
'L. | 4', # exit rule
|
524
521
|
'S => L . | 4', # end rule
|
525
522
|
'S. | 4', # exit rule
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
523
|
+
'S => S * S . | 2', # end rule
|
524
|
+
'S => S * S . | 0', # end rule
|
525
|
+
'S => S . + S | 4', # end rule
|
526
|
+
'S => S . * S | 4', # end rule
|
530
527
|
'S. | 2', # exit rule
|
531
528
|
'S. | 0', # exit rule
|
532
|
-
|
533
|
-
|
534
|
-
|
529
|
+
'S => S + S . | 0', # end rule
|
530
|
+
'S => S . + S | 2', # end rule
|
531
|
+
'S => S . * S | 2', # end rule
|
535
532
|
'P => S . | 0', # end rule
|
536
|
-
|
537
|
-
|
533
|
+
'S => S . + S | 0', # end rule
|
534
|
+
'S => S . * S | 0', # end rule
|
538
535
|
'P. | 0' # exit rule
|
539
536
|
]
|
540
537
|
compare_entry_texts(parse_result.chart[5], expected)
|
@@ -544,18 +541,18 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
544
541
|
'L. | 4' => ['L => integer . | 4'],
|
545
542
|
'S => L . | 4' => ['L. | 4'],
|
546
543
|
'S. | 4' => ['S => L . | 4'],
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
'S. | 2' => [
|
552
|
-
'S. | 0' => [
|
553
|
-
|
554
|
-
|
555
|
-
|
544
|
+
'S => S * S . | 2' => ['S. | 4'],
|
545
|
+
'S => S * S . | 0' => ['S. | 4'],
|
546
|
+
'S => S . + S | 4' => ['S. | 4'],
|
547
|
+
'S => S . * S | 4' => ['S. | 4'],
|
548
|
+
'S. | 2' => ['S => S * S . | 2'],
|
549
|
+
'S. | 0' => ['S => S * S . | 0', 'S => S + S . | 0'],
|
550
|
+
'S => S + S . | 0' => ['S. | 2'],
|
551
|
+
'S => S . + S | 2' => ['S. | 2'],
|
552
|
+
'S => S . * S | 2' => ['S. | 2'],
|
556
553
|
'P => S . | 0' => ['S. | 0'],
|
557
|
-
|
558
|
-
|
554
|
+
'S => S . + S | 0' => ['S. | 0'],
|
555
|
+
'S => S . * S | 0' => ['S. | 0'],
|
559
556
|
'P. | 0' => ['P => S . | 0']
|
560
557
|
}
|
561
558
|
check_antecedence(parse_result, 5, expected_antecedents)
|
@@ -816,9 +813,9 @@ MSG
|
|
816
813
|
# Q ::= *.
|
817
814
|
# Q ::= /.
|
818
815
|
# Q ::=.
|
819
|
-
t_a = Syntax::
|
820
|
-
t_star = Syntax::
|
821
|
-
t_slash = Syntax::
|
816
|
+
t_a = Syntax::Terminal.new('a')
|
817
|
+
t_star = Syntax::Terminal.new('*')
|
818
|
+
t_slash = Syntax::Terminal.new('/')
|
822
819
|
|
823
820
|
builder = Syntax::BaseGrammarBuilder.new do
|
824
821
|
add_terminals(t_a, t_star, t_slash)
|
@@ -846,35 +843,35 @@ MSG
|
|
846
843
|
'E => . E Q F | 0', # start rule
|
847
844
|
'E => . F | 0', # start rule
|
848
845
|
'.F | 0', # call rule
|
849
|
-
|
846
|
+
'F => . a | 0' # start rule
|
850
847
|
]
|
851
848
|
compare_entry_texts(parse_result.chart[0], expected)
|
852
849
|
|
853
850
|
###################### S(1) == a . a / a
|
854
851
|
# Expectation chart[1]:
|
855
852
|
expected = [
|
856
|
-
|
857
|
-
'F. | 0',
|
858
|
-
'E => F . | 0',
|
859
|
-
'E. | 0',
|
860
|
-
'Z => E . | 0',
|
861
|
-
'E => E . Q F | 0',
|
862
|
-
'Z. | 0',
|
863
|
-
'.Q | 1',
|
864
|
-
|
865
|
-
|
866
|
-
'Q => . | 1',
|
867
|
-
'Q. | 1',
|
868
|
-
'E => E Q . F | 0',
|
869
|
-
'.F | 1',
|
870
|
-
|
853
|
+
'F => a . | 0', # scan 'a'
|
854
|
+
'F. | 0', # exit rule
|
855
|
+
'E => F . | 0', # end rule
|
856
|
+
'E. | 0', # exit rule
|
857
|
+
'Z => E . | 0', # end rule
|
858
|
+
'E => E . Q F | 0', # end rule
|
859
|
+
'Z. | 0', # exit rule
|
860
|
+
'.Q | 1', # call rule
|
861
|
+
'Q => . * | 1', # start rule
|
862
|
+
'Q => . / | 1', # start rule
|
863
|
+
'Q => . | 1', # start rule
|
864
|
+
'Q. | 1', # exit rule
|
865
|
+
'E => E Q . F | 0', # end rule
|
866
|
+
'.F | 1', # call rule
|
867
|
+
'F => . a | 1' # start rule
|
871
868
|
]
|
872
869
|
compare_entry_texts(parse_result.chart[1], expected)
|
873
870
|
|
874
871
|
###################### S(2) == a a . / a
|
875
872
|
# Expectation chart[2]:
|
876
873
|
expected = [
|
877
|
-
|
874
|
+
'F => a . | 1', # scan 'a'
|
878
875
|
'F. | 1', # exit rule
|
879
876
|
'E => E Q F . | 0', # end rule
|
880
877
|
'E. | 0', # exit rule
|
@@ -882,13 +879,13 @@ MSG
|
|
882
879
|
'E => E . Q F | 0', # end rule
|
883
880
|
'Z. | 0', # exit rule
|
884
881
|
'.Q | 2', # call rule
|
885
|
-
|
886
|
-
|
882
|
+
'Q => . * | 2', # start rule
|
883
|
+
'Q => . / | 2', # start rule
|
887
884
|
'Q => . | 2', # start rule
|
888
885
|
'Q. | 2', # exit rule
|
889
886
|
'E => E Q . F | 0', # end rule
|
890
887
|
'.F | 2', # call rule
|
891
|
-
|
888
|
+
'F => . a | 2' # start rule
|
892
889
|
]
|
893
890
|
compare_entry_texts(parse_result.chart[2], expected)
|
894
891
|
|
@@ -896,11 +893,11 @@ MSG
|
|
896
893
|
###################### S(3) == a a / . a
|
897
894
|
# Expectation chart[3]:
|
898
895
|
expected = [
|
899
|
-
|
896
|
+
'Q => / . | 2', # scan '/'
|
900
897
|
'Q. | 2', # exit rule
|
901
898
|
'E => E Q . F | 0', # end rule
|
902
899
|
'.F | 3', # call rule
|
903
|
-
|
900
|
+
'F => . a | 3' # entry rule
|
904
901
|
]
|
905
902
|
compare_entry_texts(parse_result.chart[3], expected)
|
906
903
|
|
@@ -908,7 +905,7 @@ MSG
|
|
908
905
|
###################### S(4) == a a / a .
|
909
906
|
# Expectation chart[4]:
|
910
907
|
expected = [
|
911
|
-
|
908
|
+
'F => a . | 3', # scan 'a'
|
912
909
|
'F. | 3', # exit rule
|
913
910
|
'E => E Q F . | 0', # end rule
|
914
911
|
'E. | 0', # exit rule
|
@@ -916,13 +913,13 @@ MSG
|
|
916
913
|
'E => E . Q F | 0', # end rule
|
917
914
|
'Z. | 0', # exit rule
|
918
915
|
'.Q | 4', # call rule
|
919
|
-
|
920
|
-
|
916
|
+
'Q => . * | 4', # start rule
|
917
|
+
'Q => . / | 4', # start rule
|
921
918
|
'Q => . | 4', # start rule
|
922
919
|
'Q. | 4', # exit rule
|
923
920
|
'E => E Q . F | 0', # end rule
|
924
921
|
'.F | 4', # call rule
|
925
|
-
|
922
|
+
'F => . a | 4' # entry rule
|
926
923
|
]
|
927
924
|
compare_entry_texts(parse_result.chart[4], expected)
|
928
925
|
end
|
@@ -4,12 +4,11 @@ require_relative '../../spec_helper'
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
require_relative '../../../lib/rley/syntax/non_terminal'
|
7
|
-
require_relative '../../../lib/rley/syntax/
|
7
|
+
require_relative '../../../lib/rley/syntax/terminal'
|
8
8
|
require_relative '../../../lib/rley/syntax/production'
|
9
9
|
require_relative '../../../lib/rley/syntax/base_grammar_builder'
|
10
10
|
require_relative '../../../lib/rley/base/dotted_item'
|
11
11
|
require_relative '../../../lib/rley/lexical/token'
|
12
|
-
require_relative '../../../lib/rley/parser/parse_tracer'
|
13
12
|
require_relative '../../../lib/rley/gfg/grm_flow_graph'
|
14
13
|
require_relative '../../../lib/rley/base/grm_items_builder'
|
15
14
|
require_relative '../support/grammar_abc_helper'
|
@@ -55,8 +55,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
55
55
|
|
56
56
|
it 'should accept already built terminals' do
|
57
57
|
a = Terminal.new('a')
|
58
|
-
b =
|
59
|
-
c =
|
58
|
+
b = Terminal.new('b')
|
59
|
+
c = Terminal.new('c')
|
60
60
|
|
61
61
|
subject.add_terminals(a, b, c)
|
62
62
|
expect(subject.symbols.size).to eq(3)
|
@@ -67,8 +67,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
67
67
|
|
68
68
|
it 'should accept already built terminals' do
|
69
69
|
a = Terminal.new('a')
|
70
|
-
b =
|
71
|
-
c =
|
70
|
+
b = Terminal.new('b')
|
71
|
+
c = Terminal.new('c')
|
72
72
|
|
73
73
|
subject.add_terminals(a, b, c)
|
74
74
|
expect(subject.symbols.size).to eq(3)
|
@@ -197,9 +197,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
197
197
|
# Q ::= *.
|
198
198
|
# Q ::= /.
|
199
199
|
# Q ::=.
|
200
|
-
t_a =
|
201
|
-
t_star =
|
202
|
-
t_slash =
|
200
|
+
t_a = Terminal.new('a')
|
201
|
+
t_star = Terminal.new('*')
|
202
|
+
t_slash = Terminal.new('/')
|
203
203
|
|
204
204
|
builder = BaseGrammarBuilder.new
|
205
205
|
builder.add_terminals(t_a, t_star, t_slash)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative '../../spec_helper'
|
4
4
|
|
5
|
-
require_relative '../../../lib/rley/syntax/
|
5
|
+
require_relative '../../../lib/rley/syntax/terminal'
|
6
6
|
require_relative '../../../lib/rley/syntax/non_terminal'
|
7
7
|
require_relative '../../../lib/rley/syntax/production'
|
8
8
|
|
@@ -25,7 +25,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
25
25
|
|
26
26
|
def build_verbatim_symbols(symbols)
|
27
27
|
result = {}
|
28
|
-
symbols.each { |symb| result[symb] =
|
28
|
+
symbols.each { |symb| result[symb] = Terminal.new(symb) }
|
29
29
|
result
|
30
30
|
end
|
31
31
|
|
@@ -36,7 +36,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
36
36
|
end
|
37
37
|
|
38
38
|
# Grammar symbols for integer arithmetic expressions
|
39
|
-
let(:number) {
|
39
|
+
let(:number) { Terminal.new('number') } # Positive integers only
|
40
40
|
let(:add_op) { NonTerminal.new('add_op') }
|
41
41
|
let(:add_operators) { [grm1_ops['+'], grm1_ops['-']] }
|
42
42
|
let(:mult_op) { NonTerminal.new('mult_op') }
|
@@ -75,9 +75,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
75
75
|
let(:nt_B) { NonTerminal.new('B') }
|
76
76
|
let(:nt_C) { NonTerminal.new('C') }
|
77
77
|
let(:nt_D) { NonTerminal.new('D') }
|
78
|
-
let(:a_) {
|
79
|
-
let(:b_) {
|
80
|
-
let(:c_) {
|
78
|
+
let(:a_) { Terminal.new('a') }
|
79
|
+
let(:b_) { Terminal.new('b') }
|
80
|
+
let(:c_) { Terminal.new('c') }
|
81
81
|
let(:prod_S) { Production.new(nt_S, [nt_A]) }
|
82
82
|
let(:prod_A1) { Production.new(nt_A, [a_, nt_A, c_]) }
|
83
83
|
let(:prod_A2) { Production.new(nt_A, [b_]) }
|
@@ -104,9 +104,6 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
104
104
|
let(:conjunction) { NonTerminal.new('Conjunction') }
|
105
105
|
let(:conjunction_list) { %w(and or but) }
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
107
|
let(:noun_prods) { prods_for_list(noun, noun_list) }
|
111
108
|
let(:verb_prods) { prods_for_list(verb, verb_list) }
|
112
109
|
let(:adjective_prods) { prods_for_list(adjective, adjective_list) }
|