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

dante (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 2 06:18:16 UTC 2021


 starmath/inc/document.hxx               |    7 ++----
 starmath/qa/cppunit/test_starmath.cxx   |   34 ++++++++++++++++----------------
 starmath/source/document.cxx            |   11 ++++++++--
 starmath/source/mathml/mathmlexport.cxx |   12 +++++------
 starmath/source/mathml/mathmlimport.cxx |   12 +++++------
 starmath/source/view.cxx                |    6 ++---
 6 files changed, 44 insertions(+), 38 deletions(-)

New commits:
commit c1659be6ff0e0c91e0c7d1e6acb6ab18821e2bf7
Author:     dante <dante19031999 at gmail.com>
AuthorDate: Sat Feb 27 18:49:19 2021 +0100
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Mar 2 07:17:32 2021 +0100

    Starmath now allows multiple parsers third part
    
    Allows SmDocShell to choose parser
    
    Change-Id: I36e7563943690ffe3bf031438061b302b7439258
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111684
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index 17f0713a63ce..c7885c027019 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -77,7 +77,6 @@ class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener
 
     OUString            maText;
     SmFormat            maFormat;
-    SmParser            maParser;
     OUString            maAccText;
     SvtLinguOptions     maLinguOptions;
     std::unique_ptr<SmTableNode> mpTree;
@@ -88,6 +87,7 @@ class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener
     sal_uInt16          mnModifyCount;
     bool                mbFormulaArranged;
     sal_uInt16          mnSmSyntaxVersion;
+    std::unique_ptr<AbstractSmParser> maParser;
     std::unique_ptr<SmCursor> mpCursor;
     std::set< OUString >    maUsedSymbols;   // to export used symbols only when saving
 
@@ -166,12 +166,11 @@ public:
     const SmFormat&  GetFormat() const { return maFormat; }
 
     void            Parse();
-    SmParser &      GetParser() { return maParser; }
+    AbstractSmParser* GetParser() { return maParser.get(); }
     const SmTableNode *GetFormulaTree() const  { return mpTree.get(); }
     void            SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); }
     sal_uInt16      GetSmSyntaxVersion() const { return mnSmSyntaxVersion; }
-    void            SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion)
-    { mnSmSyntaxVersion = nSmSyntaxVersion; }
+    void            SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion);
 
     const std::set< OUString > &    GetUsedSymbols() const  { return maUsedSymbols; }
 
diff --git a/starmath/qa/cppunit/test_starmath.cxx b/starmath/qa/cppunit/test_starmath.cxx
index 480796aaddd4..37bc23489a55 100644
--- a/starmath/qa/cppunit/test_starmath.cxx
+++ b/starmath/qa/cppunit/test_starmath.cxx
@@ -234,28 +234,28 @@ void Test::editFailure()
 {
     m_xDocShRef->SetText("color a b over {a/}");
 
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
 
     CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::ColorExpected",
         pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a SmParseError::ColorExpected",
         SmParseError::ColorExpected, pErrorDesc->m_eType);
 
-    pErrorDesc = m_xDocShRef->GetParser().PrevError();
+    pErrorDesc = m_xDocShRef->GetParser()->PrevError();
 
     CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::UnexpectedChar",
         pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a SmParseError::UnexpectedChar",
         SmParseError::UnexpectedChar, pErrorDesc->m_eType);
 
-    pErrorDesc = m_xDocShRef->GetParser().PrevError();
+    pErrorDesc = m_xDocShRef->GetParser()->PrevError();
 
     CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::RgroupExpected",
         pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a SmParseError::RgroupExpected",
         SmParseError::RgroupExpected, pErrorDesc->m_eType);
 
-    const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser().PrevError();
+    const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser()->PrevError();
 
     CPPUNIT_ASSERT_MESSAGE("Should be three syntax errors",
         pLastErrorDesc);
@@ -266,7 +266,7 @@ void Test::editFailure()
 void Test::ParseErrorUnexpectedToken()
 {
     m_xDocShRef->SetText("\\foo");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::UnexpectedToken expected",
                            SmParseError::UnexpectedToken, pErrorDesc->m_eType);
@@ -275,7 +275,7 @@ void Test::ParseErrorUnexpectedToken()
 void Test::ParseErrorPoundExpected()
 {
     m_xDocShRef->SetText("matrix {1#2##a##b#c}");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::PoundExpected expected",
                            SmParseError::PoundExpected, pErrorDesc->m_eType);
@@ -284,7 +284,7 @@ void Test::ParseErrorPoundExpected()
 void Test::ParseErrorColorExpected()
 {
     m_xDocShRef->SetText("color 42 x");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::ColorExpected expected",
                            SmParseError::ColorExpected, pErrorDesc->m_eType);
@@ -293,7 +293,7 @@ void Test::ParseErrorColorExpected()
 void Test::ParseErrorLgroupExpected()
 {
     m_xDocShRef->SetText("stack 42");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::LgroupExpected expected",
                            SmParseError::LgroupExpected, pErrorDesc->m_eType);
@@ -302,7 +302,7 @@ void Test::ParseErrorLgroupExpected()
 void Test::ParseErrorRgroupExpected()
 {
     m_xDocShRef->SetText("stack {a#b#c)");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::RgroupExpected expected",
                            SmParseError::RgroupExpected, pErrorDesc->m_eType);
@@ -311,7 +311,7 @@ void Test::ParseErrorRgroupExpected()
 void Test::ParseErrorLbraceExpected()
 {
     m_xDocShRef->SetText("left 42");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::LbraceExpected expected",
                            SmParseError::LbraceExpected, pErrorDesc->m_eType);
@@ -320,7 +320,7 @@ void Test::ParseErrorLbraceExpected()
 void Test::ParseErrorRbraceExpected()
 {
     m_xDocShRef->SetText("left ( foo right x");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::RbraceExpected expected",
                            SmParseError::RbraceExpected, pErrorDesc->m_eType);
@@ -329,7 +329,7 @@ void Test::ParseErrorRbraceExpected()
 void Test::ParseErrorParentMismatch()
 {
     m_xDocShRef->SetText("lbrace foo rceil");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::ParentMismatch expected",
                            SmParseError::ParentMismatch, pErrorDesc->m_eType);
@@ -338,7 +338,7 @@ void Test::ParseErrorParentMismatch()
 void Test::ParseErrorRightExpected()
 {
     m_xDocShRef->SetText("left ( x mline y )");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::RightExpected expected",
                            SmParseError::RightExpected, pErrorDesc->m_eType);
@@ -347,7 +347,7 @@ void Test::ParseErrorRightExpected()
 void Test::ParseErrorFontExpected()
 {
     m_xDocShRef->SetText("font small bar");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::FontExpected expected",
                            SmParseError::FontExpected, pErrorDesc->m_eType);
@@ -356,7 +356,7 @@ void Test::ParseErrorFontExpected()
 void Test::ParseErrorSizeExpected()
 {
     m_xDocShRef->SetText("size small baz");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::SizeExpected expected",
                            SmParseError::SizeExpected, pErrorDesc->m_eType);
@@ -365,7 +365,7 @@ void Test::ParseErrorSizeExpected()
 void Test::ParseErrorDoubleAlign()
 {
     m_xDocShRef->SetText("alignl alignc x");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::DoubleAlign expected",
                            SmParseError::DoubleAlign, pErrorDesc->m_eType);
@@ -374,7 +374,7 @@ void Test::ParseErrorDoubleAlign()
 void Test::ParseErrorDoubleSubsupscript()
 {
     m_xDocShRef->SetText("x_y_z");
-    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
+    const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser()->NextError();
     CPPUNIT_ASSERT(pErrorDesc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("SmParseError::DoubleSubsupscript expected",
                            SmParseError::DoubleSubsupscript, pErrorDesc->m_eType);
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 59dcb21e2128..6c0e5663a5a0 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -99,6 +99,12 @@ void SmDocShell::InitInterface_Impl()
     GetStaticInterface()->RegisterPopupMenu("view");
 }
 
+void SmDocShell::SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion)
+{
+    mnSmSyntaxVersion = nSmSyntaxVersion;
+    maParser.reset(starmathdatabase::GetVersionSmParser(mnSmSyntaxVersion));
+}
+
 SFX_IMPL_OBJECTFACTORY(SmDocShell, SvGlobalName(SO3_SM_CLASSID), "smath" )
 
 void SmDocShell::Notify(SfxBroadcaster&, const SfxHint& rHint)
@@ -219,11 +225,11 @@ void SmDocShell::Parse()
 {
     mpTree.reset();
     ReplaceBadChars();
-    mpTree = maParser.Parse(maText);
+    mpTree = maParser->Parse(maText);
     mnModifyCount++;     //! see comment for SID_GAPHIC_SM in SmDocShell::GetState
     SetFormulaArranged( false );
     InvalidateCursor();
-    maUsedSymbols = maParser.GetUsedSymbols();
+    maUsedSymbols = maParser->GetUsedSymbols();
 }
 
 
