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 <vcl/svapp.hxx>
37 #define TGOPER 0x00000001
38 #define TGRELATION 0x00000002
39 #define TGSUM 0x00000004
40 #define TGPRODUCT 0x00000008
41 #define TGUNOPER 0x00000010
42 #define TGPOWER 0x00000020
43 #define TGATTRIBUT 0x00000040
44 #define TGALIGN 0x00000080
45 #define TGFUNCTION 0x00000100
46 #define TGBLANK 0x00000200
47 #define TGLBRACES 0x00000400
48 #define TGRBRACES 0x00000800
49 #define TGCOLOR 0x00001000
50 #define TGFONT 0x00002000
51 #define TGSTANDALONE 0x00004000
52 #define TGDISCARDED 0x00008000
53 #define TGLIMIT 0x00010000
54 #define TGFONTATTR 0x00020000
59 /* 0*/ TEND
, TLGROUP
, TRGROUP
, TLPARENT
, TRPARENT
,
60 /* 5*/ TLBRACKET
, TRBRACKET
, TPLUS
, TMINUS
, TMULTIPLY
,
61 /* 10*/ TDIVIDEBY
, TASSIGN
, TPOUND
, TSPECIAL
, TSLASH
,
62 /* 15*/ TBACKSLASH
, TBLANK
, TSBLANK
, TRSUB
, TRSUP
,
63 /* 20*/ TCSUB
, TCSUP
, TLSUB
, TLSUP
, TGT
,
64 /* 25*/ TLT
, TAND
, TOR
, TINTERSECT
, TUNION
,
65 /* 30*/ TNEWLINE
, TBINOM
, TFROM
, TTO
, TINT
,
66 /* 35*/ TSUM
, TOPER
, TABS
, TSQRT
, TFACT
,
67 /* 40*/ TNROOT
, TOVER
, TTIMES
, TGE
, TLE
,
68 /* 45*/ TGG
, TLL
, TDOTSAXIS
, TDOTSLOW
, TDOTSVERT
,
69 /* 50*/ TDOTSDIAG
, TDOTSUP
, TDOTSDOWN
, TACUTE
, TBAR
,
70 /* 55*/ TBREVE
, TCHECK
, TCIRCLE
, TDOT
, TDDOT
,
71 /* 60*/ TDDDOT
, TGRAVE
, THAT
, TTILDE
, TVEC
,
72 /* 65*/ TUNDERLINE
, TOVERLINE
, TOVERSTRIKE
, TITALIC
, TNITALIC
,
73 /* 70*/ TBOLD
, TNBOLD
, TPHANTOM
, TFONT
, TSIZE
,
74 /* 75*/ TCOLOR
, TALIGNL
, TALIGNC
, TALIGNR
, TLEFT
,
75 /* 80*/ TRIGHT
, TLANGLE
, TLBRACE
, TLLINE
, TLDLINE
,
76 /* 85*/ TLCEIL
, TLFLOOR
, TNONE
, TMLINE
, TRANGLE
,
77 /* 90*/ TRBRACE
, TRLINE
, TRDLINE
, TRCEIL
, TRFLOOR
,
78 /* 95*/ TSIN
, TCOS
, TTAN
, TCOT
, TFUNC
,
79 /*100*/ TSTACK
, TMATRIX
, TMATFORM
, TDPOUND
, TPLACE
,
80 /*105*/ TTEXT
, TNUMBER
, TCHARACTER
, TIDENT
, TNEQ
,
81 /*110*/ TEQUIV
, TDEF
, TPROP
, TSIM
, TSIMEQ
,
82 /*115*/ TAPPROX
, TPARALLEL
, TORTHO
, TIN
, TNOTIN
,
83 /*120*/ TSUBSET
, TSUBSETEQ
, TSUPSET
, TSUPSETEQ
, TPLUSMINUS
,
84 /*125*/ TMINUSPLUS
, TOPLUS
, TOMINUS
, TDIV
, TOTIMES
,
85 /*130*/ TODIVIDE
, TTRANSL
, TTRANSR
, TIINT
, TIIINT
,
86 /*135*/ TLINT
, TLLINT
, TLLLINT
, TPROD
, TCOPROD
,
87 /*140*/ TFORALL
, TEXISTS
, TNOTEXISTS
, TLIM
, TNABLA
,
88 /*145*/ TTOWARD
, TSINH
, TCOSH
, TTANH
, TCOTH
,
89 /*150*/ TASIN
, TACOS
, TATAN
, TLN
, TLOG
,
90 /*155*/ TUOPER
, TBOPER
, TBLACK
, TWHITE
, TRED
,
91 /*160*/ TGREEN
, TBLUE
, TCYAN
, TMAGENTA
, TYELLOW
,
92 /*165*/ TFIXED
, TSANS
, TSERIF
, TPOINT
, TASINH
,
93 /*170*/ TACOSH
, TATANH
, TACOTH
, TACOT
, TEXP
,
94 /*175*/ TCDOT
, TODOT
, TLESLANT
, TGESLANT
, TNSUBSET
,
95 /*180*/ TNSUPSET
, TNSUBSETEQ
, TNSUPSETEQ
, TPARTIAL
, TNEG
,
96 /*185*/ TNI
, TBACKEPSILON
, TALEPH
, TIM
, TRE
,
97 /*190*/ TWP
, TEMPTYSET
, TINFINITY
, TESCAPE
, TLIMSUP
,
98 /*195*/ TLIMINF
, TNDIVIDES
, TDRARROW
, TDLARROW
, TDLRARROW
,
99 /*200*/ TUNDERBRACE
, TOVERBRACE
, TCIRC
, TTOP
, THBAR
,
100 /*205*/ TLAMBDABAR
, TLEFTARROW
, TRIGHTARROW
, TUPARROW
, TDOWNARROW
,
101 /*210*/ TDIVIDES
, TNDIBVIDES
, TSETN
, TSETZ
, TSETQ
,
102 /*215*/ TSETR
, TSETC
, TWIDEVEC
, TWIDETILDE
, TWIDEHAT
,
103 /*220*/ TWIDESLASH
, TWIDEBACKSLASH
, TLDBRACKET
, TRDBRACKET
, TNOSPACE
,
104 /*225*/ TUNKNOWN
, TDEBUG
, TPRECEDES
, TSUCCEEDS
, TPRECEDESEQUAL
,
105 /*230*/ TSUCCEEDSEQUAL
, TPRECEDESEQUIV
, TSUCCEEDSEQUIV
, TNOTPRECEDES
, TNOTSUCCEEDS
,
113 OUString aText
; // token text
114 SmTokenType eType
; // token info
115 sal_Unicode cMathChar
;
126 SmToken(SmTokenType eTokenType
,
128 const sal_Char
* pText
,
129 sal_uLong nTokenGroup
= 0,
130 sal_uInt16 nTokenLevel
= 0);
136 PE_NONE
, PE_UNEXPECTED_END_OF_INPUT
,
137 PE_UNEXPECTED_CHAR
, PE_UNEXPECTED_TOKEN
,
138 PE_FUNC_EXPECTED
, PE_UNOPER_EXPECTED
,
139 PE_BINOPER_EXPECTED
, PE_SYMBOL_EXPECTED
,
140 PE_IDENTIFIER_EXPECTED
, PE_POUND_EXPECTED
,
141 PE_COLOR_EXPECTED
, PE_LGROUP_EXPECTED
,
142 PE_RGROUP_EXPECTED
, PE_LBRACE_EXPECTED
,
143 PE_RBRACE_EXPECTED
, PE_PARENT_MISMATCH
,
144 PE_RIGHT_EXPECTED
, PE_FONT_EXPECTED
,
145 PE_SIZE_EXPECTED
, PE_DOUBLE_ALIGN
,
146 PE_DOUBLE_SUBSUPSCRIPT
158 typedef ::std::stack
< SmNode
* > SmNodeStack
;
159 typedef ::std::vector
< SmErrorDesc
* > SmErrDescList
;
161 /**************************************************************************/
163 struct SmTokenTableEntry
165 const sal_Char
* pIdent
;
167 sal_Unicode cMathChar
;
174 OUString m_aBufferString
;
176 SmNodeStack m_aNodeStack
;
177 SmErrDescList m_aErrDescList
;
179 LanguageType m_nLang
;
180 sal_Int32 m_nBufferIndex
,
184 bool bImportSymNames
,
187 // map of used symbols (used to reduce file size by exporting only actually used symbols)
188 std::set
< OUString
> m_aUsedSymbols
;
190 //! locale where '.' is decimal separator!
191 ::com::sun::star::lang::Locale m_aDotLoc
;
193 // declare copy-constructor and assignment-operator private
194 SmParser(const SmParser
&);
195 SmParser
& operator = (const SmParser
&);
198 #if OSL_DEBUG_LEVEL > 1
199 bool IsDelimiter( const OUString
&rTxt
, sal_Int32 nPos
);
202 sal_Int32
GetTokenIndex() const { return m_nTokenIndex
; }
203 void Replace( sal_Int32 nPos
, sal_Int32 nLen
, const OUString
&rText
);
205 inline bool TokenInGroup( sal_uLong nGroup
);
214 void SubSup(sal_uLong nActiveGroup
);
218 void Term(bool bGroupNumberIdent
);
230 void Bracebody(bool bIsLeftRight
);
239 LanguageType
GetLanguage() const { return m_nLang
; }
240 void SetLanguage( LanguageType nNewLang
) { m_nLang
= nNewLang
; }
242 void Error(SmParseError Error
);
244 void ClearUsedSymbols() { m_aUsedSymbols
.clear(); }
245 void AddToUsedSymbols( const OUString
&rSymbolName
) { m_aUsedSymbols
.insert( rSymbolName
); }
250 /** Parse rBuffer to formula tree */
251 SmNode
*Parse(const OUString
&rBuffer
);
252 /** Parse rBuffer to formula subtree that constitutes an expression */
253 SmNode
*ParseExpression(const OUString
&rBuffer
);
255 const OUString
& GetText() const { return m_aBufferString
; };
257 bool IsImportSymbolNames() const { return bImportSymNames
; }
258 void SetImportSymbolNames(bool bVal
) { bImportSymNames
= bVal
; }
259 bool IsExportSymbolNames() const { return m_bExportSymNames
; }
260 void SetExportSymbolNames(bool bVal
) { m_bExportSymNames
= bVal
; }
262 size_t AddError(SmParseError Type
, SmNode
*pNode
);
263 const SmErrorDesc
* NextError();
264 const SmErrorDesc
* PrevError();
265 const SmErrorDesc
* GetError(size_t i
= size_t(-1) );
266 static const SmTokenTableEntry
* GetTokenTableEntry( const OUString
&rName
);
267 bool IsUsedSymbol( const OUString
&rSymbolName
) const { return m_aUsedSymbols
.find( rSymbolName
) != m_aUsedSymbols
.end(); }
268 std::set
< OUString
> GetUsedSymbols() const { return m_aUsedSymbols
; }
272 inline bool SmParser::TokenInGroup( sal_uLong nGroup
)
274 return (m_aCurToken
.nGroup
& nGroup
) ? true : false;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */