1 module antlr.v4.runtime.atn.LexerTypeAction;
2 
3 import std.format;
4 import antlr.v4.runtime.InterfaceLexer;
5 import antlr.v4.runtime.atn.LexerAction;
6 import antlr.v4.runtime.atn.LexerActionType;
7 import antlr.v4.runtime.misc.MurmurHash;
8 import antlr.v4.runtime.misc.Utils;
9 
10 /**
11  * @uml
12  * Implements the {@code type} lexer action by calling {@link Lexer#setType}
13  * with the assigned type.
14  */
15 class LexerTypeAction : LexerAction
16 {
17 
18     private int type;
19 
20     /**
21      * @uml
22      * Constructs a new {@code type} action with the specified token type value.
23      *  @param type The type to assign to the token using {@link Lexer#setType}.
24      */
25     public this(int type)
26     {
27         this.type = type;
28     }
29 
30     /**
31      * @uml
32      * Gets the type to assign to a token created by the lexer.
33      *  @return The type to assign to a token created by the lexer.
34      */
35     public int getType()
36     {
37         return type;
38     }
39 
40     /**
41      * @uml
42      * {@inheritDoc}
43      *  @return This method returns {@link LexerActionType#TYPE}.
44      * @safe
45      * @nothrow
46      */
47     public LexerActionType getActionType() @safe nothrow
48     {
49         return LexerActionType.TYPE;
50 
51     }
52 
53     /**
54      * @uml
55      * {@inheritDoc}
56      *  @return This method returns {@code false}.
57      */
58     public bool isPositionDependent()
59     {
60         return false;
61     }
62 
63     /**
64      * @uml
65      * {@inheritDoc}
66      *
67      *  <p>This action is implemented by calling {@link Lexer#setType} with the
68      * value provided by {@link #getType}.</p>
69      */
70     public void execute(InterfaceLexer lexer)
71     {
72         lexer.setType(type);
73     }
74 
75     /**
76      * @uml
77      * @safe
78      * @nothrow
79      * @override
80      */
81     public override size_t toHash() @safe nothrow
82     {
83         size_t hash = MurmurHash.initialize();
84         hash = MurmurHash.update(hash, Utils.rank(getActionType));
85         hash = MurmurHash.update(hash, type);
86         return MurmurHash.finish(hash, 2);
87     }
88 
89     public bool equals(Object obj)
90     {
91         if (obj == this) {
92             return true;
93         }
94         else if (obj.classinfo != LexerTypeAction.classinfo) {
95             return false;
96         }
97         return type == (cast(LexerTypeAction)obj).type;
98     }
99 
100     /**
101      * @uml
102      * @override
103      */
104     public override string toString()
105     {
106         return format("type(%d)", type);
107     }
108 
109 }