diff options
| author | Jed Barber <jjbarber@y7mail.com> | 2020-12-04 12:55:49 +1100 | 
|---|---|---|
| committer | Jed Barber <jjbarber@y7mail.com> | 2020-12-04 12:55:49 +1100 | 
| commit | ad215be09de49dfb60245285d6ce20a0b58fdeac (patch) | |
| tree | cdd6bdb62212c2017a8b61cfc0b4feda2402783c | |
| parent | 6c918045828db04960a75494c2d1247dab6a1351 (diff) | |
More generic token predicates
| -rw-r--r-- | example/sentence.adb | 41 | ||||
| -rw-r--r-- | src/packrat-tokens.adb | 27 | ||||
| -rw-r--r-- | src/packrat-tokens.ads | 19 | 
3 files changed, 55 insertions, 32 deletions
diff --git a/example/sentence.adb b/example/sentence.adb index 7e9114b..c8493cb 100644 --- a/example/sentence.adb +++ b/example/sentence.adb @@ -3,8 +3,6 @@  with      Ada.Text_IO, -    Ada.Characters.Latin_1, -    Ada.Strings.Maps,      Packrat.Text.Standard,      Packrat.Utilities; @@ -16,16 +14,8 @@ use  procedure Sentence is -    package Latin renames Ada.Characters.Latin_1; - - - -      Input : String := "i saw a man in the park with a bat"; - - -      type Lexer_Labels is (Word, Whitespace);      type Parser_Labels is (S, NP, PP, VP, Det, Noun, Verb, Prep); @@ -47,28 +37,15 @@ procedure Sentence is -    generic -        Match : in String; -    function Is_Value -           (Element : in My_Rat.Lexer_Traits.Tokens.Token) -        return Boolean; - -    function Is_Value -           (Element : in My_Rat.Lexer_Traits.Tokens.Token) -        return Boolean is -    begin -        return My_Rat.Lexer_Traits.Tokens.Value (Element) = Match; -    end Is_Value; - -    function Is_I is new Is_Value ("i"); -    function Is_Saw is new Is_Value ("saw"); -    function Is_A is new Is_Value ("a"); -    function Is_Man is new Is_Value ("man"); -    function Is_In is new Is_Value ("in"); -    function Is_The is new Is_Value ("the"); -    function Is_Park is new Is_Value ("park"); -    function Is_With is new Is_Value ("with"); -    function Is_Bat is new Is_Value ("bat"); +    function Is_I is new My_Rat.Lexer_Traits.Tokens.Is_Value ("i"); +    function Is_Saw is new My_Rat.Lexer_Traits.Tokens.Is_Value ("saw"); +    function Is_A is new My_Rat.Lexer_Traits.Tokens.Is_Value ("a"); +    function Is_Man is new My_Rat.Lexer_Traits.Tokens.Is_Value ("man"); +    function Is_In is new My_Rat.Lexer_Traits.Tokens.Is_Value ("in"); +    function Is_The is new My_Rat.Lexer_Traits.Tokens.Is_Value ("the"); +    function Is_Park is new My_Rat.Lexer_Traits.Tokens.Is_Value ("park"); +    function Is_With is new My_Rat.Lexer_Traits.Tokens.Is_Value ("with"); +    function Is_Bat is new My_Rat.Lexer_Traits.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); diff --git a/src/packrat-tokens.adb b/src/packrat-tokens.adb index c07408c..81d68c3 100644 --- a/src/packrat-tokens.adb +++ b/src/packrat-tokens.adb @@ -111,6 +111,33 @@ package body Packrat.Tokens is      end Value; + + + +    function Is_Label +           (This : in Token) +        return Boolean is +    begin +        return This.Identifier = Ident; +    end Is_Label; + + +    function Is_Start +           (This : in Token) +        return Boolean is +    begin +        return This.Start_At = Start; +    end Is_Start; + + +    function Is_Value +           (This : in Token) +        return Boolean is +    begin +        return This.Token_Value.Element = Value; +    end Is_Value; + +  end Packrat.Tokens; diff --git a/src/packrat-tokens.ads b/src/packrat-tokens.ads index cd691b5..b731b13 100644 --- a/src/packrat-tokens.ads +++ b/src/packrat-tokens.ads @@ -60,6 +60,25 @@ package Packrat.Tokens is          return Element_Array; +    generic +        Ident : in Label_Enum; +    function Is_Label +           (This : in Token) +        return Boolean; + +    generic +        Start : in Positive; +    function Is_Start +           (This : in Token) +        return Boolean; + +    generic +        Value : in Element_Array; +    function Is_Value +           (This : in Token) +        return Boolean; + +  private  | 
