merge the formfield patch from ooo-build
[ooovba.git] / starmath / inc / parse.hxx
blobcf4758fe8c13b3eeee97316351b9131b6e3267cf
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 #include <vcl/svapp.hxx>
35 #include <tools/stack.hxx>
36 #include <tools/list.hxx>
37 #include <tools/string.hxx>
39 #include "types.hxx"
41 class SmNode;
42 class SmDocShell;
45 // TokenGroups
46 #define TGOPER 0x00000001
47 #define TGRELATION 0x00000002
48 #define TGSUM 0x00000004
49 #define TGPRODUCT 0x00000008
50 #define TGUNOPER 0x00000010
51 #define TGPOWER 0x00000020
52 #define TGATTRIBUT 0x00000040
53 #define TGALIGN 0x00000080
54 #define TGFUNCTION 0x00000100
55 #define TGBLANK 0x00000200
56 #define TGLBRACES 0x00000400
57 #define TGRBRACES 0x00000800
58 #define TGCOLOR 0x00001000
59 #define TGFONT 0x00002000
60 #define TGSTANDALONE 0x00004000
61 #define TGDISCARDED 0x00008000
62 #define TGLIMIT 0x00010000
63 #define TGFONTATTR 0x00020000
66 enum SmTokenType
68 TEND, TLGROUP, TRGROUP, TLPARENT, TRPARENT,
69 TLBRACKET, TRBRACKET, TPLUS, TMINUS, TMULTIPLY,
70 TDIVIDEBY, TASSIGN, TPOUND, TSPECIAL, TSLASH,
71 TBACKSLASH, TBLANK, TSBLANK, TRSUB, TRSUP,
72 TCSUB, TCSUP, TLSUB, TLSUP, TGT,
73 TLT, TAND, TOR, TINTERSECT, TUNION,
74 TNEWLINE, TBINOM, TFROM, TTO, TINT,
75 TSUM, TOPER, TABS, TSQRT, TFACT,
76 TNROOT, TOVER, TTIMES, TGE, TLE,
77 TGG, TLL, TDOTSAXIS, TDOTSLOW, TDOTSVERT,
78 TDOTSDIAG, TDOTSUP, TDOTSDOWN, TACUTE, TBAR,
79 TBREVE, TCHECK, TCIRCLE, TDOT, TDDOT,
80 TDDDOT, TGRAVE, THAT, TTILDE, TVEC,
81 TUNDERLINE, TOVERLINE, TOVERSTRIKE, TITALIC, TNITALIC,
82 TBOLD, TNBOLD, TPHANTOM, TFONT, TSIZE,
83 TCOLOR, TALIGNL, TALIGNC, TALIGNR, TLEFT,
84 TRIGHT, TLANGLE, TLBRACE, TLLINE, TLDLINE,
85 TLCEIL, TLFLOOR, TNONE, TMLINE, TRANGLE,
86 TRBRACE, TRLINE, TRDLINE, TRCEIL, TRFLOOR,
87 TSIN, TCOS, TTAN, TCOT, TFUNC,
88 TSTACK, TMATRIX, TMATFORM, TDPOUND, TPLACE,
89 TTEXT, TNUMBER, TCHARACTER, TIDENT, TNEQ,
90 TEQUIV, TDEF, TPROP, TSIM, TSIMEQ,
91 TAPPROX, TPARALLEL, TORTHO, TIN, TNOTIN,
92 TSUBSET, TSUBSETEQ, TSUPSET, TSUPSETEQ, TPLUSMINUS,
93 TMINUSPLUS, TOPLUS, TOMINUS, TDIV, TOTIMES,
94 TODIVIDE, TTRANSL, TTRANSR, TIINT, TIIINT,
95 TLINT, TLLINT, TLLLINT, TPROD, TCOPROD,
96 TFORALL, TEXISTS, TLIM, TNABLA, TTOWARD,
97 TSINH, TCOSH, TTANH, TCOTH, TASIN,
98 TACOS, TATAN, TLN, TLOG, TUOPER,
99 TBOPER, TBLACK, TWHITE, TRED, TGREEN,
100 TBLUE, TCYAN, TMAGENTA, TYELLOW, TFIXED,
101 TSANS, TSERIF, TPOINT, TASINH, TACOSH,
102 TATANH, TACOTH, TACOT, TEXP, TCDOT,
103 TODOT, TLESLANT, TGESLANT, TNSUBSET, TNSUPSET,
104 TNSUBSETEQ, TNSUPSETEQ, TPARTIAL, TNEG, TNI,
105 TBACKEPSILON, TALEPH, TIM, TRE, TWP,
106 TEMPTYSET, TINFINITY, TESCAPE, TLIMSUP, TLIMINF,
107 TNDIVIDES, TDRARROW, TDLARROW, TDLRARROW, TUNDERBRACE,
108 TOVERBRACE, TCIRC, TTOP, THBAR, TLAMBDABAR,
109 TLEFTARROW, TRIGHTARROW, TUPARROW, TDOWNARROW, TDIVIDES,
110 TNDIBVIDES, TSETN, TSETZ, TSETQ, TSETR,
111 TSETC, TWIDEVEC, TWIDETILDE, TWIDEHAT, TWIDESLASH,
112 TWIDEBACKSLASH, TLDBRACKET, TRDBRACKET,
113 TUNKNOWN, TDEBUG
117 struct SmToken
119 // token text
120 String aText;
121 // token info
122 SmTokenType eType;
123 sal_Unicode cMathChar;
124 // parse-help info
125 ULONG nGroup;
126 USHORT nLevel;
127 // token position
128 USHORT nRow;
129 xub_StrLen nCol;
131 SmToken();
135 enum SmParseError
137 PE_NONE, PE_UNEXPECTED_END_OF_INPUT,
138 PE_UNEXPECTED_CHAR, PE_UNEXPECTED_TOKEN,
139 PE_FUNC_EXPECTED, PE_UNOPER_EXPECTED,
140 PE_BINOPER_EXPECTED, PE_SYMBOL_EXPECTED,
141 PE_IDENTIFIER_EXPECTED, PE_POUND_EXPECTED,
142 PE_COLOR_EXPECTED, PE_LGROUP_EXPECTED,
143 PE_RGROUP_EXPECTED, PE_LBRACE_EXPECTED,
144 PE_RBRACE_EXPECTED, PE_PARENT_MISMATCH,
145 PE_RIGHT_EXPECTED, PE_FONT_EXPECTED,
146 PE_SIZE_EXPECTED, PE_DOUBLE_ALIGN,
147 PE_DOUBLE_SUBSUPSCRIPT
151 struct SmErrorDesc
153 SmParseError Type;
154 SmNode *pNode;
155 String Text;
158 DECLARE_STACK(SmNodeStack, SmNode *)
159 DECLARE_LIST(SmErrDescList, SmErrorDesc *)
161 /**************************************************************************/
163 // defines possible conversions of the formula text from the format of
164 // one release to the one of another.
165 enum SmConvert
167 CONVERT_NONE,
168 CONVERT_40_TO_50,
169 CONVERT_50_TO_60,
170 CONVERT_60_TO_50
174 class SmParser
176 String BufferString;
177 SmToken CurToken;
178 SmNodeStack NodeStack;
179 SmErrDescList ErrDescList;
180 int CurError;
181 LanguageType nLang;
182 xub_StrLen BufferIndex,
183 nTokenIndex;
184 USHORT Row,
185 ColOff;
186 SmConvert eConversion;
187 BOOL bImportSymNames,
188 bExportSymNames;
190 // declare copy-constructor and assignment-operator private
191 SmParser(const SmParser &);
192 SmParser & operator = (const SmParser &);
194 protected:
195 #if OSL_DEBUG_LEVEL
196 BOOL IsDelimiter( const String &rTxt, xub_StrLen nPos );
197 #endif
198 void NextToken();
199 xub_StrLen GetTokenIndex() const { return nTokenIndex; }
200 void Insert(const String &rText, USHORT nPos);
201 void Replace( USHORT nPos, USHORT nLen, const String &rText );
203 inline BOOL TokenInGroup(ULONG nGroup);
205 // grammar
206 void Table();
207 void Line();
208 void Expression();
209 void Relation();
210 void Sum();
211 void Product();
212 void SubSup(ULONG nActiveGroup);
213 void OpSubSup();
214 void Power();
215 void Blank();
216 void Term();
217 void Escape();
218 void Operator();
219 void Oper();
220 void UnOper();
221 void Align();
222 void FontAttribut();
223 void Attribut();
224 void Font();
225 void FontSize();
226 void Color();
227 void Brace();
228 void Bracebody(BOOL bIsLeftRight);
229 void Function();
230 void Binom();
231 void Stack();
232 void Matrix();
233 void Special();
234 void GlyphSpecial();
235 // end of grammar
237 LanguageType GetLanguage() const { return nLang; }
238 void SetLanguage( LanguageType nNewLang ) { nLang = nNewLang; }
240 void Error(SmParseError Error);
242 public:
243 SmParser();
245 SmNode *Parse(const String &rBuffer);
247 const String & GetText() const { return BufferString; };
249 SmConvert GetConversion() const { return eConversion; }
250 void SetConversion(SmConvert eConv) { eConversion = eConv; }
252 BOOL IsImportSymbolNames() const { return bImportSymNames; }
253 void SetImportSymbolNames(BOOL bVal) { bImportSymNames = bVal; }
254 BOOL IsExportSymbolNames() const { return bExportSymNames; }
255 void SetExportSymbolNames(BOOL bVal) { bExportSymNames = bVal; }
257 USHORT AddError(SmParseError Type, SmNode *pNode);
259 const SmErrorDesc * NextError();
260 const SmErrorDesc * PrevError();
261 const SmErrorDesc * GetError(USHORT i = 0xFFFF);
265 inline BOOL SmParser::TokenInGroup(ULONG nGroup)
267 return (CurToken.nGroup & nGroup) ? TRUE : FALSE;
271 #endif