@@ -627,6 +633,7 @@ SmDocShell::SmDocShell( SfxModelFlags i_nSfxCreationFlags )
 
     SmModule *pp = SM_MOD();
     maFormat = pp->GetConfig()->GetStandardFormat();
+    maParser.reset(starmathdatabase::GetVersionSmParser(mnSmSyntaxVersion));
 
     StartListening(maFormat);
     StartListening(*pp->GetConfig());
diff --git a/starmath/source/mathml/mathmlexport.cxx b/starmath/source/mathml/mathmlexport.cxx
index 8414bc7f8dca..f1952b5057cc 100644
--- a/starmath/source/mathml/mathmlexport.cxx
+++ b/starmath/source/mathml/mathmlexport.cxx
@@ -469,13 +469,13 @@ void SmXMLExport::ExportContent_()
     if (pDocShell)
     {
         nSmSyntaxVersion = pDocShell->GetSmSyntaxVersion();
-        SmParser& rParser = pDocShell->GetParser();
-        bool bVal = rParser.IsExportSymbolNames();
-        rParser.SetExportSymbolNames(true);
-        auto pTmpTree = rParser.Parse(aText);
-        aText = rParser.GetText();
+        AbstractSmParser* rParser = pDocShell->GetParser();
+        bool bVal = rParser->IsExportSymbolNames();
+        rParser->SetExportSymbolNames(true);
+        auto pTmpTree = rParser->Parse(aText);
+        aText = rParser->GetText();
         pTmpTree.reset();
-        rParser.SetExportSymbolNames(bVal);
+        rParser->SetExportSymbolNames(bVal);
     }
 
     OUStringBuffer sStrBuf(12);
diff --git a/starmath/source/mathml/mathmlimport.cxx b/starmath/source/mathml/mathmlimport.cxx
index f9862430665d..f224f14f77b2 100644
--- a/starmath/source/mathml/mathmlimport.cxx
+++ b/starmath/source/mathml/mathmlimport.cxx
@@ -471,13 +471,13 @@ void SmXMLImport::endDocument()
             }
 
             // Convert symbol names
-            SmParser& rParser = pDocShell->GetParser();
-            bool bVal = rParser.IsImportSymbolNames();
-            rParser.SetImportSymbolNames(true);
-            auto pTmpTree = rParser.Parse(aText);
-            aText = rParser.GetText();
+            AbstractSmParser* rParser = pDocShell->GetParser();
+            bool bVal = rParser->IsImportSymbolNames();
+            rParser->SetImportSymbolNames(true);
+            auto pTmpTree = rParser->Parse(aText);
+            aText = rParser->GetText();
             pTmpTree.reset();
-            rParser.SetImportSymbolNames(bVal);
+            rParser->SetImportSymbolNames(bVal);
 
             pDocShell->SetText(aText);
             pDocShell->SetSmSyntaxVersion(mnSmSyntaxVersion);
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 0539f52f6b6c..ee72fb55b40c 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -1285,7 +1285,7 @@ void SmViewShell::SetStatusText(const OUString& rText)
 void SmViewShell::ShowError(const SmErrorDesc* pErrorDesc)
 {
     assert(GetDoc());
-    if (pErrorDesc || nullptr != (pErrorDesc = GetDoc()->GetParser().GetError()) )
+    if (pErrorDesc || nullptr != (pErrorDesc = GetDoc()->GetParser()->GetError()) )
     {
         SetStatusText( pErrorDesc->m_aText );
         GetEditWindow()->MarkError( Point( pErrorDesc->m_pNode->GetColumn(),
@@ -1296,7 +1296,7 @@ void SmViewShell::ShowError(const SmErrorDesc* pErrorDesc)
 void SmViewShell::NextError()
 {
     assert(GetDoc());
-    const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser().NextError();
+    const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser()->NextError();
 
     if (pErrorDesc)
         ShowError( pErrorDesc );
@@ -1305,7 +1305,7 @@ void SmViewShell::NextError()
 void SmViewShell::PrevError()
 {
     assert(GetDoc());
-    const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser().PrevError();
+    const SmErrorDesc   *pErrorDesc = GetDoc()->GetParser()->PrevError();
 
     if (pErrorDesc)
         ShowError( pErrorDesc );


More information about the Libreoffice-commits mailing list