3
0

ExpressionVariable.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <AzCore/std/string/regex.h>
  9. #include <ExpressionEngine/ExpressionVariable.h>
  10. #include <ExpressionEngine/InternalTypes.h>
  11. namespace ExpressionEvaluation
  12. {
  13. ///////////////////
  14. // VariableParser
  15. ///////////////////
  16. ElementInformation VariableParser::GetVariableInformation(const AZStd::string& displayName)
  17. {
  18. ElementInformation elementInformation;
  19. elementInformation.m_allowOnOperatorStack = false;
  20. elementInformation.m_id = InternalTypes::Variable;
  21. elementInformation.m_extraStore = VariableDescriptor(displayName);
  22. return elementInformation;
  23. }
  24. VariableParser::VariableParser()
  25. : m_regex(R"(^\{[^\}]*\})")
  26. {
  27. }
  28. VariableParser::ParseResult VariableParser::ParseElement(const AZStd::string& inputText, size_t offset) const
  29. {
  30. AZStd::smatch match;
  31. ParseResult result;
  32. if (AZStd::regex_search(&inputText.at(offset), match, m_regex))
  33. {
  34. AZStd::string matchedCharacters = match[0].str();
  35. result.m_charactersConsumed = matchedCharacters.length();
  36. AZStd::string variableName = matchedCharacters.substr(1, matchedCharacters.length() - 2);
  37. result.m_element = GetVariableInformation(variableName);
  38. }
  39. return result;
  40. }
  41. void VariableParser::EvaluateToken(const ElementInformation& parseResult, ExpressionResultStack& evaluationStack) const
  42. {
  43. AZ_UNUSED(parseResult);
  44. AZ_UNUSED(evaluationStack);
  45. AZ_Error("ExpressionParser", false, "VariableInterface should never be used to evaluate Variable information.");
  46. }
  47. }