ExpressionElementParser.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/any.h>
  10. #include <AzCore/RTTI/RTTI.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <ExpressionEvaluation/ExpressionEngine/ExpressionTypes.h>
  13. #include <ExpressionEngine/InternalTypes.h>
  14. namespace ExpressionEvaluation
  15. {
  16. // Interface for expanding the available grammar for parsing.
  17. //
  18. // Must handle both parsing and execution.
  19. class ExpressionElementParser
  20. {
  21. public:
  22. AZ_CLASS_ALLOCATOR(ExpressionElementParser, AZ::SystemAllocator);
  23. struct ParseResult
  24. {
  25. // Returns the number of characters that the parser wants to consume from the input text.
  26. size_t m_charactersConsumed = 0;
  27. ElementInformation m_element;
  28. };
  29. protected:
  30. ExpressionElementParser() = default;
  31. public:
  32. virtual ~ExpressionElementParser() = default;
  33. virtual ExpressionParserId GetParserId() const = 0;
  34. // Attempt to parse the specified element in the text at the specified offset.
  35. virtual ParseResult ParseElement(const AZStd::string& inputText, size_t offset) const = 0;
  36. // Evaluate the given token using the current evaluation stack.
  37. virtual void EvaluateToken(const ElementInformation& parseResult, ExpressionResultStack& evaluationStack) const = 0;
  38. };
  39. }