diff --git a/apps/calculation/app.cpp b/apps/calculation/app.cpp index bb2dbda3e..b3b5a21c3 100644 --- a/apps/calculation/app.cpp +++ b/apps/calculation/app.cpp @@ -3,6 +3,7 @@ #include "../shared/poincare_helpers.h" #include "calculation_icon.h" #include "../i18n.h" +#include using namespace Poincare; @@ -95,7 +96,7 @@ bool App::textInputIsCorrect(const char * text) { return false; } Expression ansExpression = static_cast(snapshot())->calculationStore()->ansExpression(localContext()); - exp = exp.replaceSymbolWithExpression("ans", ansExpression); + exp = exp.replaceSymbolWithExpression(Symbol::k_ans, ansExpression); char buffer[Calculation::k_printedExpressionSize]; int length = PoincareHelpers::Serialize(exp, buffer, sizeof(buffer)); /* if the buffer is totally full, it is VERY likely that writeTextInBuffer diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index e41e828bf..38c0e2e84 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -1,6 +1,7 @@ #include "calculation.h" #include "calculation_store.h" #include "../shared/poincare_helpers.h" +#include #include #include #include @@ -34,7 +35,7 @@ void Calculation::reset() { void Calculation::setContent(const char * c, Context * context, Expression ansExpression) { reset(); - Expression input = Expression::parse(c).replaceSymbolWithExpression("ans", ansExpression); + Expression input = Expression::parse(c).replaceSymbolWithExpression(Symbol::k_ans, ansExpression); /* We do not store directly the text enter by the user because we do not want * to keep Ans symbol in the calculation store. */ PoincareHelpers::Serialize(input, m_inputText, sizeof(m_inputText)); diff --git a/apps/calculation/expression_field.cpp b/apps/calculation/expression_field.cpp index 692756a18..a190a9558 100644 --- a/apps/calculation/expression_field.cpp +++ b/apps/calculation/expression_field.cpp @@ -1,4 +1,5 @@ #include "expression_field.h" +#include namespace Calculation { @@ -7,7 +8,7 @@ bool ExpressionField::handleEvent(Ion::Events::Event event) { return false; } if (event == Ion::Events::Ans) { - handleEventWithText("ans"); + handleEventWithText(Poincare::Symbol::k_ans); return true; } if (isEditing() && isEmpty() && @@ -17,7 +18,7 @@ bool ExpressionField::handleEvent(Ion::Events::Event event) { event == Ion::Events::Square || event == Ion::Events::Division || event == Ion::Events::Sto)) { - handleEventWithText("ans"); + handleEventWithText(Poincare::Symbol::k_ans); } return(::ExpressionField::handleEvent(event)); } diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 35f1a83fd..222ea46fb 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -65,6 +65,7 @@ class Symbol final : public Expression { friend class Expression; friend class Store; public: + static constexpr char k_ans[] = "ans"; enum SpecialSymbols : char { /* We can use characters from 1 to 31 as they do not correspond to usual * characters but events as 'end of text', 'backspace'... */ diff --git a/poincare/src/expression_parser.y b/poincare/src/expression_parser.y index 2d56703be..03be99195 100644 --- a/poincare/src/expression_parser.y +++ b/poincare/src/expression_parser.y @@ -154,7 +154,7 @@ exp : pow { $$ = $1; } ; final_exp : exp { $$ = $1; } - | exp STO symb { if (static_cast($3).name() == Symbol::SpecialSymbols::Ans) { YYERROR; } ; $$ = Store($1, static_cast($3)); } + | exp STO symb { if (static_cast($3).name() == Symbol::k_ans) { YYERROR; } ; $$ = Store($1, static_cast($3)); } | exp EQUAL exp { $$ = Equal($1, $3); } ; %%