mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Do not parse 1>ans
This commit is contained in:
@@ -93,7 +93,7 @@ bool App::textInputIsCorrect(const char * text) {
|
||||
}
|
||||
Expression ansExpression = static_cast<Snapshot *>(snapshot())->calculationStore()->ansExpression(localContext());
|
||||
{
|
||||
Symbol ansSymbol = Symbol(Symbol::k_ans, 3);
|
||||
Symbol ansSymbol = Symbol::Ans();
|
||||
exp = exp.replaceSymbolWithExpression(ansSymbol, ansExpression);
|
||||
}
|
||||
char buffer[Calculation::k_printedExpressionSize];
|
||||
|
||||
@@ -36,7 +36,7 @@ void Calculation::reset() {
|
||||
void Calculation::setContent(const char * c, Context * context, Expression ansExpression) {
|
||||
reset();
|
||||
{
|
||||
Symbol ansSymbol = Symbol(Symbol::k_ans, 3);
|
||||
Symbol ansSymbol = Symbol::Ans();
|
||||
Expression input = Expression::parse(c).replaceSymbolWithExpression(ansSymbol, 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. */
|
||||
|
||||
@@ -49,7 +49,8 @@ class Symbol final : public SymbolAbstract {
|
||||
friend class Store;
|
||||
friend class SymbolNode;
|
||||
public:
|
||||
static constexpr char k_ans[] = "ans";
|
||||
static constexpr int k_ansLength = 3;
|
||||
static constexpr char k_ans[k_ansLength+1] = "ans";
|
||||
static constexpr char k_unknownXReadableChar = 'x';
|
||||
enum SpecialSymbols : char {
|
||||
/* We can use characters from 1 to 31 as they do not correspond to usual
|
||||
@@ -59,7 +60,7 @@ public:
|
||||
Symbol(const char * name, int length);
|
||||
Symbol(char name);
|
||||
Symbol(const SymbolNode * node) : SymbolAbstract(node) {}
|
||||
|
||||
static Symbol Ans() { return Symbol(k_ans, k_ansLength); }
|
||||
static Expression UntypedBuilder(const char * name, size_t length, Context * context) {
|
||||
// create an expression only if it is not in the context or defined as a symbol
|
||||
Symbol s(name, length);
|
||||
|
||||
@@ -265,13 +265,14 @@ bool Parser::isReservedFunction(const Expression::FunctionHelper * const * & fun
|
||||
bool Parser::isSpecialIdentifier() const {
|
||||
// TODO Avoid special cases if possible
|
||||
return (
|
||||
m_currentToken.compareTo("inf") == 0 ||
|
||||
m_currentToken.compareTo("undef") == 0 ||
|
||||
m_currentToken.compareTo("u_") == 0 ||
|
||||
m_currentToken.compareTo("v_") == 0 ||
|
||||
m_currentToken.compareTo("u") == 0 ||
|
||||
m_currentToken.compareTo("v") == 0 ||
|
||||
m_currentToken.compareTo("log_") == 0
|
||||
m_currentToken.compareTo(Symbol::k_ans) == 0 ||
|
||||
m_currentToken.compareTo("inf") == 0 ||
|
||||
m_currentToken.compareTo("undef") == 0 ||
|
||||
m_currentToken.compareTo("u_") == 0 ||
|
||||
m_currentToken.compareTo("v_") == 0 ||
|
||||
m_currentToken.compareTo("u") == 0 ||
|
||||
m_currentToken.compareTo("v") == 0 ||
|
||||
m_currentToken.compareTo("log_") == 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -326,7 +327,9 @@ void Parser::parseSequence(Expression & leftHandSide, const char name, Token::Ty
|
||||
}
|
||||
|
||||
void Parser::parseSpecialIdentifier(Expression & leftHandSide) {
|
||||
if (m_currentToken.compareTo("inf") == 0) {
|
||||
if (m_currentToken.compareTo(Symbol::k_ans) == 0) {
|
||||
leftHandSide = Symbol::Ans();
|
||||
} else if (m_currentToken.compareTo("inf") == 0) {
|
||||
leftHandSide = Infinity(false);
|
||||
} else if (m_currentToken.compareTo("undef") == 0) {
|
||||
leftHandSide = Undefined();
|
||||
|
||||
@@ -195,7 +195,6 @@ QUIZ_CASE(poincare_parser_parse) {
|
||||
assert_raises_parsing_error("^1");
|
||||
assert_raises_parsing_error("t0000000");
|
||||
assert_raises_parsing_error("[[t0000000[");
|
||||
assert_parsed_expression_is("0=0", Equal(Rational(0), Rational(0)));
|
||||
assert_raises_parsing_error("0>x=0");
|
||||
assert_raises_parsing_error("0=0>x");
|
||||
}
|
||||
@@ -334,7 +333,6 @@ QUIZ_CASE(poincare_parser_symbols_and_functions) {
|
||||
QUIZ_CASE(poincare_parser_parse_store) {
|
||||
assert_parsed_expression_is("1>a", Store(Rational(1),Symbol("a",1)));
|
||||
assert_parsed_expression_is("1>e", Store(Rational(1),Symbol("e",1)));
|
||||
assert_parsed_expression_is("1>ans", Store(Rational(1),Symbol("ans",3)));
|
||||
assert_parsed_expression_is("1>f(x)", Store(Rational(1),Function("f",1,Symbol("x",1))));
|
||||
assert_parsed_expression_is("x>f(x)", Store(Symbol("x",1),Function("f",1,Symbol("x",1))));
|
||||
assert_parsed_expression_is("n>f(x)", Store(Symbol("n",1),Function("f",1,Symbol("x",1))));
|
||||
@@ -360,6 +358,8 @@ QUIZ_CASE(poincare_parser_parse_store) {
|
||||
assert_raises_parsing_error("1>acos");
|
||||
assert_raises_parsing_error("1>f(2)");
|
||||
assert_raises_parsing_error("1>f(f)");
|
||||
assert_raises_parsing_error("1>ans");
|
||||
assert_raises_parsing_error("ans>ans");
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_parser_implicit_multiplication) {
|
||||
|
||||
Reference in New Issue
Block a user