diff options
author | Jed Barber <jjbarber@y7mail.com> | 2020-12-05 12:56:53 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2020-12-05 12:56:53 +1100 |
commit | ee04783f617da18c15ca2b554081bcb7df418cf4 (patch) | |
tree | c9e79767541001741e6c6b8cbb6515593255c47e /example | |
parent | 170ca0a62968e78ead08b21bc5304b766fa63eb5 (diff) |
A simpler example added
Diffstat (limited to 'example')
-rw-r--r-- | example/ssss.adb | 67 |
1 files changed, 67 insertions, 0 deletions
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; + + |