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>
31 class SmBracebodyNode
;
32 class SmExpressionNode
;
33 class SmGlyphSpecialNode
;
37 class SmStructureNode
;
41 #define DEPTH_LIMIT 1024
45 OUString m_aBufferString
;
47 std::vector
<std::unique_ptr
<SmErrorDesc
>> m_aErrDescList
;
49 sal_Int32 m_nBufferIndex
,
51 sal_Int32 m_nRow
, // 1-based
53 bool m_bImportSymNames
,
55 sal_Int32 m_nParseDepth
;
60 sal_Int32
& m_rParseDepth
;
62 DepthProtect(sal_Int32
& rParseDepth
)
63 : m_rParseDepth(rParseDepth
)
67 bool TooDeep() const { return m_rParseDepth
> DEPTH_LIMIT
; }
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;
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
);
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
);
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
);
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */