summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/sentence.adb27
1 files changed, 12 insertions, 15 deletions
diff --git a/example/sentence.adb b/example/sentence.adb
index 288deeb..f522b5f 100644
--- a/example/sentence.adb
+++ b/example/sentence.adb
@@ -33,29 +33,26 @@ procedure Sentence is
function Many_Blank is new My_Rat.Lexers.Many (Sat_Blank, 1);
function Whitespace is new My_Rat.Lexers.Ignore (Whitespace, Many_Blank);
- function Scanner is new My_Rat.Lexers.Scan_Only ((Word'Access, Whitespace'Access));
+ package Scanner is new My_Rat.Lexers.Scan_Once ((Word'Access, Whitespace'Access));
- function Is_I is new My_Rat.Lexer_Tokens.Is_Value ("i");
- function Is_Saw is new My_Rat.Lexer_Tokens.Is_Value ("saw");
- function Is_A is new My_Rat.Lexer_Tokens.Is_Value ("a");
- function Is_Man is new My_Rat.Lexer_Tokens.Is_Value ("man");
function Is_In is new My_Rat.Lexer_Tokens.Is_Value ("in");
- function Is_The is new My_Rat.Lexer_Tokens.Is_Value ("the");
- function Is_Park is new My_Rat.Lexer_Tokens.Is_Value ("park");
function Is_With is new My_Rat.Lexer_Tokens.Is_Value ("with");
- function Is_Bat is new My_Rat.Lexer_Tokens.Is_Value ("bat");
-
function Sat_In is new My_Rat.Parsers.Satisfy (Is_In);
function Sat_With is new My_Rat.Parsers.Satisfy (Is_With);
function Prep_Choice is new My_Rat.Parsers.Choice ((Sat_In'Access, Sat_With'Access));
function Prep is new My_Rat.Parsers.Stamp (Prep, Prep_Choice);
+ function Is_Saw is new My_Rat.Lexer_Tokens.Is_Value ("saw");
function Sat_Saw is new My_Rat.Parsers.Satisfy (Is_Saw);
function Verb is new My_Rat.Parsers.Stamp (Verb, Sat_Saw);
+ function Is_I is new My_Rat.Lexer_Tokens.Is_Value ("i");
+ function Is_Man is new My_Rat.Lexer_Tokens.Is_Value ("man");
+ function Is_Park is new My_Rat.Lexer_Tokens.Is_Value ("park");
+ function Is_Bat is new My_Rat.Lexer_Tokens.Is_Value ("bat");
function Sat_I is new My_Rat.Parsers.Satisfy (Is_I);
function Sat_Man is new My_Rat.Parsers.Satisfy (Is_Man);
function Sat_Park is new My_Rat.Parsers.Satisfy (Is_Park);
@@ -64,11 +61,14 @@ procedure Sentence is
((Sat_I'Access, Sat_Man'Access, Sat_Park'Access, Sat_Bat'Access));
function Noun is new My_Rat.Parsers.Stamp (Noun, Noun_Choice);
+ function Is_A is new My_Rat.Lexer_Tokens.Is_Value ("a");
+ function Is_The is new My_Rat.Lexer_Tokens.Is_Value ("the");
function Sat_A is new My_Rat.Parsers.Satisfy (Is_A);
function Sat_The is new My_Rat.Parsers.Satisfy (Is_The);
function Det_Choice is new My_Rat.Parsers.Choice ((Sat_A'Access, Sat_The'Access));
function Det is new My_Rat.Parsers.Stamp (Det, Det_Choice);
+ -- These redirectors are needed to resolve circular references in the instantiations.
package NP_Redir is new My_Rat.Parsers.Redirect;
package S_Redir is new My_Rat.Parsers.Redirect;
@@ -89,15 +89,12 @@ procedure Sentence is
function S_Choice is new My_Rat.Parsers.Choice ((S_Seq_1'Access, S_Seq_2'Access));
function S is new My_Rat.Parsers.Stamp (S, S_Choice);
- function Parser is new My_Rat.Parsers.Parse_Only (S);
-
+ package Parser is new My_Rat.Parsers.Parse_Once (S);
- My_Lexer_Context : My_Rat.Lexers.Lexer_Context := My_Rat.Lexers.Empty_Context;
- My_Parser_Context : My_Rat.Parsers.Parser_Context := My_Rat.Parsers.Empty_Context;
- Lexed_Tokens : My_Rat.Lexer_Result := Scanner (Input, My_Lexer_Context);
+ Lexed_Tokens : My_Rat.Lexer_Result := Scanner.Scan (Input);
Result_Graph : My_Rat.Parser_Result;
@@ -109,7 +106,7 @@ begin
NP_Redir.Set (NP'Access);
S_Redir.Set (S'Access);
- Result_Graph := Parser (Lexed_Tokens, My_Parser_Context);
+ Result_Graph := Parser.Parse (Lexed_Tokens);
Put_Line ("Input:");