ExpressionEvaluationSystemComponent.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/Component/Component.h>
  10. #include <ExpressionEvaluation/ExpressionEvaluationBus.h>
  11. #include <ExpressionEngine/ExpressionPrimitive.h>
  12. #include <ExpressionEngine/ExpressionVariable.h>
  13. namespace ExpressionEvaluation
  14. {
  15. class ExpressionEvaluationSystemComponent
  16. : public AZ::Component
  17. , public ExpressionEvaluationRequestBus::Handler
  18. {
  19. public:
  20. AZ_COMPONENT(ExpressionEvaluationSystemComponent, "{55C70DBA-9B11-4A23-83C5-CA90260C917A}");
  21. static void Reflect(AZ::ReflectContext* context);
  22. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  23. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  24. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  25. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  26. ~ExpressionEvaluationSystemComponent();
  27. // AZ::Component
  28. void Init() override;
  29. void Activate() override;
  30. void Deactivate() override;
  31. ////
  32. void RegisterExpressionInterface(ExpressionElementParser* elementInterface);
  33. void RemoveExpressionInterface(ExpressionParserId interfaceId);
  34. // ExpressionEvaluationRequestBus
  35. ParseOutcome ParseExpression(AZStd::string_view expressionString) const override;
  36. ParseInPlaceOutcome ParseExpressionInPlace(AZStd::string_view expressionString, ExpressionTree& expressionTree) const override;
  37. ParseOutcome ParseRestrictedExpression(const AZStd::unordered_set<ExpressionParserId>& availableParsers, AZStd::string_view expressionString) const override;
  38. ParseInPlaceOutcome ParseRestrictedExpressionInPlace(const AZStd::unordered_set<ExpressionParserId>& availableParsers, AZStd::string_view expressionString, ExpressionTree& expressionTree) const override;
  39. EvaluateStringOutcome EvaluateExpression(AZStd::string_view expression) const override;
  40. ExpressionResult Evaluate(const ExpressionTree& expressionTree) const override;
  41. ////
  42. private:
  43. AZ::Outcome<void, ParsingError> ReportMissingValue(size_t offset) const;
  44. AZ::Outcome<void, ParsingError> ReportUnexpectedOperator(const AZStd::string& parseString, size_t offset, size_t charactersConsumed) const;
  45. AZ::Outcome<void, ParsingError> ReportUnexpectedValue(const AZStd::string& parseString, size_t offset, size_t charactersConsumed) const;
  46. AZ::Outcome<void, ParsingError> ReportUnexpectedSymbol(const AZStd::string& parseString, size_t offset, size_t charactersConsumed) const;
  47. AZ::Outcome<void, ParsingError> ReportUnknownCharacter(const AZStd::string& parseString, size_t offset) const;
  48. AZ::Outcome<void, ParsingError> ReportUnbalancedParen(size_t offset, const AZStd::string& offsetsString) const;
  49. AZStd::vector<ExpressionElementParser*> m_internalParsers;
  50. AZStd::unordered_map<ExpressionParserId, ExpressionElementParser*> m_elementInterfaces;
  51. };
  52. }