mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[poincare/parser] Comment and new test about system parentheses
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user