Bump version to 21.06.18.1
[LibreOffice.git] / starmath / inc / parse.hxx
blobd7db4772e81c2367575158fa310c4b004c9b3d56
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 #ifndef INCLUDED_STARMATH_INC_PARSE_HXX
25 #define INCLUDED_STARMATH_INC_PARSE_HXX
27 #include <unotools/charclass.hxx>
28 #include <memory>
29 #include <set>
30 #include <vector>
32 #include "token.hxx"
33 #include "error.hxx"
35 class SmBlankNode;
36 class SmBracebodyNode;
37 class SmExpressionNode;
38 class SmGlyphSpecialNode;
39 class SmNode;
40 class SmOperNode;
41 class SmSpecialNode;
42 class SmStructureNode;
43 class SmTableNode;
44 class SmTextNode;
46 #define DEPTH_LIMIT 1024
48 class SmParser
50 OUString m_aBufferString;
51 SmToken m_aCurToken;
52 std::vector<std::unique_ptr<SmErrorDesc>> m_aErrDescList;
53 int m_nCurError;
54 sal_Int32 m_nBufferIndex,
55 m_nTokenIndex;
56 sal_Int32 m_nRow, // 1-based
57 m_nColOff; // 0-based
58 bool m_bImportSymNames,
59 m_bExportSymNames;
60 sal_Int32 m_nParseDepth;
62 class DepthProtect
64 private:
65 sal_Int32& m_rParseDepth;
66 public:
67 DepthProtect(sal_Int32& rParseDepth)
68 : m_rParseDepth(rParseDepth)
70 ++m_rParseDepth;
72 bool TooDeep() const { return m_rParseDepth > DEPTH_LIMIT; }
73 ~DepthProtect()
75 --m_rParseDepth;
79 // map of used symbols (used to reduce file size by exporting only actually used symbols)
80 std::set< OUString > m_aUsedSymbols;
82 // CharClass representing a locale for parsing numbers
83 CharClass m_aNumCC;
84 // pointer to System locale's CharClass, which is alive inside SM_MOD()
85 const CharClass* m_pSysCC;
87 SmParser(const SmParser&) = delete;
88 SmParser& operator=(const SmParser&) = delete;
90 // Moves between tokens inside starmath code.
91 void NextToken();
92 void NextTokenColor(bool dvipload);
93 void NextTokenFontSize();
94 sal_Int32 GetTokenIndex() const { return m_nTokenIndex; }
95 void Replace( sal_Int32 nPos, sal_Int32 nLen, const OUString &rText );
97 inline bool TokenInGroup( TG nGroup );
99 // grammar
100 std::unique_ptr<SmTableNode> DoTable();
101 std::unique_ptr<SmNode> DoLine();
102 std::unique_ptr<SmNode> DoExpression(bool bUseExtraSpaces = true);
103 std::unique_ptr<SmNode> DoRelation();
104 std::unique_ptr<SmNode> DoSum();
105 std::unique_ptr<SmNode> DoProduct();
106 std::unique_ptr<SmNode> DoSubSup(TG nActiveGroup, SmNode *pGivenNode);
107 std::unique_ptr<SmNode> DoSubSupEvaluate(SmNode *pGivenNode);
108 std::unique_ptr<SmNode> DoOpSubSup();
109 std::unique_ptr<SmNode> DoPower();
110 std::unique_ptr<SmBlankNode> DoBlank();
111 std::unique_ptr<SmNode> DoTerm(bool bGroupNumberIdent);
112 std::unique_ptr<SmNode> DoEscape();
113 std::unique_ptr<SmOperNode> DoOperator();
114 std::unique_ptr<SmNode> DoOper();
115 std::unique_ptr<SmStructureNode> DoUnOper();
116 std::unique_ptr<SmNode> DoAlign(bool bUseExtraSpaces = true);
117 std::unique_ptr<SmStructureNode> DoFontAttribut();
118 std::unique_ptr<SmStructureNode> DoAttribut();
119 std::unique_ptr<SmStructureNode> DoFont();
120 std::unique_ptr<SmStructureNode> DoFontSize();
121 std::unique_ptr<SmStructureNode> DoColor();
122 std::unique_ptr<SmStructureNode> DoBrace();
123 std::unique_ptr<SmBracebodyNode> DoBracebody(bool bIsLeftRight);
124 std::unique_ptr<SmNode> DoEvaluate();
125 std::unique_ptr<SmTextNode> DoFunction();
126 std::unique_ptr<SmTableNode> DoBinom();
127 std::unique_ptr<SmBinVerNode> DoFrac();
128 std::unique_ptr<SmStructureNode> DoStack();
129 std::unique_ptr<SmStructureNode> DoMatrix();
130 std::unique_ptr<SmSpecialNode> DoSpecial();
131 std::unique_ptr<SmGlyphSpecialNode> DoGlyphSpecial();
132 std::unique_ptr<SmExpressionNode> DoError(SmParseError Error);
133 // end of grammar
135 public:
136 SmParser();
138 /** Parse rBuffer to formula tree */
139 std::unique_ptr<SmTableNode> Parse(const OUString &rBuffer);
140 /** Parse rBuffer to formula subtree that constitutes an expression */
141 std::unique_ptr<SmNode> ParseExpression(const OUString &rBuffer);
143 const OUString & GetText() const { return m_aBufferString; };
145 bool IsImportSymbolNames() const { return m_bImportSymNames; }
146 void SetImportSymbolNames(bool bVal) { m_bImportSymNames = bVal; }
147 bool IsExportSymbolNames() const { return m_bExportSymNames; }
148 void SetExportSymbolNames(bool bVal) { m_bExportSymNames = bVal; }
150 void AddError(SmParseError Type, SmNode *pNode);
151 const SmErrorDesc* NextError();
152 const SmErrorDesc* PrevError();
153 const SmErrorDesc* GetError();
154 const std::set< OUString >& GetUsedSymbols() const { return m_aUsedSymbols; }
158 inline bool SmParser::TokenInGroup( TG nGroup)
160 return bool(m_aCurToken.nGroup & nGroup);
164 #endif
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */