1 /* 2 * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 3 * Use of this file is governed by the BSD 3-clause license that 4 * can be found in the LICENSE.txt file in the project root. 5 */ 6 7 module antlr.v4.runtime.atn.LexerPushModeAction; 8 9 import std.format; 10 import antlr.v4.runtime.InterfaceLexer; 11 import antlr.v4.runtime.atn.LexerAction; 12 import antlr.v4.runtime.atn.LexerActionType; 13 import antlr.v4.runtime.misc; 14 15 // Class LexerPushModeAction 16 /** 17 * @uml 18 * Implements the {@code pushMode} lexer action by calling 19 * {@link Lexer#pushMode} with the assigned mode. 20 */ 21 class LexerPushModeAction : LexerAction 22 { 23 24 public int mode; 25 26 /** 27 * @uml 28 * Constructs a new {@code pushMode} action with the specified mode value. 29 * @param mode The mode value to pass to {@link Lexer#pushMode}. 30 */ 31 public this(int mode) 32 { 33 this.mode = mode; 34 } 35 36 /** 37 * @uml 38 * Get the lexer mode this action should transition the lexer to. 39 * 40 * @return The lexer mode for this {@code pushMode} command. 41 */ 42 public int getMode() 43 { 44 return mode; 45 } 46 47 /** 48 * @uml 49 * @safe 50 * @nothrow 51 */ 52 public LexerActionType getActionType() @safe nothrow 53 { 54 return LexerActionType.PUSH_MODE; 55 } 56 57 /** 58 * @uml 59 * {@inheritDoc} 60 * @return This method returns {@code false}. 61 */ 62 public bool isPositionDependent() 63 { 64 return false; 65 } 66 67 /** 68 * @uml 69 * {@inheritDoc} 70 * 71 * <p>This action is implemented by calling {@link Lexer#pushMode} with the 72 * value provided by {@link #getMode}.</p> 73 */ 74 public void execute(InterfaceLexer lexer) 75 { 76 lexer.pushMode(mode); 77 } 78 79 /** 80 * @uml 81 * @safe 82 * @nothrow 83 * @override 84 */ 85 public override size_t toHash() @safe nothrow 86 { 87 size_t hash = MurmurHash.initialize(); 88 hash = MurmurHash.update(hash, Utils.rank(getActionType)); 89 return MurmurHash.finish(hash, 1); 90 91 } 92 93 public bool equals(Object obj) 94 { 95 if (obj == this) { 96 return true; 97 } 98 else if (obj.classinfo != LexerPushModeAction.classinfo) { 99 return false; 100 } 101 return mode == (cast(LexerPushModeAction)obj).mode; 102 } 103 104 /** 105 * @uml 106 * @override 107 */ 108 public override string toString() 109 { 110 return format("pushMode(%d)", mode); 111 } 112 113 } 114 115 unittest 116 { 117 auto pushModeAction = new LexerPushModeAction(0); 118 }