Debian Codegraph @

t/sl_debug.t

raw
1 #!/usr/bin/perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 # Displays for SLIF Progress.pod
18
19 use 5.010001;
20 use strict;
21 use warnings;
22
23 use Test::More tests => 26;
24
25 use English qw( -no_match_vars );
26 use Fatal qw( open close );
27 use lib 'inc';
28 use Marpa::R2::Test;
29 use Marpa::R2;
30 use Data::Dumper;
31
32 my $progress_report = q{};
33
34 # Marpa::R2::Display
35 # name: SLIF debug example, part 1
36
37 my $slif_debug_source = <<'END_OF_SOURCE';
38 :default ::= action => ::array bless => ::lhs
39 :start ::= statements
40 statements ::= statement *
41 statement ::= assignment | <numeric assignment>
42 assignment ::= 'set' variable 'to' expression
43
44 # This is a deliberate error in the grammar
45 # The next line should be:
46 # <numeric assignment> ::= variable '=' <numeric expression>
47 # I have changed the <numeric expression> to <expression> which
48 # will cause problems.
49 <numeric assignment> ::= variable '=' expression
50
51 expression ::=
52 variable | string
53 || 'string' '(' <numeric expression> ')'
54 || expression '+' expression
55 <numeric expression> ::=
56 variable | number
57 || <numeric expression> '*' <numeric expression>
58 || <numeric expression> '+' <numeric expression>
59 variable ~ [\w]+
60 number ~ [\d]+
61 string ~ ['] <string contents> [']
62 <string contents> ~ [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]+
63 :discard ~ whitespace
64 whitespace ~ [\s]+
65 END_OF_SOURCE
66
67 my $grammar = Marpa::R2::Scanless::G->new(
68 {
69 bless_package => 'My_Nodes',
70 source => \$slif_debug_source,
71 });
72
73 # Marpa::R2::Display::End
74
75 ## no critic (InputOutput::RequireBriefOpen)
76 open my $trace_fh, q{>}, \( my $trace_output = q{} );
77 ## use critic
78
79 # Marpa::R2::Display
80 # name: SLIF grammar set() synopsis
81
82 $grammar->set( { trace_file_handle => $trace_fh } );
83
84 # Marpa::R2::Display::End
85
86 # Marpa::R2::Display
87 # name: SLIF debug example, part 2
88
89 my $recce = Marpa::R2::Scanless::R->new(
90 { grammar => $grammar,
91 trace_terminals => 1,
92 trace_values => 1,
93 } );
94
95 my $test_input = 'a = 8675309 + 42 * 711';
96 my $eval_error = $EVAL_ERROR if not eval { $recce->read( \$test_input ); 1 };
97
98 $progress_report = $recce->show_progress( 0, -1 );
99
100 # Marpa::R2::Display::End
101
102 # Marpa::R2::Display
103 # name: SLIF debug example error message
104 # start-after-line: END_OF_TEXT
105 # end-before-line: '^END_OF_TEXT$'
106
107 $eval_error =~ s/^(Marpa::R2 \s+ exception \s+ at) .*/$1\n/xms;
108 Marpa::R2::Test::is($eval_error, <<'END_OF_TEXT', 'Error message before fix');
109 Error in SLIF parse: No lexemes accepted at line 1, column 18
110 Rejected lexeme #0: '*'; value="*"; length = 1
111 * String before error: a = 8675309 + 42\s
112 * The error was at line 1, column 18, and at character 0x002a '*', ...
113 * here: * 711
114 Marpa::R2 exception at
115 END_OF_TEXT
116
117 # Marpa::R2::Display::End
118
119
120 # Marpa::R2::Display
121 # name: SLIF debug example dump of value
122
123 my $value_ref = $recce->value();
124 my $expected_output = \bless(
125 [
126 bless(
127 [
128 bless(
129 [
130 'a', '=',
131 bless(
132 [
133 bless( ['8675309'], 'My_Nodes::expression' ),
134 '+',
135 bless( ['42'], 'My_Nodes::expression' )
136 ],
137 'My_Nodes::expression'
138 )
139 ],
140 'My_Nodes::numeric_assignment'
141 )
142 ],
143 'My_Nodes::statement'
144 )
145 ],
146 'My_Nodes::statements'
147 );
148
149 # Marpa::R2::Display::End
150
151 Test::More::is_deeply( $value_ref, $expected_output, 'Value before fix' );
152
153 # Marpa::R2::Display
154 # name: SLIF debug example progress report
155 # start-after-line: END_PROGRESS_REPORT
156 # end-before-line: '^END_PROGRESS_REPORT$'
157
158 Marpa::R2::Test::is( $progress_report,
159 <<'END_PROGRESS_REPORT', 'progress report' );
160 P0 @0-0 L0c0 statements -> . statement *
161 P1 @0-0 L0c0 statement -> . assignment
162 P2 @0-0 L0c0 statement -> . <numeric assignment>
163 P3 @0-0 L0c0 assignment -> . 'set' variable 'to' expression
164 P4 @0-0 L0c0 <numeric assignment> -> . variable '=' expression
165 P19 @0-0 L0c0 :start -> . statements
166 R4:1 @0-1 L1c1 <numeric assignment> -> variable . '=' expression
167 R4:2 @0-2 L1c1-3 <numeric assignment> -> variable '=' . expression
168 P5 @2-2 L1c3 expression -> . expression
169 P6 @2-2 L1c3 expression -> . expression
170 P7 @2-2 L1c3 expression -> . expression
171 P8 @2-2 L1c3 expression -> . variable
172 P9 @2-2 L1c3 expression -> . string
173 P10 @2-2 L1c3 expression -> . 'string' '(' <numeric expression> ')'
174 P11 @2-2 L1c3 expression -> . expression '+' expression
175 F0 @0-3 L1c1-11 statements -> statement * .
176 P1 @3-3 L1c5-11 statement -> . assignment
177 P2 @3-3 L1c5-11 statement -> . <numeric assignment>
178 F2 @0-3 L1c1-11 statement -> <numeric assignment> .
179 P3 @3-3 L1c5-11 assignment -> . 'set' variable 'to' expression
180 P4 @3-3 L1c5-11 <numeric assignment> -> . variable '=' expression
181 F4 @0-3 L1c1-11 <numeric assignment> -> variable '=' expression .
182 F5 @2-3 L1c3-11 expression -> expression .
183 F6 @2-3 L1c3-11 expression -> expression .
184 F7 @2-3 L1c3-11 expression -> expression .
185 F8 @2-3 L1c3-11 expression -> variable .
186 R11:1 @2-3 L1c3-11 expression -> expression . '+' expression
187 F19 @0-3 L1c1-11 :start -> statements .
188 P7 @4-4 L1c13 expression -> . expression
189 P8 @4-4 L1c13 expression -> . variable
190 P9 @4-4 L1c13 expression -> . string
191 P10 @4-4 L1c13 expression -> . 'string' '(' <numeric expression> ')'
192 R11:2 @2-4 L1c3-13 expression -> expression '+' . expression
193 F0 @0-5 L1c1-16 statements -> statement * .
194 P1 @5-5 L1c15-16 statement -> . assignment
195 P2 @5-5 L1c15-16 statement -> . <numeric assignment>
196 F2 @0-5 L1c1-16 statement -> <numeric assignment> .
197 P3 @5-5 L1c15-16 assignment -> . 'set' variable 'to' expression
198 P4 @5-5 L1c15-16 <numeric assignment> -> . variable '=' expression
199 F4 @0-5 L1c1-16 <numeric assignment> -> variable '=' expression .
200 F5 @2-5 L1c3-16 expression -> expression .
201 F7 @4-5 L1c13-16 expression -> expression .
202 F8 @4-5 L1c13-16 expression -> variable .
203 R11:1 @2-5 L1c3-16 expression -> expression . '+' expression
204 F11 @2-5 L1c3-16 expression -> expression '+' expression .
205 F19 @0-5 L1c1-16 :start -> statements .
206 END_PROGRESS_REPORT
207
208 # Marpa::R2::Display::End
209
210 $Data::Dumper::Indent = 0;
211 $Data::Dumper::Terse = 1;
212
213 # Marpa::R2::Display
214 # name: SLIF progress(0) example
215
216 my $report0 = $recce->progress(0);
217
218 # Marpa::R2::Display::End
219
220 # Marpa::R2::Display
221 # name: SLIF progress() output at location 0
222 # start-after-line: END_PROGRESS_REPORT
223 # end-before-line: '^END_PROGRESS_REPORT$'
224
225 chomp( my $expected_report0 = <<'END_PROGRESS_REPORT');
226 [[0,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0],[19,0,0]]
227 END_PROGRESS_REPORT
228 Marpa::R2::Test::is( Data::Dumper::Dumper($report0),
229 $expected_report0, 'progress report at location 0' );
230
231 # Marpa::R2::Display::End
232
233 # Try again with negative index
234 $report0 = $recce->progress(-6);
235 Marpa::R2::Test::is( Data::Dumper::Dumper($report0),
236 $expected_report0, 'progress report at location -6' );
237
238 my $report1 = $recce->progress(1);
239
240 # Marpa::R2::Display
241 # name: SLIF progress() output at location 1
242 # start-after-line: END_PROGRESS_REPORT
243 # end-before-line: '^END_PROGRESS_REPORT$'
244
245 chomp( my $expected_report1 = <<'END_PROGRESS_REPORT');
246 [[4,1,0]]
247 END_PROGRESS_REPORT
248 Marpa::R2::Test::is( Data::Dumper::Dumper($report1),
249 $expected_report1, 'progress report at location 1' );
250
251 # Marpa::R2::Display::End
252
253 # Try again with negative index
254 $report1 = $recce->progress(-5);
255 Marpa::R2::Test::is( Data::Dumper::Dumper($report1),
256 $expected_report1, 'progress report at location -5' );
257
258 my $report2 = $recce->progress(2);
259
260 # Marpa::R2::Display
261 # name: SLIF progress() output at location 2
262 # start-after-line: END_PROGRESS_REPORT
263 # end-before-line: '^END_PROGRESS_REPORT$'
264
265 chomp( my $expected_report2 = <<'END_PROGRESS_REPORT');
266 [[5,0,2],[6,0,2],[7,0,2],[8,0,2],[9,0,2],[10,0,2],[11,0,2],[4,2,0]]
267 END_PROGRESS_REPORT
268 Marpa::R2::Test::is( Data::Dumper::Dumper($report2),
269 $expected_report2, 'progress report at location 2' );
270
271 # Marpa::R2::Display::End
272
273 # Try again with negative index
274 $report2 = $recce->progress(-4);
275 Marpa::R2::Test::is( Data::Dumper::Dumper($report2),
276 $expected_report2, 'progress report at location -4' );
277
278 # Marpa::R2::Display
279 # name: SLIF progress() example
280
281 my $latest_report = $recce->progress();
282
283 # Marpa::R2::Display::End
284
285 # Marpa::R2::Display
286 # name: SLIF progress() output at default location
287 # start-after-line: END_PROGRESS_REPORT
288 # end-before-line: '^END_PROGRESS_REPORT$'
289
290 chomp( my $expected_default_report = <<'END_PROGRESS_REPORT');
291 [[0,-1,0],[2,-1,0],[4,-1,0],[5,-1,2],[7,-1,4],[8,-1,4],[11,-1,2],[19,-1,0],[1,0,5],[2,0,5],[3,0,5],[4,0,5],[11,1,2]]
292 END_PROGRESS_REPORT
293 Marpa::R2::Test::is( Data::Dumper::Dumper($latest_report),
294 $expected_default_report, 'progress report at default location' );
295
296 # Marpa::R2::Display::End
297
298 chomp( my $expected_report3 = <<'END_PROGRESS_REPORT');
299 [[0,-1,0],[2,-1,0],[4,-1,0],[5,-1,2],[6,-1,2],[7,-1,2],[8,-1,2],[19,-1,0],[1,0,3],[2,0,3],[3,0,3],[4,0,3],[11,1,2]]
300 END_PROGRESS_REPORT
301
302 # Try latest report again with explicit index
303 my $report3 = $recce->progress(3);
304 Marpa::R2::Test::is( Data::Dumper::Dumper($report3),
305 $expected_report3, 'progress report at location 3' );
306
307 # Try latest report again with negative index
308 $latest_report = $recce->progress(-3);
309 Marpa::R2::Test::is( Data::Dumper::Dumper($latest_report),
310 $expected_report3, 'progress report at location -3' );
311
312 # Marpa::R2::Display
313 # name: SLIF debug example trace output
314 # start-after-line: END_TRACE_OUTPUT
315 # end-before-line: '^END_TRACE_OUTPUT$'
316
317 Marpa::R2::Test::is( $trace_output, <<'END_TRACE_OUTPUT', 'trace output' );
318 Setting trace_terminals option
319 Setting trace_values option
320 Accepted lexeme L1c1 e1: variable; value="a"
321 Discarded lexeme L1c2: whitespace
322 Accepted lexeme L1c3 e2: '='; value="="
323 Discarded lexeme L1c4: whitespace
324 Rejected lexeme L1c5-11: number; value="8675309"
325 Accepted lexeme L1c5-11 e3: variable; value="8675309"
326 Discarded lexeme L1c12: whitespace
327 Rejected lexeme L1c13: '+'; value="+"
328 Accepted lexeme L1c13 e4: '+'; value="+"
329 Discarded lexeme L1c14: whitespace
330 Rejected lexeme L1c15-16: number; value="42"
331 Accepted lexeme L1c15-16 e5: variable; value="42"
332 Discarded lexeme L1c17: whitespace
333 Rejected lexeme L1c18: '*'; value="*"
334 END_TRACE_OUTPUT
335
336 # Marpa::R2::Display::End
337
338 $slif_debug_source =~
339 s{^ [<] numeric \s+ assignment [>] \s+ [:][:][=] \s+ variable \s+ ['][=]['] \s+ expression $}
340 {<numeric assignment> ::= variable '=' <numeric expression>}xms;
341
342 $grammar = Marpa::R2::Scanless::G->new(
343 {
344 bless_package => 'My_Nodes',
345 source => \$slif_debug_source,
346 });
347
348 $recce = Marpa::R2::Scanless::R->new(
349 { grammar => $grammar } );
350
351 die if not defined $recce->read( \$test_input );
352 $value_ref = $recce->value();
353 my $expected_value_after_fix = \bless(
354 [
355 bless(
356 [
357 bless(
358 [
359 'a', '=',
360 bless(
361 [
362 bless(
363 ['8675309'], 'My_Nodes::numeric_expression'
364 ),
365 '+',
366 bless(
367 [
368 bless(
369 ['42'],
370 'My_Nodes::numeric_expression'
371 ),
372 '*',
373 bless(
374 ['711'],
375 'My_Nodes::numeric_expression'
376 )
377 ],
378 'My_Nodes::numeric_expression'
379 )
380 ],
381 'My_Nodes::numeric_expression'
382 )
383 ],
384 'My_Nodes::numeric_assignment'
385 )
386 ],
387 'My_Nodes::statement'
388 )
389 ],
390 'My_Nodes::statements'
391 );
392 Test::More::is_deeply( $value_ref, $expected_value_after_fix,
393 'Value after fix' );
394
395 my $show_rules_output;
396 $show_rules_output .= "G1 Rules:\n";
397 $show_rules_output .= $grammar->show_rules(3);
398 $show_rules_output .= "Lex (L0) Rules:\n";
399
400 # Marpa::R2::Display
401 # name: SLG show_rules() synopsis with 2 args
402
403 $show_rules_output .= $grammar->show_rules(3, 'L0');
404
405 # Marpa::R2::Display::End
406
407 # Marpa::R2::Display
408 # name: SLIF debug example show_rules() output
409 # start-after-line: END_OF_SHOW_RULES_OUTPUT
410 # end-before-line: '^END_OF_SHOW_RULES_OUTPUT$'
411
412 Marpa::R2::Test::is( $show_rules_output,
413 <<'END_OF_SHOW_RULES_OUTPUT', 'SLIF show_rules()' );
414 G1 Rules:
415 G1 R0 statements ::= statement *
416 Symbol IDs: <16> ::= <17>
417 Internal symbols: <statements> ::= <statement>
418 G1 R1 statement ::= assignment
419 Symbol IDs: <17> ::= <18>
420 Internal symbols: <statement> ::= <assignment>
421 G1 R2 statement ::= <numeric assignment>
422 Symbol IDs: <17> ::= <19>
423 Internal symbols: <statement> ::= <numeric assignment>
424 G1 R3 assignment ::= 'set' variable 'to' expression
425 Symbol IDs: <18> ::= <1> <20> <2> <21>
426 Internal symbols: <assignment> ::= <[Lex-0]> <variable> <[Lex-1]> <expression>
427 G1 R4 <numeric assignment> ::= variable '=' <numeric expression>
428 Symbol IDs: <19> ::= <20> <3> <22>
429 Internal symbols: <numeric assignment> ::= <variable> <[Lex-2]> <numeric expression>
430 G1 R5 expression ::= expression
431 Internal rule top priority rule for <expression>
432 Symbol IDs: <21> ::= <10>
433 Internal symbols: <expression> ::= <expression[0]>
434 G1 R6 expression ::= expression
435 Internal rule for symbol <expression> priority transition from 0 to 1
436 Symbol IDs: <10> ::= <11>
437 Internal symbols: <expression[0]> ::= <expression[1]>
438 G1 R7 expression ::= expression
439 Internal rule for symbol <expression> priority transition from 1 to 2
440 Symbol IDs: <11> ::= <12>
441 Internal symbols: <expression[1]> ::= <expression[2]>
442 G1 R8 expression ::= variable
443 Symbol IDs: <12> ::= <20>
444 Internal symbols: <expression[2]> ::= <variable>
445 G1 R9 expression ::= string
446 Symbol IDs: <12> ::= <23>
447 Internal symbols: <expression[2]> ::= <string>
448 G1 R10 expression ::= 'string' '(' <numeric expression> ')'
449 Symbol IDs: <11> ::= <4> <5> <22> <6>
450 Internal symbols: <expression[1]> ::= <[Lex-3]> <[Lex-4]> <numeric expression> <[Lex-5]>
451 G1 R11 expression ::= expression '+' expression
452 Symbol IDs: <10> ::= <10> <7> <11>
453 Internal symbols: <expression[0]> ::= <expression[0]> <[Lex-6]> <expression[1]>
454 G1 R12 <numeric expression> ::= <numeric expression>
455 Internal rule top priority rule for <numeric expression>
456 Symbol IDs: <22> ::= <13>
457 Internal symbols: <numeric expression> ::= <numeric expression[0]>
458 G1 R13 <numeric expression> ::= <numeric expression>
459 Internal rule for symbol <numeric expression> priority transition from 0 to 1
460 Symbol IDs: <13> ::= <14>
461 Internal symbols: <numeric expression[0]> ::= <numeric expression[1]>
462 G1 R14 <numeric expression> ::= <numeric expression>
463 Internal rule for symbol <numeric expression> priority transition from 1 to 2
464 Symbol IDs: <14> ::= <15>
465 Internal symbols: <numeric expression[1]> ::= <numeric expression[2]>
466 G1 R15 <numeric expression> ::= variable
467 Symbol IDs: <15> ::= <20>
468 Internal symbols: <numeric expression[2]> ::= <variable>
469 G1 R16 <numeric expression> ::= number
470 Symbol IDs: <15> ::= <24>
471 Internal symbols: <numeric expression[2]> ::= <number>
472 G1 R17 <numeric expression> ::= <numeric expression> '*' <numeric expression>
473 Symbol IDs: <14> ::= <14> <8> <15>
474 Internal symbols: <numeric expression[1]> ::= <numeric expression[1]> <[Lex-7]> <numeric expression[2]>
475 G1 R18 <numeric expression> ::= <numeric expression> '+' <numeric expression>
476 Symbol IDs: <13> ::= <13> <9> <14>
477 Internal symbols: <numeric expression[0]> ::= <numeric expression[0]> <[Lex-8]> <numeric expression[1]>
478 G1 R19 :start ::= statements
479 Symbol IDs: <0> ::= <16>
480 Internal symbols: <[:start]> ::= <statements>
481 Lex (L0) Rules:
482 L0 R0 'set' ::= [s] [e] [t]
483 Internal rule for single-quoted string 'set'
484 Symbol IDs: <2> ::= <27> <21> <28>
485 Internal symbols: <[Lex-0]> ::= <[[s]]> <[[e]]> <[[t]]>
486 L0 R1 'to' ::= [t] [o]
487 Internal rule for single-quoted string 'to'
488 Symbol IDs: <3> ::= <28> <25>
489 Internal symbols: <[Lex-1]> ::= <[[t]]> <[[o]]>
490 L0 R2 '=' ::= [\=]
491 Internal rule for single-quoted string '='
492 Symbol IDs: <4> ::= <16>
493 Internal symbols: <[Lex-2]> ::= <[[\=]]>
494 L0 R3 'string' ::= [s] [t] [r] [i] [n] [g]
495 Internal rule for single-quoted string 'string'
496 Symbol IDs: <5> ::= <27> <28> <26> <23> <24> <22>
497 Internal symbols: <[Lex-3]> ::= <[[s]]> <[[t]]> <[[r]]> <[[i]]> <[[n]]> <[[g]]>
498 L0 R4 '(' ::= [\(]
499 Internal rule for single-quoted string '('
500 Symbol IDs: <6> ::= <12>
501 Internal symbols: <[Lex-4]> ::= <[[\(]]>
502 L0 R5 ')' ::= [\)]
503 Internal rule for single-quoted string ')'
504 Symbol IDs: <7> ::= <13>
505 Internal symbols: <[Lex-5]> ::= <[[\)]]>
506 L0 R6 '+' ::= [\+]
507 Internal rule for single-quoted string '+'
508 Symbol IDs: <8> ::= <15>
509 Internal symbols: <[Lex-6]> ::= <[[\+]]>
510 L0 R7 '*' ::= [\*]
511 Internal rule for single-quoted string '*'
512 Symbol IDs: <9> ::= <14>
513 Internal symbols: <[Lex-7]> ::= <[[\*]]>
514 L0 R8 '+' ::= [\+]
515 Internal rule for single-quoted string '+'
516 Symbol IDs: <10> ::= <15>
517 Internal symbols: <[Lex-8]> ::= <[[\+]]>
518 L0 R9 variable ::= [\w] +
519 Symbol IDs: <29> ::= <19>
520 Internal symbols: <variable> ::= <[[\w]]>
521 L0 R10 number ::= [\d] +
522 Symbol IDs: <30> ::= <17>
523 Internal symbols: <number> ::= <[[\d]]>
524 L0 R11 string ::= ['] <string contents> [']
525 Symbol IDs: <31> ::= <11> <32> <11>
526 Internal symbols: <string> ::= <[[']]> <string contents> <[[']]>
527 L0 R12 <string contents> ::= [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}] +
528 Symbol IDs: <32> ::= <20>
529 Internal symbols: <string contents> ::= <[[^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]]>
530 L0 R13 :discard ::= whitespace
531 Discard rule for <whitespace>
532 Symbol IDs: <0> ::= <33>
533 Internal symbols: <[:discard]> ::= <whitespace>
534 L0 R14 whitespace ::= [\s] +
535 Symbol IDs: <33> ::= <18>
536 Internal symbols: <whitespace> ::= <[[\s]]>
537 L0 R15 :start_lex ::= :discard
538 Internal lexical start rule for <[:discard]>
539 Symbol IDs: <1> ::= <0>
540 Internal symbols: <[:start_lex]> ::= <[:discard]>
541 L0 R16 :start_lex ::= 'set'
542 Internal lexical start rule for <[Lex-0]>
543 Symbol IDs: <1> ::= <2>
544 Internal symbols: <[:start_lex]> ::= <[Lex-0]>
545 L0 R17 :start_lex ::= 'to'
546 Internal lexical start rule for <[Lex-1]>
547 Symbol IDs: <1> ::= <3>
548 Internal symbols: <[:start_lex]> ::= <[Lex-1]>
549 L0 R18 :start_lex ::= '='
550 Internal lexical start rule for <[Lex-2]>
551 Symbol IDs: <1> ::= <4>
552 Internal symbols: <[:start_lex]> ::= <[Lex-2]>
553 L0 R19 :start_lex ::= 'string'
554 Internal lexical start rule for <[Lex-3]>
555 Symbol IDs: <1> ::= <5>
556 Internal symbols: <[:start_lex]> ::= <[Lex-3]>
557 L0 R20 :start_lex ::= '('
558 Internal lexical start rule for <[Lex-4]>
559 Symbol IDs: <1> ::= <6>
560 Internal symbols: <[:start_lex]> ::= <[Lex-4]>
561 L0 R21 :start_lex ::= ')'
562 Internal lexical start rule for <[Lex-5]>
563 Symbol IDs: <1> ::= <7>
564 Internal symbols: <[:start_lex]> ::= <[Lex-5]>
565 L0 R22 :start_lex ::= '+'
566 Internal lexical start rule for <[Lex-6]>
567 Symbol IDs: <1> ::= <8>
568 Internal symbols: <[:start_lex]> ::= <[Lex-6]>
569 L0 R23 :start_lex ::= '*'
570 Internal lexical start rule for <[Lex-7]>
571 Symbol IDs: <1> ::= <9>
572 Internal symbols: <[:start_lex]> ::= <[Lex-7]>
573 L0 R24 :start_lex ::= '+'
574 Internal lexical start rule for <[Lex-8]>
575 Symbol IDs: <1> ::= <10>
576 Internal symbols: <[:start_lex]> ::= <[Lex-8]>
577 L0 R25 :start_lex ::= number
578 Internal lexical start rule for <number>
579 Symbol IDs: <1> ::= <30>
580 Internal symbols: <[:start_lex]> ::= <number>
581 L0 R26 :start_lex ::= string
582 Internal lexical start rule for <string>
583 Symbol IDs: <1> ::= <31>
584 Internal symbols: <[:start_lex]> ::= <string>
585 L0 R27 :start_lex ::= variable
586 Internal lexical start rule for <variable>
587 Symbol IDs: <1> ::= <29>
588 Internal symbols: <[:start_lex]> ::= <variable>
589 END_OF_SHOW_RULES_OUTPUT
590
591 # Marpa::R2::Display::End
592
593 # Marpa::R2::Display
594 # name: SLIF show_symbols() synopsis
595
596 my $show_symbols_output;
597 $show_symbols_output .= "G1 Symbols:\n";
598 $show_symbols_output .= $grammar->show_symbols(3);
599 $show_symbols_output .= "Lex (L0) Symbols:\n";
600 $show_symbols_output .= $grammar->show_symbols(3, 'L0');
601
602 # Marpa::R2::Display::End
603
604 # Marpa::R2::Display
605 # name: SLIF debug example show_symbols() output
606 # start-after-line: END_OF_SHOW_SYMBOLS_OUTPUT
607 # end-before-line: '^END_OF_SHOW_SYMBOLS_OUTPUT$'
608
609 Marpa::R2::Test::is( $show_symbols_output,
610 <<'END_OF_SHOW_SYMBOLS_OUTPUT', 'SLIF show_symbols()' );
611 G1 Symbols:
612 G1 S0 :start -- Internal G1 start symbol
613 Internal name: <[:start]>
614 G1 S1 'set' -- Internal lexical symbol for "'set'"
615 /* terminal */
616 Internal name: <[Lex-0]>
617 SLIF name: 'set'
618 G1 S2 'to' -- Internal lexical symbol for "'to'"
619 /* terminal */
620 Internal name: <[Lex-1]>
621 SLIF name: 'to'
622 G1 S3 '=' -- Internal lexical symbol for "'='"
623 /* terminal */
624 Internal name: <[Lex-2]>
625 SLIF name: '='
626 G1 S4 'string' -- Internal lexical symbol for "'string'"
627 /* terminal */
628 Internal name: <[Lex-3]>
629 SLIF name: 'string'
630 G1 S5 '(' -- Internal lexical symbol for "'('"
631 /* terminal */
632 Internal name: <[Lex-4]>
633 SLIF name: '('
634 G1 S6 ')' -- Internal lexical symbol for "')'"
635 /* terminal */
636 Internal name: <[Lex-5]>
637 SLIF name: ')'
638 G1 S7 '+' -- Internal lexical symbol for "'+'"
639 /* terminal */
640 Internal name: <[Lex-6]>
641 SLIF name: '+'
642 G1 S8 '*' -- Internal lexical symbol for "'*'"
643 /* terminal */
644 Internal name: <[Lex-7]>
645 SLIF name: '*'
646 G1 S9 '+' -- Internal lexical symbol for "'+'"
647 /* terminal */
648 Internal name: <[Lex-8]>
649 SLIF name: '+'
650 G1 S10 expression -- <expression> at priority 0
651 Internal name: <expression[0]>
652 SLIF name: expression
653 G1 S11 expression -- <expression> at priority 1
654 Internal name: <expression[1]>
655 SLIF name: expression
656 G1 S12 expression -- <expression> at priority 2
657 Internal name: <expression[2]>
658 SLIF name: expression
659 G1 S13 <numeric expression> -- <numeric expression> at priority 0
660 Internal name: <numeric expression[0]>
661 SLIF name: numeric expression
662 G1 S14 <numeric expression> -- <numeric expression> at priority 1
663 Internal name: <numeric expression[1]>
664 SLIF name: numeric expression
665 G1 S15 <numeric expression> -- <numeric expression> at priority 2
666 Internal name: <numeric expression[2]>
667 SLIF name: numeric expression
668 G1 S16 statements
669 Internal name: <statements>
670 G1 S17 statement
671 Internal name: <statement>
672 G1 S18 assignment
673 Internal name: <assignment>
674 G1 S19 <numeric assignment>
675 Internal name: <numeric assignment>
676 G1 S20 variable
677 /* terminal */
678 Internal name: <variable>
679 G1 S21 expression
680 Internal name: <expression>
681 G1 S22 <numeric expression>
682 Internal name: <numeric expression>
683 G1 S23 string
684 /* terminal */
685 Internal name: <string>
686 G1 S24 number
687 /* terminal */
688 Internal name: <number>
689 Lex (L0) Symbols:
690 L0 S0 :discard -- Internal LHS for lexer "L0" discard
691 Internal name: <[:discard]>
692 L0 S1 :start_lex -- Internal L0 (lexical) start symbol
693 Internal name: <[:start_lex]>
694 L0 S2 'set' -- Internal lexical symbol for "'set'"
695 Internal name: <[Lex-0]>
696 SLIF name: 'set'
697 L0 S3 'to' -- Internal lexical symbol for "'to'"
698 Internal name: <[Lex-1]>
699 SLIF name: 'to'
700 L0 S4 '=' -- Internal lexical symbol for "'='"
701 Internal name: <[Lex-2]>
702 SLIF name: '='
703 L0 S5 'string' -- Internal lexical symbol for "'string'"
704 Internal name: <[Lex-3]>
705 SLIF name: 'string'
706 L0 S6 '(' -- Internal lexical symbol for "'('"
707 Internal name: <[Lex-4]>
708 SLIF name: '('
709 L0 S7 ')' -- Internal lexical symbol for "')'"
710 Internal name: <[Lex-5]>
711 SLIF name: ')'
712 L0 S8 '+' -- Internal lexical symbol for "'+'"
713 Internal name: <[Lex-6]>
714 SLIF name: '+'
715 L0 S9 '*' -- Internal lexical symbol for "'*'"
716 Internal name: <[Lex-7]>
717 SLIF name: '*'
718 L0 S10 '+' -- Internal lexical symbol for "'+'"
719 Internal name: <[Lex-8]>
720 SLIF name: '+'
721 L0 S11 ['] -- Character class: [']
722 /* terminal */
723 Internal name: <[[']]>
724 SLIF name: [']
725 L0 S12 [\(] -- Character class: [\(]
726 /* terminal */
727 Internal name: <[[\(]]>
728 SLIF name: [\(]
729 L0 S13 [\)] -- Character class: [\)]
730 /* terminal */
731 Internal name: <[[\)]]>
732 SLIF name: [\)]
733 L0 S14 [\*] -- Character class: [\*]
734 /* terminal */
735 Internal name: <[[\*]]>
736 SLIF name: [\*]
737 L0 S15 [\+] -- Character class: [\+]
738 /* terminal */
739 Internal name: <[[\+]]>
740 SLIF name: [\+]
741 L0 S16 [\=] -- Character class: [\=]
742 /* terminal */
743 Internal name: <[[\=]]>
744 SLIF name: [\=]
745 L0 S17 [\d] -- Character class: [\d]
746 /* terminal */
747 Internal name: <[[\d]]>
748 SLIF name: [\d]
749 L0 S18 [\s] -- Character class: [\s]
750 /* terminal */
751 Internal name: <[[\s]]>
752 SLIF name: [\s]
753 L0 S19 [\w] -- Character class: [\w]
754 /* terminal */
755 Internal name: <[[\w]]>
756 SLIF name: [\w]
757 L0 S20 [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}] -- Character class: [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]
758 /* terminal */
759 Internal name: <[[^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]]>
760 SLIF name: [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]
761 L0 S21 [e] -- Character class: [e]
762 /* terminal */
763 Internal name: <[[e]]>
764 SLIF name: [e]
765 L0 S22 [g] -- Character class: [g]
766 /* terminal */
767 Internal name: <[[g]]>
768 SLIF name: [g]
769 L0 S23 [i] -- Character class: [i]
770 /* terminal */
771 Internal name: <[[i]]>
772 SLIF name: [i]
773 L0 S24 [n] -- Character class: [n]
774 /* terminal */
775 Internal name: <[[n]]>
776 SLIF name: [n]
777 L0 S25 [o] -- Character class: [o]
778 /* terminal */
779 Internal name: <[[o]]>
780 SLIF name: [o]
781 L0 S26 [r] -- Character class: [r]
782 /* terminal */
783 Internal name: <[[r]]>
784 SLIF name: [r]
785 L0 S27 [s] -- Character class: [s]
786 /* terminal */
787 Internal name: <[[s]]>
788 SLIF name: [s]
789 L0 S28 [t] -- Character class: [t]
790 /* terminal */
791 Internal name: <[[t]]>
792 SLIF name: [t]
793 L0 S29 variable
794 Internal name: <variable>
795 L0 S30 number
796 Internal name: <number>
797 L0 S31 string
798 Internal name: <string>
799 L0 S32 <string contents>
800 Internal name: <string contents>
801 L0 S33 whitespace
802 Internal name: <whitespace>
803 END_OF_SHOW_SYMBOLS_OUTPUT
804
805 # Marpa::R2::Display::End
806
807 our @TEST_ARRAY;
808 sub do_something { push @TEST_ARRAY, $_[0] }
809
810 @TEST_ARRAY = ();
811
812 # Marpa::R2::Display
813 # name: SLG symbol_ids() 2 arg synopsis
814
815 do_something($_) for $grammar->symbol_ids('L0');
816
817 # Marpa::R2::Display::End
818
819 Marpa::R2::Test::is(
820 ( join "\n", @TEST_ARRAY ),
821 ( join "\n", 0 .. 33 ),
822 'L0 symbol ids'
823 );
824
825 @TEST_ARRAY = ();
826
827 # Marpa::R2::Display
828 # name: SLG symbol_ids() synopsis
829
830 do_something($_) for $grammar->symbol_ids();
831
832 # Marpa::R2::Display::End
833
834 Marpa::R2::Test::is(
835 ( join "\n", @TEST_ARRAY ),
836 ( join "\n", 0 .. 24 ),
837 'G1 symbol ids'
838 );
839
840 @TEST_ARRAY = ();
841
842 # Marpa::R2::Display
843 # name: SLG rule_ids() synopsis
844
845 do_something($_) for $grammar->rule_ids();
846
847 # Marpa::R2::Display::End
848
849 Marpa::R2::Test::is(
850 ( join "\n", @TEST_ARRAY, '' ),
851 ( join "\n", 0 .. 19, '' ),
852 'G1 rule ids'
853 );
854
855 @TEST_ARRAY = ();
856
857 # Marpa::R2::Display
858 # name: SLG rule_ids() 2 arg synopsis
859
860 do_something($_) for $grammar->rule_ids('L0');
861
862 # Marpa::R2::Display::End
863
864 Marpa::R2::Test::is(
865 ( join "\n", @TEST_ARRAY, ''),
866 ( join "\n", 0 .. 27, '' ),
867 'L0 rule ids'
868 );
869
870 my $text;
871
872 $text = q{};
873
874 for my $rule_id ( $grammar->rule_ids() ) {
875
876 # Marpa::R2::Display
877 # name: SLG rule_expand() synopsis
878
879 my ($lhs_id, @rhs_ids) = $grammar->rule_expand($rule_id);
880 $text .= "Rule #$rule_id: $lhs_id ::= " . (join q{ }, @rhs_ids) . "\n";
881
882 # Marpa::R2::Display::End
883
884 }
885
886 Marpa::R2::Test::is( $text, <<'END_OF_TEXT', 'G1 symbol ids by rule id');
887 Rule #0: 16 ::= 17
888 Rule #1: 17 ::= 18
889 Rule #2: 17 ::= 19
890 Rule #3: 18 ::= 1 20 2 21
891 Rule #4: 19 ::= 20 3 22
892 Rule #5: 21 ::= 10
893 Rule #6: 10 ::= 11
894 Rule #7: 11 ::= 12
895 Rule #8: 12 ::= 20
896 Rule #9: 12 ::= 23
897 Rule #10: 11 ::= 4 5 22 6
898 Rule #11: 10 ::= 10 7 11
899 Rule #12: 22 ::= 13
900 Rule #13: 13 ::= 14
901 Rule #14: 14 ::= 15
902 Rule #15: 15 ::= 20
903 Rule #16: 15 ::= 24
904 Rule #17: 14 ::= 14 8 15
905 Rule #18: 13 ::= 13 9 14
906 Rule #19: 0 ::= 16
907 END_OF_TEXT
908
909 $text = q{};
910
911 for my $rule_id ( $grammar->rule_ids('L0') ) {
912
913 # Marpa::R2::Display
914 # name: SLG rule_expand() 2 args synopsis
915
916 my ($lhs_id, @rhs_ids) = $grammar->rule_expand($rule_id, 'L0');
917 $text .= "L0 Rule #$rule_id: $lhs_id ::= " . (join q{ }, @rhs_ids) . "\n";
918
919 # Marpa::R2::Display::End
920
921 }
922
923 Marpa::R2::Test::is( $text, <<'END_OF_TEXT', 'L0 symbol ids by rule id');
924 L0 Rule #0: 2 ::= 27 21 28
925 L0 Rule #1: 3 ::= 28 25
926 L0 Rule #2: 4 ::= 16
927 L0 Rule #3: 5 ::= 27 28 26 23 24 22
928 L0 Rule #4: 6 ::= 12
929 L0 Rule #5: 7 ::= 13
930 L0 Rule #6: 8 ::= 15
931 L0 Rule #7: 9 ::= 14
932 L0 Rule #8: 10 ::= 15
933 L0 Rule #9: 29 ::= 19
934 L0 Rule #10: 30 ::= 17
935 L0 Rule #11: 31 ::= 11 32 11
936 L0 Rule #12: 32 ::= 20
937 L0 Rule #13: 0 ::= 33
938 L0 Rule #14: 33 ::= 18
939 L0 Rule #15: 1 ::= 0
940 L0 Rule #16: 1 ::= 2
941 L0 Rule #17: 1 ::= 3
942 L0 Rule #18: 1 ::= 4
943 L0 Rule #19: 1 ::= 5
944 L0 Rule #20: 1 ::= 6
945 L0 Rule #21: 1 ::= 7
946 L0 Rule #22: 1 ::= 8
947 L0 Rule #23: 1 ::= 9
948 L0 Rule #24: 1 ::= 10
949 L0 Rule #25: 1 ::= 30
950 L0 Rule #26: 1 ::= 31
951 L0 Rule #27: 1 ::= 29
952 END_OF_TEXT
953
954 $text = q{};
955
956 for my $symbol_id ( $grammar->symbol_ids() ) {
957
958 # Marpa::R2::Display
959 # name: SLG symbol_name() synopsis
960
961 my $name = $grammar->symbol_name($symbol_id);
962 $text .= "symbol number: $symbol_id name: $name\n";
963
964 # Marpa::R2::Display::End
965
966 # Marpa::R2::Display
967 # name: SLG symbol_description() synopsis
968
969 my $description = $grammar->symbol_description($symbol_id)
970 // '[No description]';
971 $text .= "symbol number: $symbol_id description $description\n";
972
973 # Marpa::R2::Display::End
974
975 # Marpa::R2::Display
976 # name: SLG symbol_display_form() synopsis
977
978 my $display_form = $grammar->symbol_display_form($symbol_id);
979 $text
980 .= "symbol number: $symbol_id name in display form: $display_form\n";
981
982 # Marpa::R2::Display::End
983
984 # Marpa::R2::Display
985 # name: SLG symbol_dsl_form() synopsis
986
987 my $dsl_form = $grammar->symbol_dsl_form($symbol_id)
988 // '[No name in DSL form]';
989 $text .= "symbol number: $symbol_id DSL form: $dsl_form\n";
990
991 # Marpa::R2::Display::End
992
993 } ## end for my $symbol_id ( $grammar->symbol_ids() )
994
995 Marpa::R2::Test::is( $text, <<'END_OF_TEXT', 'G1 symbol names and description');
996 symbol number: 0 name: [:start]
997 symbol number: 0 description Internal G1 start symbol
998 symbol number: 0 name in display form: :start
999 symbol number: 0 DSL form: [No name in DSL form]
1000 symbol number: 1 name: [Lex-0]
1001 symbol number: 1 description Internal lexical symbol for "'set'"
1002 symbol number: 1 name in display form: 'set'
1003 symbol number: 1 DSL form: 'set'
1004 symbol number: 2 name: [Lex-1]
1005 symbol number: 2 description Internal lexical symbol for "'to'"
1006 symbol number: 2 name in display form: 'to'
1007 symbol number: 2 DSL form: 'to'
1008 symbol number: 3 name: [Lex-2]
1009 symbol number: 3 description Internal lexical symbol for "'='"
1010 symbol number: 3 name in display form: '='
1011 symbol number: 3 DSL form: '='
1012 symbol number: 4 name: [Lex-3]
1013 symbol number: 4 description Internal lexical symbol for "'string'"
1014 symbol number: 4 name in display form: 'string'
1015 symbol number: 4 DSL form: 'string'
1016 symbol number: 5 name: [Lex-4]
1017 symbol number: 5 description Internal lexical symbol for "'('"
1018 symbol number: 5 name in display form: '('
1019 symbol number: 5 DSL form: '('
1020 symbol number: 6 name: [Lex-5]
1021 symbol number: 6 description Internal lexical symbol for "')'"
1022 symbol number: 6 name in display form: ')'
1023 symbol number: 6 DSL form: ')'
1024 symbol number: 7 name: [Lex-6]
1025 symbol number: 7 description Internal lexical symbol for "'+'"
1026 symbol number: 7 name in display form: '+'
1027 symbol number: 7 DSL form: '+'
1028 symbol number: 8 name: [Lex-7]
1029 symbol number: 8 description Internal lexical symbol for "'*'"
1030 symbol number: 8 name in display form: '*'
1031 symbol number: 8 DSL form: '*'
1032 symbol number: 9 name: [Lex-8]
1033 symbol number: 9 description Internal lexical symbol for "'+'"
1034 symbol number: 9 name in display form: '+'
1035 symbol number: 9 DSL form: '+'
1036 symbol number: 10 name: expression[0]
1037 symbol number: 10 description <expression> at priority 0
1038 symbol number: 10 name in display form: expression
1039 symbol number: 10 DSL form: expression
1040 symbol number: 11 name: expression[1]
1041 symbol number: 11 description <expression> at priority 1
1042 symbol number: 11 name in display form: expression
1043 symbol number: 11 DSL form: expression
1044 symbol number: 12 name: expression[2]
1045 symbol number: 12 description <expression> at priority 2
1046 symbol number: 12 name in display form: expression
1047 symbol number: 12 DSL form: expression
1048 symbol number: 13 name: numeric expression[0]
1049 symbol number: 13 description <numeric expression> at priority 0
1050 symbol number: 13 name in display form: <numeric expression>
1051 symbol number: 13 DSL form: numeric expression
1052 symbol number: 14 name: numeric expression[1]
1053 symbol number: 14 description <numeric expression> at priority 1
1054 symbol number: 14 name in display form: <numeric expression>
1055 symbol number: 14 DSL form: numeric expression
1056 symbol number: 15 name: numeric expression[2]
1057 symbol number: 15 description <numeric expression> at priority 2
1058 symbol number: 15 name in display form: <numeric expression>
1059 symbol number: 15 DSL form: numeric expression
1060 symbol number: 16 name: statements
1061 symbol number: 16 description [No description]
1062 symbol number: 16 name in display form: statements
1063 symbol number: 16 DSL form: [No name in DSL form]
1064 symbol number: 17 name: statement
1065 symbol number: 17 description [No description]
1066 symbol number: 17 name in display form: statement
1067 symbol number: 17 DSL form: [No name in DSL form]
1068 symbol number: 18 name: assignment
1069 symbol number: 18 description [No description]
1070 symbol number: 18 name in display form: assignment
1071 symbol number: 18 DSL form: [No name in DSL form]
1072 symbol number: 19 name: numeric assignment
1073 symbol number: 19 description [No description]
1074 symbol number: 19 name in display form: <numeric assignment>
1075 symbol number: 19 DSL form: [No name in DSL form]
1076 symbol number: 20 name: variable
1077 symbol number: 20 description [No description]
1078 symbol number: 20 name in display form: variable
1079 symbol number: 20 DSL form: [No name in DSL form]
1080 symbol number: 21 name: expression
1081 symbol number: 21 description [No description]
1082 symbol number: 21 name in display form: expression
1083 symbol number: 21 DSL form: [No name in DSL form]
1084 symbol number: 22 name: numeric expression
1085 symbol number: 22 description [No description]
1086 symbol number: 22 name in display form: <numeric expression>
1087 symbol number: 22 DSL form: [No name in DSL form]
1088 symbol number: 23 name: string
1089 symbol number: 23 description [No description]
1090 symbol number: 23 name in display form: string
1091 symbol number: 23 DSL form: [No name in DSL form]
1092 symbol number: 24 name: number
1093 symbol number: 24 description [No description]
1094 symbol number: 24 name in display form: number
1095 symbol number: 24 DSL form: [No name in DSL form]
1096 END_OF_TEXT
1097
1098 $text = q{};
1099
1100 for my $rule_id ( $grammar->rule_ids() ) {
1101
1102 # Marpa::R2::Display
1103 # name: SLG rule_show() synopsis
1104
1105 my $rule_description = $grammar->rule_show($rule_id);
1106
1107 # Marpa::R2::Display::End
1108
1109 $text .= "$rule_description\n";
1110
1111 }
1112
1113 Marpa::R2::Test::is( $text, <<'END_OF_TEXT', 'G1 rule_show() by rule id');
1114 statements ::= statement *
1115 statement ::= assignment
1116 statement ::= <numeric assignment>
1117 assignment ::= 'set' variable 'to' expression
1118 <numeric assignment> ::= variable '=' <numeric expression>
1119 expression ::= expression
1120 expression ::= expression
1121 expression ::= expression
1122 expression ::= variable
1123 expression ::= string
1124 expression ::= 'string' '(' <numeric expression> ')'
1125 expression ::= expression '+' expression
1126 <numeric expression> ::= <numeric expression>
1127 <numeric expression> ::= <numeric expression>
1128 <numeric expression> ::= <numeric expression>
1129 <numeric expression> ::= variable
1130 <numeric expression> ::= number
1131 <numeric expression> ::= <numeric expression> '*' <numeric expression>
1132 <numeric expression> ::= <numeric expression> '+' <numeric expression>
1133 :start ::= statements
1134 END_OF_TEXT
1135
1136 $text = q{};
1137
1138 for my $rule_id ( $grammar->rule_ids('L0') ) {
1139
1140 # Marpa::R2::Display
1141 # name: SLG rule_show() 2 args synopsis
1142
1143 my $rule_description = $grammar->rule_show($rule_id, 'L0');
1144
1145 # Marpa::R2::Display::End
1146 $text .= "$rule_description\n";
1147
1148 }
1149
1150 Marpa::R2::Test::is( $text, <<'END_OF_TEXT', 'L0 rule_show() by rule id');
1151 'set' ::= [s] [e] [t]
1152 'to' ::= [t] [o]
1153 '=' ::= [\=]
1154 'string' ::= [s] [t] [r] [i] [n] [g]
1155 '(' ::= [\(]
1156 ')' ::= [\)]
1157 '+' ::= [\+]
1158 '*' ::= [\*]
1159 '+' ::= [\+]
1160 variable ::= [\w] +
1161 number ::= [\d] +
1162 string ::= ['] <string contents> [']
1163 <string contents> ::= [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}] +
1164 :discard ::= whitespace
1165 whitespace ::= [\s] +
1166 :start_lex ::= :discard
1167 :start_lex ::= 'set'
1168 :start_lex ::= 'to'
1169 :start_lex ::= '='
1170 :start_lex ::= 'string'
1171 :start_lex ::= '('
1172 :start_lex ::= ')'
1173 :start_lex ::= '+'
1174 :start_lex ::= '*'
1175 :start_lex ::= '+'
1176 :start_lex ::= number
1177 :start_lex ::= string
1178 :start_lex ::= variable
1179 END_OF_TEXT
1180
1181 $text = '';
1182
1183 for my $symbol_id ( $grammar->symbol_ids('L0') ) {
1184
1185 # Marpa::R2::Display
1186 # name: SLG symbol_name() 2 arg synopsis
1187
1188 my $name = $grammar->symbol_name( $symbol_id, 'L0' );
1189 $text .= "L0 symbol number: $symbol_id name: $name\n";
1190
1191 # Marpa::R2::Display::End
1192
1193 # Marpa::R2::Display
1194 # name: SLG symbol_description() 2 arg synopsis
1195
1196 my $description = $grammar->symbol_description( $symbol_id, 'L0' )
1197 // '[No description]';
1198 $text .= "L0 symbol number: $symbol_id description $description\n";
1199
1200 # Marpa::R2::Display::End
1201
1202 # Marpa::R2::Display
1203 # name: SLG symbol_display_form() 2 arg synopsis
1204
1205 my $display_form = $grammar->symbol_display_form( $symbol_id, 'L0' );
1206 $text
1207 .= "L0 symbol number: $symbol_id name in display form: $display_form\n";
1208
1209 # Marpa::R2::Display::End
1210
1211 # Marpa::R2::Display
1212 # name: SLG symbol_dsl_form() 2 arg synopsis
1213
1214 my $dsl_form = $grammar->symbol_dsl_form( $symbol_id, 'L0' )
1215 // '[No name in DSL form]';
1216 $text .= "L0 symbol number: $symbol_id DSL form: $dsl_form\n";
1217
1218 # Marpa::R2::Display::End
1219
1220 } ## end for my $symbol_id ( $grammar->symbol_ids('L0') )
1221
1222 Marpa::R2::Test::is( $text, <<'END_OF_TEXT', 'L0 symbol names and description');
1223 L0 symbol number: 0 name: [:discard]
1224 L0 symbol number: 0 description Internal LHS for lexer "L0" discard
1225 L0 symbol number: 0 name in display form: :discard
1226 L0 symbol number: 0 DSL form: [No name in DSL form]
1227 L0 symbol number: 1 name: [:start_lex]
1228 L0 symbol number: 1 description Internal L0 (lexical) start symbol
1229 L0 symbol number: 1 name in display form: :start_lex
1230 L0 symbol number: 1 DSL form: [No name in DSL form]
1231 L0 symbol number: 2 name: [Lex-0]
1232 L0 symbol number: 2 description Internal lexical symbol for "'set'"
1233 L0 symbol number: 2 name in display form: 'set'
1234 L0 symbol number: 2 DSL form: 'set'
1235 L0 symbol number: 3 name: [Lex-1]
1236 L0 symbol number: 3 description Internal lexical symbol for "'to'"
1237 L0 symbol number: 3 name in display form: 'to'
1238 L0 symbol number: 3 DSL form: 'to'
1239 L0 symbol number: 4 name: [Lex-2]
1240 L0 symbol number: 4 description Internal lexical symbol for "'='"
1241 L0 symbol number: 4 name in display form: '='
1242 L0 symbol number: 4 DSL form: '='
1243 L0 symbol number: 5 name: [Lex-3]
1244 L0 symbol number: 5 description Internal lexical symbol for "'string'"
1245 L0 symbol number: 5 name in display form: 'string'
1246 L0 symbol number: 5 DSL form: 'string'
1247 L0 symbol number: 6 name: [Lex-4]
1248 L0 symbol number: 6 description Internal lexical symbol for "'('"
1249 L0 symbol number: 6 name in display form: '('
1250 L0 symbol number: 6 DSL form: '('
1251 L0 symbol number: 7 name: [Lex-5]
1252 L0 symbol number: 7 description Internal lexical symbol for "')'"
1253 L0 symbol number: 7 name in display form: ')'
1254 L0 symbol number: 7 DSL form: ')'
1255 L0 symbol number: 8 name: [Lex-6]
1256 L0 symbol number: 8 description Internal lexical symbol for "'+'"
1257 L0 symbol number: 8 name in display form: '+'
1258 L0 symbol number: 8 DSL form: '+'
1259 L0 symbol number: 9 name: [Lex-7]
1260 L0 symbol number: 9 description Internal lexical symbol for "'*'"
1261 L0 symbol number: 9 name in display form: '*'
1262 L0 symbol number: 9 DSL form: '*'
1263 L0 symbol number: 10 name: [Lex-8]
1264 L0 symbol number: 10 description Internal lexical symbol for "'+'"
1265 L0 symbol number: 10 name in display form: '+'
1266 L0 symbol number: 10 DSL form: '+'
1267 L0 symbol number: 11 name: [[']]
1268 L0 symbol number: 11 description Character class: [']
1269 L0 symbol number: 11 name in display form: [']
1270 L0 symbol number: 11 DSL form: [']
1271 L0 symbol number: 12 name: [[\(]]
1272 L0 symbol number: 12 description Character class: [\(]
1273 L0 symbol number: 12 name in display form: [\(]
1274 L0 symbol number: 12 DSL form: [\(]
1275 L0 symbol number: 13 name: [[\)]]
1276 L0 symbol number: 13 description Character class: [\)]
1277 L0 symbol number: 13 name in display form: [\)]
1278 L0 symbol number: 13 DSL form: [\)]
1279 L0 symbol number: 14 name: [[\*]]
1280 L0 symbol number: 14 description Character class: [\*]
1281 L0 symbol number: 14 name in display form: [\*]
1282 L0 symbol number: 14 DSL form: [\*]
1283 L0 symbol number: 15 name: [[\+]]
1284 L0 symbol number: 15 description Character class: [\+]
1285 L0 symbol number: 15 name in display form: [\+]
1286 L0 symbol number: 15 DSL form: [\+]
1287 L0 symbol number: 16 name: [[\=]]
1288 L0 symbol number: 16 description Character class: [\=]
1289 L0 symbol number: 16 name in display form: [\=]
1290 L0 symbol number: 16 DSL form: [\=]
1291 L0 symbol number: 17 name: [[\d]]
1292 L0 symbol number: 17 description Character class: [\d]
1293 L0 symbol number: 17 name in display form: [\d]
1294 L0 symbol number: 17 DSL form: [\d]
1295 L0 symbol number: 18 name: [[\s]]
1296 L0 symbol number: 18 description Character class: [\s]
1297 L0 symbol number: 18 name in display form: [\s]
1298 L0 symbol number: 18 DSL form: [\s]
1299 L0 symbol number: 19 name: [[\w]]
1300 L0 symbol number: 19 description Character class: [\w]
1301 L0 symbol number: 19 name in display form: [\w]
1302 L0 symbol number: 19 DSL form: [\w]
1303 L0 symbol number: 20 name: [[^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]]
1304 L0 symbol number: 20 description Character class: [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]
1305 L0 symbol number: 20 name in display form: [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]
1306 L0 symbol number: 20 DSL form: [^'\x{0A}\x{0B}\x{0C}\x{0D}\x{0085}\x{2028}\x{2029}]
1307 L0 symbol number: 21 name: [[e]]
1308 L0 symbol number: 21 description Character class: [e]
1309 L0 symbol number: 21 name in display form: [e]
1310 L0 symbol number: 21 DSL form: [e]
1311 L0 symbol number: 22 name: [[g]]
1312 L0 symbol number: 22 description Character class: [g]
1313 L0 symbol number: 22 name in display form: [g]
1314 L0 symbol number: 22 DSL form: [g]
1315 L0 symbol number: 23 name: [[i]]
1316 L0 symbol number: 23 description Character class: [i]
1317 L0 symbol number: 23 name in display form: [i]
1318 L0 symbol number: 23 DSL form: [i]
1319 L0 symbol number: 24 name: [[n]]
1320 L0 symbol number: 24 description Character class: [n]
1321 L0 symbol number: 24 name in display form: [n]
1322 L0 symbol number: 24 DSL form: [n]
1323 L0 symbol number: 25 name: [[o]]
1324 L0 symbol number: 25 description Character class: [o]
1325 L0 symbol number: 25 name in display form: [o]
1326 L0 symbol number: 25 DSL form: [o]
1327 L0 symbol number: 26 name: [[r]]
1328 L0 symbol number: 26 description Character class: [r]
1329 L0 symbol number: 26 name in display form: [r]
1330 L0 symbol number: 26 DSL form: [r]
1331 L0 symbol number: 27 name: [[s]]
1332 L0 symbol number: 27 description Character class: [s]
1333 L0 symbol number: 27 name in display form: [s]
1334 L0 symbol number: 27 DSL form: [s]
1335 L0 symbol number: 28 name: [[t]]
1336 L0 symbol number: 28 description Character class: [t]
1337 L0 symbol number: 28 name in display form: [t]
1338 L0 symbol number: 28 DSL form: [t]
1339 L0 symbol number: 29 name: variable
1340 L0 symbol number: 29 description [No description]
1341 L0 symbol number: 29 name in display form: variable
1342 L0 symbol number: 29 DSL form: [No name in DSL form]
1343 L0 symbol number: 30 name: number
1344 L0 symbol number: 30 description [No description]
1345 L0 symbol number: 30 name in display form: number
1346 L0 symbol number: 30 DSL form: [No name in DSL form]
1347 L0 symbol number: 31 name: string
1348 L0 symbol number: 31 description [No description]
1349 L0 symbol number: 31 name in display form: string
1350 L0 symbol number: 31 DSL form: [No name in DSL form]
1351 L0 symbol number: 32 name: string contents
1352 L0 symbol number: 32 description [No description]
1353 L0 symbol number: 32 name in display form: <string contents>
1354 L0 symbol number: 32 DSL form: [No name in DSL form]
1355 L0 symbol number: 33 name: whitespace
1356 L0 symbol number: 33 description [No description]
1357 L0 symbol number: 33 name in display form: whitespace
1358 L0 symbol number: 33 DSL form: [No name in DSL form]
1359 END_OF_TEXT
1360
1361 1; # In case used as "do" file
1362
1363 # Local Variables:
1364 # mode: cperl
1365 # cperl-indent-level: 4
1366 # fill-column: 100
1367 # End:
1368 # vim: expandtab shiftwidth=4: