Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_starmath / parse.hxx
blobe0b18d5bd8e26d718db0cc47b1f64504c36f052c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: parse.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef PARSE_HXX
31 #define PARSE_HXX
34 #ifndef _SV_SVAPP_HXX
35 #include <vcl/svapp.hxx>
36 #endif
37 #ifndef _STACK_HXX //autogen
38 #include <tools/stack.hxx>
39 #endif
41 namespace binfilter {
43 class SmNode;
44 class SmDocShell;
47 // TokenGroups
48 #define TGOPER 0x00000001
49 #define TGRELATION 0x00000002
50 #define TGSUM 0x00000004
51 #define TGPRODUCT 0x00000008
52 #define TGUNOPER 0x00000010
53 #define TGPOWER 0x00000020
54 #define TGATTRIBUT 0x00000040
55 #define TGALIGN 0x00000080
56 #define TGFUNCTION 0x00000100
57 #define TGBLANK 0x00000200
58 #define TGLBRACES 0x00000400
59 #define TGRBRACES 0x00000800
60 #define TGCOLOR 0x00001000
61 #define TGFONT 0x00002000
62 #define TGSTANDALONE 0x00004000
63 #define TGDISCARDED 0x00008000
64 #define TGLIMIT 0x00010000
65 #define TGFONTATTR 0x00020000
68 enum SmTokenType
70 TEND, TLGROUP, TRGROUP, TLPARENT, TRPARENT,
71 TLBRACKET, TRBRACKET, TPLUS, TMINUS, TMULTIPLY,
72 TDIVIDEBY, TASSIGN, TPOUND, TSPECIAL, TSLASH,
73 TBACKSLASH, TBLANK, TSBLANK, TRSUB, TRSUP,
74 TCSUB, TCSUP, TLSUB, TLSUP, TGT,
75 TLT, TAND, TOR, TINTERSECT, TUNION,
76 TNEWLINE, TBINOM, TFROM, TTO, TINT,
77 TSUM, TOPER, TABS, TSQRT, TFACT,
78 TNROOT, TOVER, TTIMES, TGE, TLE,
79 TGG, TLL, TDOTSAXIS, TDOTSLOW, TDOTSVERT,
80 TDOTSDIAG, TDOTSUP, TDOTSDOWN, TACUTE, TBAR,
81 TBREVE, TCHECK, TCIRCLE, TDOT, TDDOT,
82 TDDDOT, TGRAVE, THAT, TTILDE, TVEC,
83 TUNDERLINE, TOVERLINE, TOVERSTRIKE, TITALIC, TNITALIC,
84 TBOLD, TNBOLD, TPHANTOM, TFONT, TSIZE,
85 TCOLOR, TALIGNL, TALIGNC, TALIGNR, TLEFT,
86 TRIGHT, TLANGLE, TLBRACE, TLLINE, TLDLINE,
87 TLCEIL, TLFLOOR, TNONE, TMLINE, TRANGLE,
88 TRBRACE, TRLINE, TRDLINE, TRCEIL, TRFLOOR,
89 TSIN, TCOS, TTAN, TCOT, TFUNC,
90 TSTACK, TMATRIX, TMATFORM, TDPOUND, TPLACE,
91 TTEXT, TNUMBER, TCHARACTER, TIDENT, TNEQ,
92 TEQUIV, TDEF, TPROP, TSIM, TSIMEQ,
93 TAPPROX, TPARALLEL, TORTHO, TIN, TNOTIN,
94 TSUBSET, TSUBSETEQ, TSUPSET, TSUPSETEQ, TPLUSMINUS,
95 TMINUSPLUS, TOPLUS, TOMINUS, TDIV, TOTIMES,
96 TODIVIDE, TTRANSL, TTRANSR, TIINT, TIIINT,
97 TLINT, TLLINT, TLLLINT, TPROD, TCOPROD,
98 TFORALL, TEXISTS, TLIM, TNABLA, TTOWARD,
99 TSINH, TCOSH, TTANH, TCOTH, TASIN,
100 TACOS, TATAN, TLN, TLOG, TUOPER,
101 TBOPER, TBLACK, TWHITE, TRED, TGREEN,
102 TBLUE, TCYAN, TMAGENTA, TYELLOW, TFIXED,
103 TSANS, TSERIF, TPOINT, TASINH, TACOSH,
104 TATANH, TACOTH, TACOT, TEXP, TCDOT,
105 TODOT, TLESLANT, TGESLANT, TNSUBSET, TNSUPSET,
106 TNSUBSETEQ, TNSUPSETEQ, TPARTIAL, TNEG, TNI,
107 TBACKEPSILON, TALEPH, TIM, TRE, TWP,
108 TEMPTYSET, TINFINITY, TESCAPE, TLIMSUP, TLIMINF,
109 TNDIVIDES, TDRARROW, TDLARROW, TDLRARROW, TUNDERBRACE,
110 TOVERBRACE, TCIRC, TTOP, THBAR, TLAMBDABAR,
111 TLEFTARROW, TRIGHTARROW, TUPARROW, TDOWNARROW, TDIVIDES,
112 TNDIBVIDES, TSETN, TSETZ, TSETQ, TSETR,
113 TSETC, TWIDEVEC, TWIDETILDE, TWIDEHAT, TWIDESLASH,
114 TWIDEBACKSLASH, TLDBRACKET, TRDBRACKET,
115 TUNKNOWN, TDEBUG
119 struct SmToken
121 // token text
122 String aText;
123 // token info
124 SmTokenType eType;
125 sal_Unicode cMathChar;
126 // parse-help info
127 ULONG nGroup;
128 USHORT nLevel;
129 // token position
130 INT32 nRow;
131 INT32 nCol;
133 SmToken();
137 enum SmParseError
139 PE_NONE, PE_UNEXPECTED_END_OF_INPUT,
140 PE_UNEXPECTED_CHAR, PE_UNEXPECTED_TOKEN,
141 PE_FUNC_EXPECTED, PE_UNOPER_EXPECTED,
142 PE_BINOPER_EXPECTED, PE_SYMBOL_EXPECTED,
143 PE_IDENTIFIER_EXPECTED, PE_POUND_EXPECTED,
144 PE_COLOR_EXPECTED, PE_LGROUP_EXPECTED,
145 PE_RGROUP_EXPECTED, PE_LBRACE_EXPECTED,
146 PE_RBRACE_EXPECTED, PE_PARENT_MISMATCH,
147 PE_RIGHT_EXPECTED, PE_FONT_EXPECTED,
148 PE_SIZE_EXPECTED, PE_DOUBLE_ALIGN,
149 PE_DOUBLE_SUBSUPSCRIPT
153 struct SmErrorDesc
155 SmParseError Type;
156 SmNode *pNode;
157 String Text;
160 DECLARE_STACK(SmNodeStack, SmNode *)
161 DECLARE_LIST(SmErrDescList, SmErrorDesc *)
163 /**************************************************************************/
165 // defines possible conversions of the formula text from the format of
166 // one release to the one of another.
167 enum SmConvert
169 CONVERT_NONE,
170 CONVERT_40_TO_50,
171 CONVERT_50_TO_60,
172 CONVERT_60_TO_50
176 class SmParser
178 String BufferString;
179 SmToken CurToken;
180 SmNodeStack NodeStack;
181 SmErrDescList ErrDescList;
182 int CurError;
183 LanguageType nLang;
184 xub_StrLen BufferIndex,
185 nTokenIndex;
186 USHORT Row,
187 ColOff;
188 SmConvert eConversion;
189 BOOL bImportSymNames,
190 bExportSymNames;
192 // declare copy-constructor and assignment-operator private
193 SmParser(const SmParser &);
194 SmParser & operator = (const SmParser &);
196 protected:
198 #if OSL_DEBUG_LEVEL > 1
199 BOOL IsDelimiter( const String &rTxt, xub_StrLen nPos );
200 #endif
202 void NextToken();
203 xub_StrLen GetTokenIndex() const { return nTokenIndex; }
204 void Insert(const String &rText, USHORT nPos);
205 void Replace( USHORT nPos, USHORT nLen, const String &rText );
207 inline BOOL TokenInGroup(ULONG nGroup);
209 // grammar
210 void Table();
211 void Line();
212 void Expression();
213 void Relation();
214 void Sum();
215 void Product();
216 void SubSup(ULONG nActiveGroup);
217 void OpSubSup();
218 void Power();
219 void Blank();
220 void Term();
221 void Escape();
222 void Operator();
223 void Oper();
224 void UnOper();
225 void Align();
226 void FontAttribut();
227 void Attribut();
228 void Font();
229 void FontSize();
230 void Color();
231 void Brace();
232 void Bracebody(BOOL bIsLeftRight);
233 void Function();
234 /*N*/ void Binom(); // matrixfett.smf
235 /*N*/ void Stack(); // matrixfett.smf
236 void Matrix();
237 void Special();
238 void GlyphSpecial();
239 // end of grammar
241 LanguageType GetLanguage() const { return nLang; }
242 void SetLanguage( LanguageType nNewLang ) { nLang = nNewLang; }
244 void Error(SmParseError Error);
246 public:
247 SmParser();
249 SmNode *Parse(const String &rBuffer);
251 const String & GetText() const { return BufferString; };
253 SmConvert GetConversion() const { return eConversion; }
254 void SetConversion(SmConvert eConv) { eConversion = eConv; }
256 BOOL IsImportSymbolNames() const { return bImportSymNames; }
257 void SetImportSymbolNames(BOOL bVal) { bImportSymNames = bVal; }
258 BOOL IsExportSymbolNames() const { return bExportSymNames; }
259 void SetExportSymbolNames(BOOL bVal) { bExportSymNames = bVal; }
261 USHORT AddError(SmParseError Type, SmNode *pNode);
266 inline BOOL SmParser::TokenInGroup(ULONG nGroup)
268 return (CurToken.nGroup & nGroup) ? TRUE : FALSE;
272 } //namespace binfilter
273 #endif