summaryrefslogtreecommitdiff
path: root/example/ssss.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2021-01-23 18:37:42 +1100
committerJed Barber <jjbarber@y7mail.com>2021-01-23 18:37:42 +1100
commit7c1db8ca1988ff9a9c9054be012eac830674f9d3 (patch)
treed5c9701d31d971479002ad751f885134039699b7 /example/ssss.adb
parentc7195329c60123b2363ba13863f6951a21d0ff57 (diff)
Slight improvements to example codeHEADmaster
Diffstat (limited to 'example/ssss.adb')
-rw-r--r--example/ssss.adb28
1 files changed, 17 insertions, 11 deletions
diff --git a/example/ssss.adb b/example/ssss.adb
index 2c29b2f..25faa21 100644
--- a/example/ssss.adb
+++ b/example/ssss.adb
@@ -23,22 +23,28 @@ procedure Ssss is
type Parser_Labels is (S, X);
package My_Rat is new Packrat.No_Lex (Parser_Labels, Character, String);
+ use My_Rat;
- package S_Redir is new My_Rat.Parsers.Redirect;
+ -- Parser grammar from page 5 of
+ -- Parser Combinators for Ambiguous Left-Recursive Grammars
+ -- (Richard A. Frost, Rahmatullah Hafiz, Paul Callaghan, 2008)
- function Match_X is new My_Rat.Parsers.Match ('x');
- function Let_X is new My_Rat.Parsers.Stamp (X, Match_X);
+ -- s ::= "x" s s | empty
- function S_Seq is new My_Rat.Parsers.Sequence
+ package S_Redir is new Parsers.Redirect;
+
+ function Match_X is new Parsers.Match ('x');
+ function Let_X is new Parsers.Stamp (X, Match_X);
+
+ function S_Seq is new Parsers.Sequence
((Let_X'Access, S_Redir.Call'Access, S_Redir.Call'Access));
- function S_Choice is new My_Rat.Parsers.Choice
- ((S_Seq'Access, My_Rat.Parsers.Empty'Access));
- function S is new My_Rat.Parsers.Stamp (S, S_Choice);
+ function S_Choice is new Parsers.Choice_2 (S_Seq, My_Rat.Parsers.Empty);
+ function S is new Parsers.Stamp (S, S_Choice);
- package Parser is new My_Rat.Parsers.Parse_Once (S);
+ package Parser is new Parsers.Parse_Once (S);
@@ -55,7 +61,7 @@ procedure Ssss is
package Comlin renames Ada.Command_Line;
- Result_Graph : My_Rat.Parser_Result;
+ Result_Graph : Parser_Result;
Silent_Running : Boolean := False;
Input_Length : Positive := 4;
@@ -95,12 +101,12 @@ begin
New_Line;
Put_Line ("Parser graph output:");
- Put_Line (My_Rat.Parse_Graphs.Debug_String (Result_Graph));
+ Put_Line (Parse_Graphs.Debug_String (Result_Graph));
New_Line;
Put_Line ("Root tokens:");
for T of Result_Graph.Root_Elements loop
- Put (My_Rat.Parser_Tokens.Debug_String (T));
+ Put (Parser_Tokens.Debug_String (T));
end loop;
end if;