File: relop_example_token.adb

package info (click to toggle)
opentoken 4.0b-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,812 kB
  • ctags: 57
  • sloc: ada: 12,643; makefile: 129; java: 37; sh: 6
file content (83 lines) | stat: -rw-r--r-- 2,930 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package body Relop_Example_Token is

   ---------------------------------------------------------------------------
   --  This procedure will be called when analysis on a new candidate string
   --  is started. The Token needs to clear its state (if any).
   ---------------------------------------------------------------------------
   overriding procedure Clear (The_Token : in out Instance) is
   begin
      The_Token.State := First_Char;
   end Clear;

   ---------------------------------------------------------------------------
   --  This procedure will be called to create a Relop token recognizer
   ---------------------------------------------------------------------------
   function Get return Instance is
   begin
      return (Report => True,
              State  => First_Char);
   end Get;

   --------------------------------------------------------------------------
   --  This procedure will be called to perform further analysis on a token
   --  based on the given next character.
   ---------------------------------------------------------------------------
   overriding procedure Analyze
     (The_Token : in out Instance;
      Next_Char : in     Character;
      Verdict   :    out OpenToken.Recognizer.Analysis_Verdict)
   is begin

      case The_Token.State is

         when First_Char =>
            --  If the first char is a <, =, or >, its a match
            case Next_Char is
               when '<' =>
                  Verdict         := OpenToken.Recognizer.Matches;
                  The_Token.State := Equal_or_Greater;

               when '>' =>
                  Verdict         := OpenToken.Recognizer.Matches;
                  The_Token.State := Equal;


               when '=' =>
                  Verdict         := OpenToken.Recognizer.Matches;
                  The_Token.State := Done;

               when others =>
                  Verdict         := OpenToken.Recognizer.Failed;
                  The_Token.State := Done;
            end case;

         when Equal_or_Greater =>

            --  If the next char is a > or =, its a match
            case Next_Char is
               when '>' | '=' =>
                  Verdict         := OpenToken.Recognizer.Matches;
                  The_Token.State := Done;

               when others =>
                  Verdict         := OpenToken.Recognizer.Failed;
                  The_Token.State := Done;
            end case;

         when Equal =>

            --  If the next char is a =, its a match
            if Next_Char = '=' then
               Verdict         := OpenToken.Recognizer.Matches;
               The_Token.State := Done;
            else
               Verdict         := OpenToken.Recognizer.Failed;
               The_Token.State := Done;
            end if;

         when Done =>
            Verdict := OpenToken.Recognizer.Failed;
      end case;
   end Analyze;

end Relop_Example_Token;