diff --git a/poincare/src/parsing/parser.cpp b/poincare/src/parsing/parser.cpp index 7a32b7cd0..48beae151 100644 --- a/poincare/src/parsing/parser.cpp +++ b/poincare/src/parsing/parser.cpp @@ -417,6 +417,9 @@ void Parser::parseCustomIdentifier(Expression & leftHandSide, const char * name, return; } bool poppedParenthesisIsSystem = false; + /* If the identifier is followed by parentheses it is a function, else it is a + * symbol. The parentheses can be system parentheses, if serialized using + * SerializationHelper::Prefix. */ if (!popTokenIfType(Token::LeftParenthesis)) { if (!popTokenIfType(Token::LeftSystemParenthesis)) { leftHandSide = Symbol::Builder(name, length); @@ -467,6 +470,8 @@ void Parser::parseIdentifier(Expression & leftHandSide, Token::Type stoppingType Expression Parser::parseFunctionParameters() { bool poppedParenthesisIsSystem = false; + /* The function parentheses can be system parentheses, if serialized using + * SerializationHelper::Prefix.*/ if (!popTokenIfType(Token::LeftParenthesis)) { if (!popTokenIfType(Token::LeftSystemParenthesis)) { m_status = Status::Error; // Left parenthesis missing. diff --git a/poincare/src/serialization_helper.cpp b/poincare/src/serialization_helper.cpp index 34f25f169..ffe45b6f0 100644 --- a/poincare/src/serialization_helper.cpp +++ b/poincare/src/serialization_helper.cpp @@ -80,6 +80,9 @@ int InfixPrefix( int numberOfChar = 0; + /* For Prefix, we use system parentheses so that, for instance, |3)+(1| is not + * parsable after serialization.*/ + if (prefix) { // Prefix: Copy the operator name numberOfChar = strlcpy(buffer, operatorName, bufferSize); diff --git a/poincare/test/layouts.cpp b/poincare/test/layouts.cpp index c68a27420..5509a0fdd 100644 --- a/poincare/test/layouts.cpp +++ b/poincare/test/layouts.cpp @@ -423,4 +423,18 @@ QUIZ_CASE(poincare_unparsable_layouts) { HorizontalLayout::Builder(children, childrenCount)); assert_layout_is_not_parsed(l); } + + { + // |3)+(1| + constexpr int childrenCount = 5; + Layout children[childrenCount] = { + CodePointLayout::Builder('3'), + RightParenthesisLayout::Builder(), + CodePointLayout::Builder('+'), + LeftParenthesisLayout::Builder(), + CodePointLayout::Builder('1')}; + + Layout l = AbsoluteValueLayout::Builder(HorizontalLayout::Builder(children, childrenCount)); + assert_layout_is_not_parsed(l); + } }