Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / starmath / inc / parse.hxx
blob2d6036bb8df186454ce8fad94fc5aade09bd6be1
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 .
19 #ifndef INCLUDED_STARMATH_INC_PARSE_HXX
20 #define INCLUDED_STARMATH_INC_PARSE_HXX
22 #include <unotools/charclass.hxx>
23 #include <memory>
24 #include <set>
25 #include <vector>
27 #include "token.hxx"
28 #include "error.hxx"
30 class SmBlankNode;
31 class SmBracebodyNode;
32 class SmExpressionNode;
33 class SmGlyphSpecialNode;
34 class SmNode;
35 class SmOperNode;
36 class SmSpecialNode;
37 class SmStructureNode;
38 class SmTableNode;
39 class SmTextNode;
41 #define DEPTH_LIMIT 1024
43 class SmParser
45 OUString m_aBufferString;
46 SmToken m_aCurToken;
47 std::vector<std::unique_ptr<SmErrorDesc>> m_aErrDescList;
48 int m_nCurError;
49 sal_Int32 m_nBufferIndex,
50 m_nTokenIndex;
51 sal_Int32 m_nRow, // 1-based
52 m_nColOff; // 0-based
53 bool m_bImportSymNames,
54 m_bExportSymNames;
55 sal_Int32 m_nParseDepth;
57 class DepthProtect
59 private:
60 sal_Int32& m_rParseDepth;
61 public:
62 DepthProtect(sal_Int32& rParseDepth)
63 : m_rParseDepth(rParseDepth)
65 ++m_rParseDepth;
67 bool TooDeep() const { return m_rParseDepth > DEPTH_LIMIT; }
68 ~DepthProtect()
70 --m_rParseDepth;
74 // map of used symbols (used to reduce file size by exporting only actually used symbols)
75 std::set< OUString > m_aUsedSymbols;
77 // CharClass representing a locale for parsing numbers
78 CharClass const m_aNumCC;
79 // pointer to System locale's CharClass, which is alive inside SM_MOD()
80 const CharClass* m_pSysCC;
82 SmParser(const SmParser&) = delete;
83 SmParser& operator=(const SmParser&) = delete;
85 void NextToken();
86 sal_Int32 GetTokenIndex() const { return m_nTokenIndex; }
87 void Replace( sal_Int32 nPos, sal_Int32 nLen, const OUString &rText );
89 inline bool TokenInGroup( TG nGroup );
91 // grammar
92 std::unique_ptr<SmTableNode> DoTable();
93 std::unique_ptr<SmNode> DoLine();
94 std::unique_ptr<SmNode> DoExpression(bool bUseExtraSpaces = true);
95 std::unique_ptr<SmNode> DoRelation();
96 std::unique_ptr<SmNode> DoSum();
97 std::unique_ptr<SmNode> DoProduct();
98 std::unique_ptr<SmNode> DoSubSup(TG nActiveGroup, SmNode *pGivenNode);
99 std::unique_ptr<SmNode> DoOpSubSup();
100 std::unique_ptr<SmNode> DoPower();
101 std::unique_ptr<SmBlankNode> DoBlank();
102 std::unique_ptr<SmNode> DoTerm(bool bGroupNumberIdent);
103 std::unique_ptr<SmNode> DoEscape();
104 std::unique_ptr<SmOperNode> DoOperator();
105 std::unique_ptr<SmNode> DoOper();
106 std::unique_ptr<SmStructureNode> DoUnOper();
107 std::unique_ptr<SmNode> DoAlign(bool bUseExtraSpaces = true);
108 std::unique_ptr<SmStructureNode> DoFontAttribut();
109 std::unique_ptr<SmStructureNode> DoAttribut();
110 std::unique_ptr<SmStructureNode> DoFont();
111 std::unique_ptr<SmStructureNode> DoFontSize();
112 std::unique_ptr<SmStructureNode> DoColor();
113 std::unique_ptr<SmStructureNode> DoBrace();
114 std::unique_ptr<SmBracebodyNode> DoBracebody(bool bIsLeftRight);
115 std::unique_ptr<SmTextNode> DoFunction();
116 std::unique_ptr<SmTableNode> DoBinom();
117 std::unique_ptr<SmStructureNode> DoStack();
118 std::unique_ptr<SmStructureNode> DoMatrix();
119 std::unique_ptr<SmSpecialNode> DoSpecial();
120 std::unique_ptr<SmGlyphSpecialNode> DoGlyphSpecial();
121 std::unique_ptr<SmExpressionNode> DoError(SmParseError Error);
122 // end of grammar
124 public:
125 SmParser();
127 /** Parse rBuffer to formula tree */
128 std::unique_ptr<SmTableNode> Parse(const OUString &rBuffer);
129 /** Parse rBuffer to formula subtree that constitutes an expression */
130 std::unique_ptr<SmNode> ParseExpression(const OUString &rBuffer);
132 const OUString & GetText() const { return m_aBufferString; };
134 bool IsImportSymbolNames() const { return m_bImportSymNames; }
135 void SetImportSymbolNames(bool bVal) { m_bImportSymNames = bVal; }
136 bool IsExportSymbolNames() const { return m_bExportSymNames; }
137 void SetExportSymbolNames(bool bVal) { m_bExportSymNames = bVal; }
139 void AddError(SmParseError Type, SmNode *pNode);
140 const SmErrorDesc* NextError();
141 const SmErrorDesc* PrevError();
142 const SmErrorDesc* GetError();
143 static const SmTokenTableEntry* GetTokenTableEntry( const OUString &rName );
144 const std::set< OUString >& GetUsedSymbols() const { return m_aUsedSymbols; }
148 inline bool SmParser::TokenInGroup( TG nGroup)
150 return bool(m_aCurToken.nGroup & nGroup);
154 #endif
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */