1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 #define DEPTH_LIMIT 1024
36 OUString m_aBufferString
;
38 std::vector
<std::unique_ptr
<SmErrorDesc
>> m_aErrDescList
;
40 sal_Int32 m_nBufferIndex
,
42 sal_Int32 m_nRow
, // 1-based
44 bool m_bImportSymNames
,
46 sal_Int32 m_nParseDepth
;
51 sal_Int32
& m_rParseDepth
;
53 DepthProtect(sal_Int32
& rParseDepth
)
54 : m_rParseDepth(rParseDepth
)
58 bool TooDeep() const { return m_rParseDepth
> DEPTH_LIMIT
; }
65 // map of used symbols (used to reduce file size by exporting only actually used symbols)
66 std::set
< OUString
> m_aUsedSymbols
;
68 // CharClass representing a locale for parsing numbers
70 // pointer to System locale's CharClass, which is alive inside SM_MOD()
71 const CharClass
* m_pSysCC
;
73 SmParser(const SmParser
&) = delete;
74 SmParser
& operator=(const SmParser
&) = delete;
77 sal_Int32
GetTokenIndex() const { return m_nTokenIndex
; }
78 void Replace( sal_Int32 nPos
, sal_Int32 nLen
, const OUString
&rText
);
80 inline bool TokenInGroup( TG nGroup
);
83 std::unique_ptr
<SmTableNode
> DoTable();
84 std::unique_ptr
<SmNode
> DoLine();
85 std::unique_ptr
<SmNode
> DoExpression(bool bUseExtraSpaces
= true);
86 std::unique_ptr
<SmNode
> DoRelation();
87 std::unique_ptr
<SmNode
> DoSum();
88 std::unique_ptr
<SmNode
> DoProduct();
89 std::unique_ptr
<SmNode
> DoSubSup(TG nActiveGroup
, SmNode
*pGivenNode
);
90 std::unique_ptr
<SmNode
> DoOpSubSup();
91 std::unique_ptr
<SmNode
> DoPower();
92 SmBlankNode
*DoBlank();
93 SmNode
*DoTerm(bool bGroupNumberIdent
);
95 SmOperNode
*DoOperator();
96 std::unique_ptr
<SmNode
> DoOper();
97 SmStructureNode
*DoUnOper();
98 std::unique_ptr
<SmNode
> DoAlign(bool bUseExtraSpaces
= true);
99 std::unique_ptr
<SmStructureNode
> DoFontAttribut();
100 std::unique_ptr
<SmStructureNode
> DoAttribut();
101 std::unique_ptr
<SmStructureNode
> DoFont();
102 std::unique_ptr
<SmStructureNode
> DoFontSize();
103 std::unique_ptr
<SmStructureNode
> DoColor();
104 SmStructureNode
*DoBrace();
105 SmBracebodyNode
*DoBracebody(bool bIsLeftRight
);
106 SmTextNode
*DoFunction();
107 SmTableNode
*DoBinom();
108 SmStructureNode
*DoStack();
109 SmStructureNode
*DoMatrix();
110 SmSpecialNode
*DoSpecial();
111 SmGlyphSpecialNode
*DoGlyphSpecial();
112 SmExpressionNode
*DoError(SmParseError Error
);
118 /** Parse rBuffer to formula tree */
119 std::unique_ptr
<SmTableNode
> Parse(const OUString
&rBuffer
);
120 /** Parse rBuffer to formula subtree that constitutes an expression */
121 std::unique_ptr
<SmNode
> ParseExpression(const OUString
&rBuffer
);
123 const OUString
& GetText() const { return m_aBufferString
; };
125 bool IsImportSymbolNames() const { return m_bImportSymNames
; }
126 void SetImportSymbolNames(bool bVal
) { m_bImportSymNames
= bVal
; }
127 bool IsExportSymbolNames() const { return m_bExportSymNames
; }
128 void SetExportSymbolNames(bool bVal
) { m_bExportSymNames
= bVal
; }
130 void AddError(SmParseError Type
, SmNode
*pNode
);
131 const SmErrorDesc
* NextError();
132 const SmErrorDesc
* PrevError();
133 const SmErrorDesc
* GetError();
134 static const SmTokenTableEntry
* GetTokenTableEntry( const OUString
&rName
);
135 const std::set
< OUString
>& GetUsedSymbols() const { return m_aUsedSymbols
; }
139 inline bool SmParser::TokenInGroup( TG nGroup
)
141 return bool(m_aCurToken
.nGroup
& nGroup
);
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */