summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2017-03-25 16:50:11 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2017-03-30 23:58:49 +0000
commit0ba23e36bb81b65360f3279f5af14a63916189f6 (patch)
tree02c98b3eb9e460d2eab50f0e53679e31368aff13 /starmath
parentc382c998ffdaf80c10a3f078fb4f0a37224d1158 (diff)
starmath: Stop using the stack to parse consective identifiers
and numbers. Change-Id: I7e898cd437ec314a0d07a16e13d3044480d2e057 Reviewed-on: https://gerrit.libreoffice.org/35903 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/source/parse.cxx90
1 files changed, 40 insertions, 50 deletions
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 182e2498a07d..9e423e1a7f17 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -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 :