Kaydet (Commit) 0ba23e36 authored tarafından Takeshi Abe's avatar Takeshi Abe

starmath: Stop using the stack to parse consective identifiers

and numbers.

Change-Id: I7e898cd437ec314a0d07a16e13d3044480d2e057
Reviewed-on: https://gerrit.libreoffice.org/35903Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTakeshi Abe <tabe@fixedpoint.jp>
üst c382c998
......@@ -1328,66 +1328,56 @@ SmNode *SmParser::DoTerm(bool bGroupNumberIdent)
case TIDENT :
case TNUMBER :
{
m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken,
auto pTextNode = o3tl::make_unique<SmTextNode>(m_aCurToken,
m_aCurToken.eType == TNUMBER ?
FNT_NUMBER :
FNT_VARIABLE));
FNT_VARIABLE);
if (!bGroupNumberIdent)
{
NextToken();
return pTextNode.release();
}
else
SmNodeArray aNodes;
// Some people want to be able to write "x_2n" for "x_{2n}"
// although e.g. LaTeX or AsciiMath interpret that as "x_2 n".
// The tokenizer skips whitespaces so we need some additional
// work to distinguish from "x_2 n".
// See https://bz.apache.org/ooo/show_bug.cgi?id=11752 and
// https://bugs.libreoffice.org/show_bug.cgi?id=55853
sal_Int32 nBufLen = m_aBufferString.getLength();
// We need to be careful to call NextToken() only after having
// tested for a whitespace separator (otherwise it will be
// skipped!)
bool moveToNextToken = true;
while (m_nBufferIndex < nBufLen &&
m_pSysCC->getType(m_aBufferString, m_nBufferIndex) !=
UnicodeType::SPACE_SEPARATOR)
{
// Some people want to be able to write "x_2n" for "x_{2n}"
// although e.g. LaTeX or AsciiMath interpret that as "x_2 n".
// The tokenizer skips whitespaces so we need some additional
// work to distinguish from "x_2 n".
// See https://bz.apache.org/ooo/show_bug.cgi?id=11752 and
// https://bugs.libreoffice.org/show_bug.cgi?id=55853
sal_Int32 nBufLen = m_aBufferString.getLength();
sal_Int32 nTokens = 1;
// We need to be careful to call NextToken() only after having
// tested for a whitespace separator (otherwise it will be
// skipped!)
bool moveToNextToken = true;
while (m_nBufferIndex < nBufLen &&
m_pSysCC->getType(m_aBufferString, m_nBufferIndex) !=
UnicodeType::SPACE_SEPARATOR)
{
NextToken();
if (m_aCurToken.eType != TNUMBER &&
m_aCurToken.eType != TIDENT)
{
// Neither a number nor an identifier. We just moved to
// the next token, so no need to do that again.
moveToNextToken = false;
break;
}
m_aNodeStack.push_front(o3tl::make_unique<SmTextNode>(m_aCurToken,
m_aCurToken.eType ==
TNUMBER ?
FNT_NUMBER :
FNT_VARIABLE));
nTokens++;
}
if (moveToNextToken) NextToken();
if (nTokens > 1)
NextToken();
if (m_aCurToken.eType != TNUMBER &&
m_aCurToken.eType != TIDENT)
{
// We have several concatenated identifiers and numbers.
// Let's group them into one SmExpressionNode.
SmNodeArray nodeArray(nTokens);
for (auto rIt = nodeArray.rbegin(), rEnd = nodeArray.rend(); rIt != rEnd; ++rIt)
{
*rIt = popOrZero(m_aNodeStack);
}
std::unique_ptr<SmExpressionNode> pNode(new SmExpressionNode(SmToken()));
pNode->SetSubNodes(nodeArray);
return pNode.release();
// Neither a number nor an identifier. We just moved to
// the next token, so no need to do that again.
moveToNextToken = false;
break;
}
aNodes.push_back(new SmTextNode(m_aCurToken,
m_aCurToken.eType ==
TNUMBER ?
FNT_NUMBER :
FNT_VARIABLE));
}
auto pNode = std::move(m_aNodeStack.front());
m_aNodeStack.pop_front();
if (moveToNextToken)
NextToken();
if (aNodes.empty())
return pTextNode.release();
// We have several concatenated identifiers and numbers.
// Let's group them into one SmExpressionNode.
aNodes.insert(aNodes.begin(), pTextNode.release());
std::unique_ptr<SmExpressionNode> pNode(new SmExpressionNode(SmToken()));
pNode->SetSubNodes(aNodes);
return pNode.release();
}
case TLEFTARROW :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment