[Libreoffice-commits] core.git: starmath/source

Takeshi Abe tabe at fixedpoint.jp
Thu Mar 30 23:59:11 UTC 2017


 starmath/source/parse.cxx |   90 ++++++++++++++++++++--------------------------
 1 file changed, 40 insertions(+), 50 deletions(-)

New commits:
commit 0ba23e36bb81b65360f3279f5af14a63916189f6
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sat Mar 25 16:50:11 2017 +0900

    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 at libreoffice.org>
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>

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 :


More information about the Libreoffice-commits mailing list