diff options
Diffstat (limited to 'example/ssss.adb')
-rw-r--r-- | example/ssss.adb | 28 |
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; |