3
0

ExpressionPrimitive.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/string/regex.h>
  10. #include <AzCore/RTTI/RTTI.h>
  11. #include <ExpressionEvaluation/ExpressionEngine/ExpressionTree.h>
  12. #include <ExpressionEngine/ExpressionElementParser.h>
  13. #include <ExpressionEngine/InternalTypes.h>
  14. namespace ExpressionEvaluation
  15. {
  16. // Shared interface for pushing Primitives onto the evaluation stack. Does not handle parsing.
  17. class PrimitiveParser
  18. : public ExpressionElementParser
  19. {
  20. public:
  21. AZ_CLASS_ALLOCATOR(PrimitiveParser, AZ::SystemAllocator);
  22. PrimitiveParser() = default;
  23. void EvaluateToken(const ElementInformation& parseResult, ExpressionResultStack& evaluationStack) const override;
  24. };
  25. namespace Primitive
  26. {
  27. template<typename T>
  28. ElementInformation GetPrimitiveElement(const T& valueType)
  29. {
  30. ElementInformation primitiveInformation;
  31. primitiveInformation.m_allowOnOperatorStack = false;
  32. primitiveInformation.m_id = InternalTypes::Primitive;
  33. primitiveInformation.m_extraStore = valueType;
  34. return primitiveInformation;
  35. }
  36. }
  37. // Parser for basic numeric types
  38. class NumericPrimitiveParser
  39. : public PrimitiveParser
  40. {
  41. public:
  42. AZ_CLASS_ALLOCATOR(NumericPrimitiveParser, AZ::SystemAllocator);
  43. NumericPrimitiveParser();
  44. ExpressionParserId GetParserId() const override;
  45. ParseResult ParseElement(const AZStd::string& inputText, size_t offset) const override;
  46. private:
  47. AZStd::regex m_regex;
  48. };
  49. // Parser for basic boolean types
  50. class BooleanPrimitiveParser
  51. : public PrimitiveParser
  52. {
  53. public:
  54. AZ_CLASS_ALLOCATOR(BooleanPrimitiveParser, AZ::SystemAllocator);
  55. BooleanPrimitiveParser();
  56. ExpressionParserId GetParserId() const override;
  57. ParseResult ParseElement(const AZStd::string& inputText, size_t offset) const override;
  58. private:
  59. AZStd::regex m_regex;
  60. };
  61. }