LexerPushModeAction.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
  2. * Use of this file is governed by the BSD 3-clause license that
  3. * can be found in the LICENSE.txt file in the project root.
  4. */
  5. #pragma once
  6. #include "atn/LexerAction.h"
  7. #include "atn/LexerActionType.h"
  8. namespace antlr4 {
  9. namespace atn {
  10. /// <summary>
  11. /// Implements the {@code pushMode} lexer action by calling
  12. /// <seealso cref="Lexer#pushMode"/> with the assigned mode.
  13. ///
  14. /// @author Sam Harwell
  15. /// @since 4.2
  16. /// </summary>
  17. class ANTLR4CPP_PUBLIC LexerPushModeAction final : public LexerAction {
  18. public:
  19. static bool is(const LexerAction &lexerAction) { return lexerAction.getActionType() == LexerActionType::PUSH_MODE; }
  20. static bool is(const LexerAction *lexerAction) { return lexerAction != nullptr && is(*lexerAction); }
  21. /// <summary>
  22. /// Constructs a new {@code pushMode} action with the specified mode value. </summary>
  23. /// <param name="mode"> The mode value to pass to <seealso cref="Lexer#pushMode"/>. </param>
  24. explicit LexerPushModeAction(int mode);
  25. /// <summary>
  26. /// Get the lexer mode this action should transition the lexer to.
  27. /// </summary>
  28. /// <returns> The lexer mode for this {@code pushMode} command. </returns>
  29. int getMode() const { return _mode; }
  30. /// <summary>
  31. /// {@inheritDoc}
  32. ///
  33. /// <para>This action is implemented by calling <seealso cref="Lexer#pushMode"/> with the
  34. /// value provided by <seealso cref="#getMode"/>.</para>
  35. /// </summary>
  36. void execute(Lexer *lexer) const override;
  37. bool equals(const LexerAction &obj) const override;
  38. std::string toString() const override;
  39. protected:
  40. size_t hashCodeImpl() const override;
  41. private:
  42. const int _mode;
  43. };
  44. } // namespace atn
  45. } // namespace antlr4