bump product version to 7.2.5.1
[LibreOffice.git] / starmath / inc / parsebase.hxx
blobc8507db1dbbb2065b20034a9eaecea97bbdd43a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 /** Parses the starmath code and creates the nodes.
24 #pragma once
26 #include <unotools/charclass.hxx>
28 #include "node.hxx"
30 #define DEPTH_LIMIT 1024
32 // Those are the errors that the parser may encounter.
33 enum class SmParseError : uint_fast8_t
35 None = 0,
36 UnexpectedChar = 1,
37 UnexpectedToken = 2,
38 PoundExpected = 3,
39 ColorExpected = 4,
40 LgroupExpected = 5,
41 RgroupExpected = 6,
42 LbraceExpected = 7,
43 RbraceExpected = 8,
44 ParentMismatch = 9,
45 RightExpected = 10,
46 FontExpected = 11,
47 SizeExpected = 12,
48 DoubleAlign = 13,
49 DoubleSubsupscript = 14,
50 NumberExpected = 15
53 struct SmErrorDesc
55 SmParseError m_eType;
56 SmNode* m_pNode;
57 OUString m_aText;
59 SmErrorDesc(SmParseError eType, SmNode* pNode, OUString aText)
60 : m_eType(eType)
61 , m_pNode(pNode)
62 , m_aText(aText)
67 class DepthProtect
69 private:
70 sal_Int32& m_rParseDepth;
72 public:
73 DepthProtect(sal_Int32& rParseDepth)
74 : m_rParseDepth(rParseDepth)
76 ++m_rParseDepth;
77 if (m_rParseDepth > DEPTH_LIMIT)
78 throw std::range_error("parser depth limit");
80 ~DepthProtect() { --m_rParseDepth; }
83 namespace starmathdatabase
85 // Must be in sync with SmParseError list
86 extern const char* SmParseErrorDesc[16];
88 OUString getParseErrorDesc(SmParseError err);
91 class AbstractSmParser
93 public:
94 AbstractSmParser() {}
95 virtual ~AbstractSmParser() {}
97 /** Parse rBuffer to formula tree */
98 virtual std::unique_ptr<SmTableNode> Parse(const OUString& rBuffer) = 0;
99 /** Parse rBuffer to formula subtree that constitutes an expression */
100 virtual std::unique_ptr<SmNode> ParseExpression(const OUString& rBuffer) = 0;
102 virtual const OUString& GetText() const = 0;
104 virtual bool IsImportSymbolNames() const = 0;
105 virtual void SetImportSymbolNames(bool bVal) = 0;
106 virtual bool IsExportSymbolNames() const = 0;
107 virtual void SetExportSymbolNames(bool bVal) = 0;
109 virtual const SmErrorDesc* NextError() = 0;
110 virtual const SmErrorDesc* PrevError() = 0;
111 virtual const SmErrorDesc* GetError() const = 0;
112 virtual const std::set<OUString>& GetUsedSymbols() const = 0;
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */