From ee04783f617da18c15ca2b554081bcb7df418cf4 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sat, 5 Dec 2020 12:56:53 +1100 Subject: A simpler example added --- example/ssss.adb | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 example/ssss.adb (limited to 'example') diff --git a/example/ssss.adb b/example/ssss.adb new file mode 100644 index 0000000..56f980d --- /dev/null +++ b/example/ssss.adb @@ -0,0 +1,67 @@ + + +with + + Ada.Text_IO, + Packrat.No_Lex, + Packrat.Utilities; + +use + + Ada.Text_IO; + + +procedure Ssss is + + + Input : String := "xxxx"; + + type Parser_Labels is (S); + + package My_Rat is new Packrat.No_Lex (Parser_Labels, Character, String); + + + + + package S_Redir is new My_Rat.Parsers.Redirect; + + function Match_X is new My_Rat.Parsers.Match ('x'); + function S_Seq is new My_Rat.Parsers.Sequence + ((Match_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); + + package Parser is new My_Rat.Parsers.Parse_Once (S); + + + + + Result_Graph : My_Rat.Parser_Result; + + +begin + + + S_Redir.Set (S'Access); + + Result_Graph := Parser.Parse (Input); + + + Put_Line ("Input:"); + Put_Line (Input); + New_Line; + + Put_Line ("Parser graph output:"); + Put_Line (My_Rat.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)); + end loop; + + +end Ssss; + + -- cgit