summaryrefslogtreecommitdiff
path: root/starmath/inc/parsebase.hxx
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2021-02-19 20:52:30 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-02-24 09:19:05 +0100
commit1d529ad0bd59cbbf029e45a715db5db87541d5c1 (patch)
treea1487a5f67e02d49f3b4fdce05b568b82b7ae71b /starmath/inc/parsebase.hxx
parent7cb59a86d45d06836723c93b063060f27f9669c6 (diff)
Starmath now allows multiple parsers second part
Uses AbstractSmParser as base for SmParser Renames parse._xx as parse5._xx rename of parse._xx is not recognized, so clang-formated New parse.hxx as a future mean to get the parser. Change-Id: I122c1fda0144a24316948fcc125e60ed1a130bcb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111243 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/inc/parsebase.hxx')
-rw-r--r--starmath/inc/parsebase.hxx122
1 files changed, 122 insertions, 0 deletions
diff --git a/starmath/inc/parsebase.hxx b/starmath/inc/parsebase.hxx
new file mode 100644
index 000000000000..ee6a0621b0d6
--- /dev/null
+++ b/starmath/inc/parsebase.hxx
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+/** Parses the starmath code and creates the nodes.
+ *
+ */
+
+#ifndef INCLUDED_STARMATH_INC_PARSEBASE_HXX
+#define INCLUDED_STARMATH_INC_PARSEBASE_HXX
+
+#include <unotools/charclass.hxx>
+#include <memory>
+#include <set>
+#include <vector>
+
+#include "token.hxx"
+#include "node.hxx"
+
+#define DEPTH_LIMIT 1024
+
+// Those are the errors that the parser may encounter.
+enum class SmParseError : uint_fast8_t
+{
+ None = 0,
+ UnexpectedChar = 1,
+ UnexpectedToken = 2,
+ PoundExpected = 3,
+ ColorExpected = 4,
+ LgroupExpected = 5,
+ RgroupExpected = 6,
+ LbraceExpected = 7,
+ RbraceExpected = 8,
+ ParentMismatch = 9,
+ RightExpected = 10,
+ FontExpected = 11,
+ SizeExpected = 12,
+ DoubleAlign = 13,
+ DoubleSubsupscript = 14,
+ NumberExpected = 15
+};
+
+struct SmErrorDesc
+{
+ SmParseError m_eType;
+ SmNode* m_pNode;
+ OUString m_aText;
+
+ SmErrorDesc(SmParseError eType, SmNode* pNode, OUString aText)
+ : m_eType(eType)
+ , m_pNode(pNode)
+ , m_aText(aText)
+ {
+ }
+};
+
+class DepthProtect
+{
+private:
+ sal_Int32& m_rParseDepth;
+
+public:
+ DepthProtect(sal_Int32& rParseDepth)
+ : m_rParseDepth(rParseDepth)
+ {
+ ++m_rParseDepth;
+ if (m_rParseDepth > DEPTH_LIMIT)
+ throw std::range_error("parser depth limit");
+ }
+ ~DepthProtect() { --m_rParseDepth; }
+};
+
+namespace starmathdatabase
+{
+// Must be in sync with SmParseError list
+extern const char* SmParseErrorDesc[16];
+
+OUString getParseErrorDesc(SmParseError err);
+}
+
+class AbstractSmParser
+{
+public:
+ AbstractSmParser() {}
+ virtual ~AbstractSmParser() {}
+
+ /** Parse rBuffer to formula tree */
+ virtual std::unique_ptr<SmTableNode> Parse(const OUString& rBuffer) = 0;
+ /** Parse rBuffer to formula subtree that constitutes an expression */
+ virtual std::unique_ptr<SmNode> ParseExpression(const OUString& rBuffer) = 0;
+
+ virtual const OUString& GetText() const = 0;
+
+ virtual bool IsImportSymbolNames() const = 0;
+ virtual void SetImportSymbolNames(bool bVal) = 0;
+ virtual bool IsExportSymbolNames() const = 0;
+ virtual void SetExportSymbolNames(bool bVal) = 0;
+
+ virtual const SmErrorDesc* NextError() = 0;
+ virtual const SmErrorDesc* PrevError() = 0;
+ virtual const SmErrorDesc* GetError() const = 0;
+ virtual const std::set<OUString>& GetUsedSymbols() const = 0;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */