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