crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / starmath / inc / token.hxx
blob00ffbc026d20040cccdeb31b512779a330536e7a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 /** The tokens contain the information gathered by the parser.
22 * They contain:
23 * the data type (~ mathematical operation).
24 * The mathematical char.
25 * The corresponding code or information to recreate it.
26 * Location of the token in the starmath code.
29 #pragma once
31 #include <tools/color.hxx>
32 #include <o3tl/string_view.hxx>
33 #include <o3tl/typed_flags_set.hxx>
35 // std imports
36 #include <memory>
37 #include <utility>
39 // TokenGroups
40 enum class TG
42 NONE = 0x000000,
43 Oper = 0x000001,
44 Relation = 0x000002,
45 Sum = 0x000004,
46 Product = 0x000008,
47 UnOper = 0x000010,
48 Power = 0x000020,
49 Attribute = 0x000040,
50 Align = 0x000080,
51 Function = 0x000100,
52 Blank = 0x000200,
53 LBrace = 0x000400,
54 RBrace = 0x000800,
55 Color = 0x001000,
56 Font = 0x002000,
57 Standalone = 0x004000,
58 Limit = 0x010000,
59 FontAttr = 0x020000
62 namespace o3tl
64 template <> struct typed_flags<TG> : is_typed_flags<TG, 0x037fff>
69 // Tokens identifiers. Allow to know what kind of information the node contains.
70 enum SmTokenType
72 // clang-format off
73 // Uncategorized
74 TEND, TSPECIAL, TNONE, TESCAPE, TUNKNOWN,
75 TBLANK, TSBLANK, TPLACE, TNOSPACE, TDOTSDOWN,
76 TNEWLINE, TDOTSAXIS, TDOTSLOW, TDOTSVERT, TBACKEPSILON,
77 TDOTSDIAG, TDOTSUP, TERROR,
78 // Basic
79 TPLUS, TMINUS, TMULTIPLY, TDIVIDEBY, // +-*/
80 TGT, TLT, TGE, TLE, // > < >= <=
81 TASSIGN, TNEQ, TGG, TLL, // = != >>> <<<
82 TPARALLEL, TORTHO, TEQUIV, // Geometry
83 TOPER, TSUM, TPROD, TCOPROD, // Operators
84 TIM, TRE, THBAR, TLAMBDABAR, // Complex and constants
85 TPLUSMINUS, TMINUSPLUS, TSIM, TSIMEQ, // +- -+ ~ ~=
86 TLIM, TLIMSUP, TLIMINF, TTOWARD, // Limits
87 THADD, TNAHA,
88 TOVER, TTIMES, TCDOT, TDIV, // Product type
89 TSLASH, TBACKSLASH, TWIDESLASH, TWIDEBACKSLASH, //Slash
90 TFRAC, TIT, // mathml related
91 // Structure
92 TMATRIX, TPOUND, TDPOUND, TSTACK, TBINOM,
93 // Logic
94 TAND, TOR, TNEG, // && || !
95 TPRECEDES, TSUCCEEDS, TNOTPRECEDES, TNOTSUCCEEDS, // Order
96 TPRECEDESEQUAL, TSUCCEEDSEQUAL, TPRECEDESEQUIV, TSUCCEEDSEQUIV, // Order eq
97 TLEFTARROW, TRIGHTARROW, TUPARROW, TDOWNARROW, // Arrows
98 TDRARROW, TDLARROW, TDLRARROW, TDEF, // Double arrows, definition
99 TPROP, TNDIVIDES, TDIVIDES, TAPPROX, // Proportions, approximation
100 TLESLANT, TGESLANT, TTRANSL, TTRANSR, // <= >= corresponds
101 // Tensors
102 TOPLUS, TOMINUS, TOTIMES, TODIVIDE, TODOT,
103 TCIRC,
104 // Positions
105 TRSUB, TRSUP, TCSUB, TCSUP, TLSUB,
106 TLSUP, TFROM, TTO, TUOPER, TBOPER,
107 // Set theory
108 TSETN, TSETZ, TSETQ, TSETR, TSETC,
109 TIN, TNOTIN, TNI, TEMPTYSET, // Insideout
110 TSUBSET, TSUBSETEQ, TSUPSET, TSUPSETEQ, // Subsupset
111 TNSUBSET, TNSUPSET, TNSUBSETEQ, TNSUPSETEQ, // Not subsupset
112 TINTERSECT, TUNION, TSETMINUS, TSETQUOTIENT, // +-/
113 TALEPH, TWP, TINFINITY, // Abstract sets
114 TFORALL, TEXISTS, TNOTEXISTS, // Existential
115 // Font
116 TFONT, TSIZE, TCOLOR, TPHANTOM, // Basic
117 TITALIC, TNITALIC, TBOLD, TNBOLD, // Bold ital
118 TALIGNL, TALIGNC, TALIGNR, // Align
119 TUNDERLINE, TOVERLINE, TOVERSTRIKE, TBAR, // Lines
120 TFIXED, TSANS, TSERIF, // Types
121 TACUTE, TGRAVE, THAT, TBREVE, // Accents
122 TWIDEVEC, TWIDEHARPOON, TWIDETILDE, TWIDEHAT, // Wide math
123 TVEC, THARPOON, TTILDE, TCIRCLE, // math
124 TCHECK,
125 TTEXT, TNUMBER, TCHARACTER, TIDENT, // Content type
126 // Brackets
127 TLEFT, TRIGHT, TUNDERBRACE, TOVERBRACE, // Scalable, upsidedown
128 TLGROUP, TRGROUP, TLPARENT, TRPARENT, // Structural
129 TLBRACKET, TRBRACKET, TLDBRACKET, TRDBRACKET, // Bracket x1 & x2
130 TLCEIL, TRCEIL, TLFLOOR, TRFLOOR, // Reals -> Wholes
131 TLANGLE, TRANGLE, TLBRACE, TRBRACE, // <x> {x}
132 TLLINE, TRLINE, TLDLINE, TRDLINE, // Lines x1 x2
133 TMLINE, TEVALUATE, TLRLINE, TLRDLINE, // Custom
134 // Differential calculus
135 TNABLA, TPARTIAL, TFOURIER, TLAPLACE, // Derivative, Transformation
136 TINTD, TINT, TIINT, TIIINT, // Integral
137 TLINT, TLLINT, TLLLINT, // Circuit integral
138 TDOT, TDDOT, TDDDOT, // Derivative dots
139 // Function
140 TFUNC, TLN, TLOG, TEXP, // Exp - Log
141 TSIN, TCOS, TTAN, TCOT, // Trigo
142 TSEC, TCSC, TSECH, TCSCH,
143 TSINH, TCOSH, TTANH, TCOTH, // Trigo hyperbolic
144 TASIN, TACOS, TATAN, TACOT, // Arctrigo
145 TASINH, TACOSH, TATANH, TACOTH, // Arctrigo hyperbolic
146 TSQRT, TNROOT, TFACT, TABS, // roots, n! |z|
147 // Color
148 TRGB, TRGBA, THEX, THTMLCOL, TDVIPSNAMESCOL,
149 TICONICCOL, TMATHMLCOL
150 // clang-format on
153 struct SmTokenTableEntry
155 OUString aIdent;
156 SmTokenType eType;
157 sal_uInt32 cMathChar;
158 TG nGroup;
159 sal_uInt16 nLevel;
162 struct SmColorTokenTableEntry
164 OUString aIdent;
165 SmTokenType eType;
166 Color cColor;
168 SmColorTokenTableEntry()
169 : eType(TERROR)
170 , cColor()
174 explicit SmColorTokenTableEntry(const SmColorTokenTableEntry* amColorTokenTableEntry)
175 : aIdent(amColorTokenTableEntry->aIdent)
176 , eType(amColorTokenTableEntry->eType)
177 , cColor(amColorTokenTableEntry->cColor)
181 explicit SmColorTokenTableEntry(
182 const std::unique_ptr<SmColorTokenTableEntry> amColorTokenTableEntry)
183 : aIdent(amColorTokenTableEntry->aIdent)
184 , eType(amColorTokenTableEntry->eType)
185 , cColor(amColorTokenTableEntry->cColor)
189 SmColorTokenTableEntry(OUString name, SmTokenType ctype, Color ncolor)
190 : aIdent(std::move(name))
191 , eType(ctype)
192 , cColor(ncolor)
196 SmColorTokenTableEntry(OUString name, SmTokenType ctype, sal_uInt32 ncolor)
197 : aIdent(std::move(name))
198 , eType(ctype)
199 , cColor(ColorTransparency, ncolor)
203 bool equals(std::u16string_view colorname) const
205 return o3tl::compareToIgnoreAsciiCase(colorname, aIdent) == 0;
208 bool equals(sal_uInt32 colorcode) const { return colorcode == static_cast<sal_uInt32>(cColor); }
210 bool equals(Color colorcode) const { return colorcode == cColor; }
213 struct SmToken
215 OUString aText; // token text
216 SmTokenType eType; // token info
217 OUString cMathChar;
219 // parse-help info
220 TG nGroup;
221 sal_uInt16 nLevel;
223 SmToken()
224 : eType(TUNKNOWN)
225 , cMathChar('\0')
226 , nGroup(TG::NONE)
227 , nLevel(0)
231 SmToken(SmTokenType eTokenType, sal_uInt32 cMath, OUString rText, TG nTokenGroup = TG::NONE,
232 sal_uInt16 nTokenLevel = 0)
233 : aText(std::move(rText))
234 , eType(eTokenType)
235 , cMathChar(&cMath, 1)
236 , nGroup(nTokenGroup)
237 , nLevel(nTokenLevel)
241 void operator=(const SmTokenTableEntry& aTokenTableEntry)
243 aText = aTokenTableEntry.aIdent;
244 eType = aTokenTableEntry.eType;
245 cMathChar = OUString(&aTokenTableEntry.cMathChar, 1);
246 nGroup = aTokenTableEntry.nGroup;
247 nLevel = aTokenTableEntry.nLevel;
250 void operator=(const SmTokenTableEntry* aTokenTableEntry)
252 aText = aTokenTableEntry->aIdent;
253 eType = aTokenTableEntry->eType;
254 cMathChar = OUString(&aTokenTableEntry->cMathChar, 1);
255 nGroup = aTokenTableEntry->nGroup;
256 nLevel = aTokenTableEntry->nLevel;
259 void operator=(const SmColorTokenTableEntry& aTokenTableEntry)
261 aText = u""_ustr;
262 eType = aTokenTableEntry.eType;
263 cMathChar = OUString::number(static_cast<sal_uInt32>(aTokenTableEntry.cColor), 16);
264 nGroup = TG::Color;
265 nLevel = 0;
268 void operator=(const SmColorTokenTableEntry* aTokenTableEntry)
270 aText = u""_ustr;
271 eType = aTokenTableEntry->eType;
272 cMathChar = OUString::number(static_cast<sal_uInt32>(aTokenTableEntry->cColor), 16);
273 nGroup = TG::Color;
274 nLevel = 0;
277 void operator=(const std::unique_ptr<SmColorTokenTableEntry>& aTokenTableEntry)
279 aText = u""_ustr;
280 eType = aTokenTableEntry->eType;
281 cMathChar = OUString::number(static_cast<sal_uInt32>(aTokenTableEntry->cColor), 16);
282 nGroup = TG::Color;
283 nLevel = 0;
286 void setChar(sal_uInt32 cChar) { cMathChar = OUString(&cChar, 1); }
287 void setChar(const OUString& rText) { cMathChar = rText; }
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */