[poincare/parser] Comment and new test about system parentheses

This commit is contained in:
Léa Saviot
2019-06-26 10:41:16 +02:00
committed by LeaNumworks
parent 596a438557
commit 0298291043
3 changed files with 22 additions and 0 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -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);
}
}