From 0c51270e19216df4a41826a1186ba62f1adb13c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 25 Jan 2017 18:07:20 +0100 Subject: [PATCH] [apps][poincare] Use special symbols when required Change-Id: I376f15eb9e08fd26d34fffb6aa86d2097af4c2c4 --- .../calculation/finite_integral_calculation.cpp | 4 +++- .../calculation/left_integral_calculation.cpp | 4 +++- .../calculation/right_integral_calculation.cpp | 4 +++- apps/probability/law/exponential_law.cpp | 4 +++- apps/probability/law/normal_law.cpp | 7 +++++-- apps/regression/graph_controller.cpp | 6 ++++-- ion/src/shared/events.cpp | 8 ++++++-- poincare/include/poincare/symbol.h | 3 +-- poincare/src/expression_lexer.l | 9 +++++++-- poincare/src/global_context.cpp | 3 ++- poincare/src/symbol.cpp | 3 --- 11 files changed, 37 insertions(+), 18 deletions(-) diff --git a/apps/probability/calculation/finite_integral_calculation.cpp b/apps/probability/calculation/finite_integral_calculation.cpp index e935cf640..33ab9e920 100644 --- a/apps/probability/calculation/finite_integral_calculation.cpp +++ b/apps/probability/calculation/finite_integral_calculation.cpp @@ -1,5 +1,6 @@ #include "finite_integral_calculation.h" #include +#include #include namespace Probability { @@ -23,7 +24,8 @@ const char * FiniteIntegralCalculation::legendForParameterAtIndex(int index) { return "P("; } if (index == 1) { - return "<=X<="; + constexpr static char comparison[] = {Ion::Charset::LessEqual, 'X', Ion::Charset::LessEqual, 0}; + return comparison; } return ")="; } diff --git a/apps/probability/calculation/left_integral_calculation.cpp b/apps/probability/calculation/left_integral_calculation.cpp index 2f1217ebc..0b2591139 100644 --- a/apps/probability/calculation/left_integral_calculation.cpp +++ b/apps/probability/calculation/left_integral_calculation.cpp @@ -1,5 +1,6 @@ #include "left_integral_calculation.h" #include +#include #include namespace Probability { @@ -19,7 +20,8 @@ int LeftIntegralCalculation::numberOfParameters() { const char * LeftIntegralCalculation::legendForParameterAtIndex(int index) { assert(index >= 0 && index < 2); if (index == 0) { - return "P(X<="; + constexpr static char comparison[] = {'P', '(', 'X', Ion::Charset::LessEqual, 0}; + return comparison; } return ")="; } diff --git a/apps/probability/calculation/right_integral_calculation.cpp b/apps/probability/calculation/right_integral_calculation.cpp index 6e30bd883..b14922fc7 100644 --- a/apps/probability/calculation/right_integral_calculation.cpp +++ b/apps/probability/calculation/right_integral_calculation.cpp @@ -1,5 +1,6 @@ #include "right_integral_calculation.h" #include +#include #include namespace Probability { @@ -21,7 +22,8 @@ const char * RightIntegralCalculation::legendForParameterAtIndex(int index) { if (index == 0) { return "P("; } - return "<=X)="; + constexpr static char comparison[] = {Ion::Charset::LessEqual, 'X', ')', '=', 0}; + return comparison; } void RightIntegralCalculation::setParameterAtIndex(float f, int index) { diff --git a/apps/probability/law/exponential_law.cpp b/apps/probability/law/exponential_law.cpp index 1b79a8e0e..75d278bbd 100644 --- a/apps/probability/law/exponential_law.cpp +++ b/apps/probability/law/exponential_law.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace Probability { @@ -29,7 +30,8 @@ const char * ExponentialLaw::parameterNameAtIndex(int index) { const char * ExponentialLaw::parameterDefinitionAtIndex(int index) { assert(index == 0); - return "l : parametre"; + constexpr static char def[] = {Ion::Charset::SmallLambda, ' ', ':', ' ', 'p', 'a', 'r', 'a', 'm', 'e', 't', 'r', 'e', 0}; + return def; } float ExponentialLaw::xMin() { diff --git a/apps/probability/law/normal_law.cpp b/apps/probability/law/normal_law.cpp index 4597ce710..3f8b4af3d 100644 --- a/apps/probability/law/normal_law.cpp +++ b/apps/probability/law/normal_law.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace Probability { @@ -34,9 +35,11 @@ const char * NormalLaw::parameterNameAtIndex(int index) { const char * NormalLaw::parameterDefinitionAtIndex(int index) { assert(index >= 0 && index < 2); if (index == 0) { - return "u : moyenne"; + constexpr static char meanDef[] = {Ion::Charset::SmallMu, ' ', ':', ' ', 'm', 'o', 'y', 'e', 'n', 'n', 'e', 0}; + return meanDef; } else { - return "o : ecart-type"; + constexpr static char devDef[] = {Ion::Charset::SmallSigma, ' ', ':', ' ', 'e', 'c', 'a', 'r', 't', '-', 't', 'y', 'p', 'e', 0}; + return devDef; } } diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index 82dc9c11f..bd033a5f7 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -73,7 +73,8 @@ void GraphController::reloadBannerView() { float x = m_cursor.x(); // Display a specific legend if the mean dot is selected if (m_selectedDotIndex == m_store->numberOfPairs()) { - legend = "x^ = "; + constexpr static char legX[] = {Ion::Charset::XBar, ' ', '=', ' ', 0}; + legend = legX; x = m_store->meanOfColumn(0); } legendLength = strlen(legend); @@ -84,7 +85,8 @@ void GraphController::reloadBannerView() { legend = "y = "; float y = m_cursor.y(); if (m_selectedDotIndex == m_store->numberOfPairs()) { - legend = "y^ = "; + constexpr static char legY[] = {Ion::Charset::YBar, ' ', '=', ' ', 0}; + legend = legY; y = m_store->meanOfColumn(1); } legendLength = strlen(legend); diff --git a/ion/src/shared/events.cpp b/ion/src/shared/events.cpp index 0ce13fbdd..2077d1b52 100644 --- a/ion/src/shared/events.cpp +++ b/ion/src/shared/events.cpp @@ -24,13 +24,17 @@ private: #define U() EventData::Undefined() #define T(x) EventData::Text(x) +static constexpr const char k_pi[2] = {Ion::Charset::SmallPi, 0}; +static constexpr const char k_root[4] = {Ion::Charset::Root, '(', ')', 0}; +static constexpr const char k_complexI[2] = {Ion::Charset::SmallIota, 0}; + static constexpr EventData s_dataForEvent[] = { // Plain TL(), TL(), TL(), TL(), TL(), TL(), TL(), TL(), U(), U(), U(), U(), TL(), TL(), TL(), TL(), TL(), TL(), - T("exp()"), T("ln()"), T("log()"), T("i"), T(","), T("^"), - T("sin()"), T("cos()"), T("tan()"), T("Pi"), T("v()"), T("^2"), + T("exp()"), T("ln()"), T("log()"), T(k_complexI), T(","), T("^"), + T("sin()"), T("cos()"), T("tan()"), T(k_pi), T(k_root), T("^2"), T("7"), T("8"), T("9"), T("("), T(")"), U(), T("4"), T("5"), T("6"), T("*"), T("/"), U(), T("1"), T("2"), T("3"), T("+"), T("-"), U(), diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 694397b09..6b80bfdd3 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -6,8 +6,7 @@ class Symbol : public LeafExpression { public: enum SpecialSymbols : char { - Ans = '^', - Pi = '*' + Ans = '^' }; Symbol(char name); ExpressionLayout * createLayout() const override; diff --git a/poincare/src/expression_lexer.l b/poincare/src/expression_lexer.l index 90b1a9838..4ce002f57 100644 --- a/poincare/src/expression_lexer.l +++ b/poincare/src/expression_lexer.l @@ -75,6 +75,11 @@ * by flex temporarily swapping the last character. Afterwards the pointer is * still valid but the string isn't null-terminated anymore. */ + /* We designed our own extended-ASCII to include requiered symbols in less + * than 255 glyphs. The file ion/include/ion/charset.h lists all added + * non-ASCII symbols with their char associated. For example, the char \xa0 + * refered to Pi symbols. This artefact leads to the following lexer rules + * starting with \x. */ [0-9]+ { poincare_expression_yylval.string.address = yytext; poincare_expression_yylval.string.length = yyleng; return DIGITS; } E { return EE; } @@ -92,8 +97,8 @@ ln { poincare_expression_yylval.expression = new NaperianLogarithm(); return FUN root { poincare_expression_yylval.expression = new NthRoot(); return FUNCTION; } sum { poincare_expression_yylval.expression = new Sum(); return FUNCTION; } product { poincare_expression_yylval.expression = new Product(); return FUNCTION; } -Pi { poincare_expression_yylval.character = Symbol::SpecialSymbols::Pi; return SYMBOL; } -v { poincare_expression_yylval.expression = new SquareRoot(); return FUNCTION; } +\xa0 { poincare_expression_yylval.character = yytext[0]; return SYMBOL; } +\xa5 { poincare_expression_yylval.expression = new SquareRoot(); return FUNCTION; } \+ { return PLUS; } \- { return MINUS; } \* { return MULTIPLY; } diff --git a/poincare/src/global_context.cpp b/poincare/src/global_context.cpp index baee54faf..0b11660ee 100644 --- a/poincare/src/global_context.cpp +++ b/poincare/src/global_context.cpp @@ -1,6 +1,7 @@ #include #include #include +#include GlobalContext::GlobalContext() : m_pi(Float(M_PI)) @@ -21,7 +22,7 @@ int GlobalContext::symbolIndex(const Symbol * symbol) const { } const Expression * GlobalContext::expressionForSymbol(const Symbol * symbol) { - if (symbol->name() == Symbol::SpecialSymbols::Pi) { + if (symbol->name() == Ion::Charset::SmallPi) { return &m_pi; } int index = symbolIndex(symbol); diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 720040800..33aefd4c1 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -35,9 +35,6 @@ ExpressionLayout * Symbol::createLayout() const { if (m_name == SpecialSymbols::Ans) { return new StringLayout("ans", 4); } - if (m_name == SpecialSymbols::Pi) { - return new StringLayout("Pi", 4); - } return new StringLayout(&m_name, 1); }