361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
+
+
|
Report.Report_Exception (Name & " (in Query_Event)", Error);
if Called then
Report.Info (" Process was called with atom """
& To_String (Output.Get_Data) & '"');
end if;
end;
end;
Report.Item (Name, NT.Success);
exception
when Error : others => Report.Report_Exception (Name, Error);
end Parser_Interface;
procedure Quoted_Escapes (Report : in out NT.Reporter'Class) is
CR : constant Character := Character'Val (13);
|
407
408
409
410
411
412
413
414
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
& "10:hidden-end)(12:hidden-begin"
& "3:end)"
& "(16:overflowing atom)"));
begin
Test (Report);
end Special_Subexpression;
procedure Subparser_Interface (Report : in out NT.Reporter'Class) is
Name : constant String := "Subparser interface";
Source : constant Atom
:= To_Atom ("(begin(command arg1 (subarg1 subarg2) arg3)end)");
begin
declare
Input : aliased Test_Tools.Memory_Stream;
Parser : aliased Parsers.Parser;
Sub : Subparser (Parser'Access, Input'Access);
Event : Events.Event;
begin
Input.Set_Data (Source);
-- Read header
Parser.Next_Event (Input'Access);
pragma Assert (Parser.Current_Event = Events.Open_List);
Parser.Next_Event (Input'Access);
pragma Assert (Parser.Current_Event = Events.Add_Atom
and then Parser.Current_Atom = To_Atom ("begin"));
Parser.Next_Event (Input'Access);
pragma Assert (Parser.Current_Event = Events.Open_List);
Parser.Next_Event (Input'Access);
pragma Assert (Parser.Current_Event = Events.Add_Atom
and then Parser.Current_Atom = To_Atom ("command"));
-- Use subparser as command arguments
Sub.Next (Event);
if Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser current event: "
& Events.Event'Image (Event));
return;
end if;
if Sub.Current_Atom /= To_Atom ("arg1") then
Report.Item (Name, NT.Fail);
Test_Tools.Dump_Atom (Report, Sub.Current_Atom,
"Unexpected first subparser atom");
return;
end if;
Sub.Next (Event);
if Event /= Events.Open_List then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser second event: "
& Events.Event'Image (Event));
return;
end if;
if Sub.Current_Level /= 3 then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected nesting level"
& Natural'Image (Sub.Current_Level));
end if;
Sub.Next (Event);
if Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser third event: "
& Events.Event'Image (Event));
return;
end if;
declare
Data : Atom (21 .. 40);
Length : Count;
begin
Sub.Read_Atom (Data, Length);
if Data (Data'First .. Data'First + Length - 1)
/= To_Atom ("subarg1")
then
Report.Item (Name, NT.Fail);
Test_Tools.Dump_Atom (Report,
Data (Data'First .. Data'First + Length - 1),
"Unexpected first sub-argument atom:");
return;
end if;
end;
Sub.Next (Event);
if Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser third event: "
& Events.Event'Image (Event));
return;
end if;
Sub.Finish;
-- Check final state of parser
if Parser.Current_Event /= Events.Close_List then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected parser final state: "
& Events.Event'Image (Parser.Current_Event));
return;
end if;
if Parser.Current_Level /= 1 then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected parser final level:"
& Natural'Image (Parser.Current_Level));
return;
end if;
Parser.Next_Event (Input'Access);
if Parser.Current_Event /= Events.Add_Atom then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected parser penultimate state: "
& Events.Event'Image (Parser.Current_Event));
return;
end if;
if Parser.Current_Atom /= To_Atom ("end") then
Report.Item (Name, NT.Fail);
Test_Tools.Dump_Atom (Report, Parser.Current_Atom,
"Parser last atom");
end if;
-- Check subparser error states
if Sub.Current_Event /= Events.End_Of_Input then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser final state: "
& Events.Event'Image (Parser.Current_Event));
return;
end if;
if Sub.Current_Level /= 2 then
Report.Item (Name, NT.Fail);
Report.Info ("Unexpected subparser final level:"
& Natural'Image (Parser.Current_Level));
return;
end if;
begin
declare
Buffer : constant Atom := Sub.Current_Atom;
begin
Report.Item (Name, NT.Fail);
Report.Info
("No exception raised in Current_Atom on finished subparser");
Test_Tools.Dump_Atom (Report, Buffer);
end;
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Current_Atom)", Error);
return;
end;
declare
Buffer : Atom (1 .. 100);
Length : Count := 0;
begin
Sub.Read_Atom (Buffer, Length);
Report.Item (Name, NT.Fail);
Report.Info
("No exception raised in Read_Atom on finished subparser");
Test_Tools.Dump_Atom (Report, Buffer (1 .. Length));
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Read_Atom)", Error);
Test_Tools.Dump_Atom (Report, Buffer (1 .. Length), "Buffer");
return;
end;
declare
Called : Boolean := False;
Output : Test_Tools.Memory_Stream;
procedure Process (Data : in Atom);
procedure Process (Data : in Atom) is
begin
Called := True;
Output.Set_Data (Data);
end Process;
begin
Sub.Query_Atom (Process'Access);
Report.Item (Name, NT.Fail);
Report.Info
("No exception raised in Query_Atom on finished subparser");
if Called then
Test_Tools.Dump_Atom (Report, Output.Get_Data,
"Process called with");
end if;
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Query_Event)", Error);
if Called then
Test_Tools.Dump_Atom (Report, Output.Get_Data,
"Process called with");
end if;
return;
end;
begin
Sub.Next (Event);
Report.Item (Name, NT.Fail);
Report.Info ("No exception raised in Next on finished subparser");
Report.Info (" returned event: " & Events.Event'Image (Event));
return;
exception
when Constraint_Error => null;
when Error : others =>
Report.Report_Exception (Name & " (in Next)", Error);
return;
end;
-- Check that above subparser calls have not tampered with Parser
if Parser.Current_Event /= Events.Add_Atom
or else Parser.Current_Level /= 1
or else Parser.Current_Atom /= To_Atom ("end")
then
Report.Item (Name, NT.Fail);
Report.Info ("Parser state changed after calling methods on "
& "finished subparser");
return;
end if;
end;
Report.Item (Name, NT.Success);
exception
when Error : others => Report.Report_Exception (Name, Error);
end Subparser_Interface;
end Natools.S_Expressions.Parsers.Tests;
|