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 | |
parent | 170ca0a62968e78ead08b21bc5304b766fa63eb5 (diff) |
A simpler example added
-rw-r--r-- | example/ssss.adb | 67 | ||||
-rw-r--r-- | examples.gpr | 7 |
2 files changed, 71 insertions, 3 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; + + diff --git a/examples.gpr b/examples.gpr index 1921d31..9e1d531 100644 --- a/examples.gpr +++ b/examples.gpr @@ -12,16 +12,17 @@ project Examples is for Source_Dirs use ("example/**"); for Object_Dir use "obj"; for Exec_Dir use "bin"; - for Main use ("sentence.adb"); + for Main use ("sentence.adb", "ssss.adb"); package Builder is - for Executable("sentence.adb") use "sentence"; + for Executable ("sentence.adb") use "sentence"; + for Executable ("ssss.adb") use "ssss"; end Builder; package Compiler is - for Default_Switches("Ada") use ("-gnaty4aAbcefhiklM100nprt"); + for Default_Switches ("Ada") use ("-gnaty4aAbcefhiklM100nprt"); end Compiler; |