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 .
20 /** The tokens contain the information gathered by the parser.
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.
32 #include <rtl/ustrbuf.hxx>
33 #include <tools/color.hxx>
34 #include <o3tl/typed_flags_set.hxx>
63 Standalone
= 0x004000,
70 template <> struct typed_flags
<TG
> : is_typed_flags
<TG
, 0x037fff>
75 // Tokens identifiers. Allow to know what kind of information the node contains.
80 TEND
, TSPECIAL
, TNONE
, TESCAPE
, TUNKNOWN
,
81 TBLANK
, TSBLANK
, TPLACE
, TNOSPACE
, TDOTSDOWN
,
82 TNEWLINE
, TDOTSAXIS
, TDOTSLOW
, TDOTSVERT
, TBACKEPSILON
,
83 TDOTSDIAG
, TDOTSUP
, TERROR
,
85 TPLUS
, TMINUS
, TMULTIPLY
, TDIVIDEBY
, // +-*/
86 TGT
, TLT
, TGE
, TLE
, // > < >= <=
87 TASSIGN
, TNEQ
, TGG
, TLL
, // = != >>> <<<
88 TPARALLEL
, TORTHO
, TEQUIV
, // Geometry
89 TOPER
, TSUM
, TPROD
, TCOPROD
, // Operators
90 TIM
, TRE
, THBAR
, TLAMBDABAR
, // Complex and constants
91 TPLUSMINUS
, TMINUSPLUS
, TSIM
, TSIMEQ
, // +- -+ ~ ~=
92 TLIM
, TLIMSUP
, TLIMINF
, TTOWARD
, // Limits
93 TOVER
, TTIMES
, TCDOT
, TDIV
, // Product type
94 TSLASH
, TBACKSLASH
, TWIDESLASH
, TWIDEBACKSLASH
, //Slash
95 TFRAC
, TIT
, // mathml related
97 TMATRIX
, TPOUND
, TDPOUND
, TSTACK
, TBINOM
,
99 TAND
, TOR
, TNEG
, // && || !
100 TPRECEDES
, TSUCCEEDS
, TNOTPRECEDES
, TNOTSUCCEEDS
, // Order
101 TPRECEDESEQUAL
, TSUCCEEDSEQUAL
, TPRECEDESEQUIV
, TSUCCEEDSEQUIV
, // Order eq
102 TLEFTARROW
, TRIGHTARROW
, TUPARROW
, TDOWNARROW
, // Arrows
103 TDRARROW
, TDLARROW
, TDLRARROW
, TDEF
, // Double arrows, definition
104 TPROP
, TNDIVIDES
, TDIVIDES
, TAPPROX
, // Proportions, approximation
105 TLESLANT
, TGESLANT
, TTRANSL
, TTRANSR
, // <= >= corresponds
107 TOPLUS
, TOMINUS
, TOTIMES
, TODIVIDE
, TODOT
,
110 TRSUB
, TRSUP
, TCSUB
, TCSUP
, TLSUB
,
111 TLSUP
, TFROM
, TTO
, TUOPER
, TBOPER
,
113 TSETN
, TSETZ
, TSETQ
, TSETR
, TSETC
,
114 TIN
, TNOTIN
, TNI
, TEMPTYSET
, // Insideout
115 TSUBSET
, TSUBSETEQ
, TSUPSET
, TSUPSETEQ
, // Subsupset
116 TNSUBSET
, TNSUPSET
, TNSUBSETEQ
, TNSUPSETEQ
, // Not subsupset
117 TINTERSECT
, TUNION
, TSETMINUS
, TSETQUOTIENT
, // +-/
118 TALEPH
, TWP
, TINFINITY
, // Abstract sets
119 TFORALL
, TEXISTS
, TNOTEXISTS
, // Existential
121 TFONT
, TSIZE
, TCOLOR
, TPHANTOM
, // Basic
122 TITALIC
, TNITALIC
, TBOLD
, TNBOLD
, // Bold ital
123 TALIGNL
, TALIGNC
, TALIGNR
, // Align
124 TUNDERLINE
, TOVERLINE
, TOVERSTRIKE
, TBAR
, // Lines
125 TFIXED
, TSANS
, TSERIF
, // Types
126 TACUTE
, TGRAVE
, THAT
, TBREVE
, // Accents
127 TWIDEVEC
, TWIDEHARPOON
, TWIDETILDE
, TWIDEHAT
, // Wide math
128 TVEC
, THARPOON
, TTILDE
, TCIRCLE
, // math
130 TTEXT
, TNUMBER
, TCHARACTER
, TIDENT
, // Content type
132 TLEFT
, TRIGHT
, TUNDERBRACE
, TOVERBRACE
, // Scalable, upsidedown
133 TLGROUP
, TRGROUP
, TLPARENT
, TRPARENT
, // Structural
134 TLBRACKET
, TRBRACKET
, TLDBRACKET
, TRDBRACKET
, // Bracket x1 & x2
135 TLCEIL
, TRCEIL
, TLFLOOR
, TRFLOOR
, // Reals -> Wholes
136 TLANGLE
, TRANGLE
, TLBRACE
, TRBRACE
, // <x> {x}
137 TLLINE
, TRLINE
, TLDLINE
, TRDLINE
, // Lines x1 x2
138 TMLINE
, TEVALUATE
, TLRLINE
, TLRDLINE
, // Custom
139 // Differential calculus
140 TNABLA
, TPARTIAL
, TFOURIER
, TLAPLACE
, // Derivative, Transformation
141 TINTD
, TINT
, TIINT
, TIIINT
, // Integral
142 TLINT
, TLLINT
, TLLLINT
, // Circuit integral
143 TDOT
, TDDOT
, TDDDOT
, // Derivative dots
145 TFUNC
, TLN
, TLOG
, TEXP
, // Exp - Log
146 TSIN
, TCOS
, TTAN
, TCOT
, // Trigo
147 TSINH
, TCOSH
, TTANH
, TCOTH
, // Trigo hyperbolic
148 TASIN
, TACOS
, TATAN
, TACOT
, // Arctrigo
149 TASINH
, TACOSH
, TATANH
, TACOTH
, // Arctrigo hyperbolic
150 TSQRT
, TNROOT
, TFACT
, TABS
, // roots, n! |z|
152 TRGB
, TRGBA
, THEX
, THTMLCOL
, TDVIPSNAMESCOL
,
153 TICONICCOL
, TMATHMLCOL
157 struct SmTokenTableEntry
159 std::u16string_view pIdent
;
161 sal_Unicode cMathChar
;
166 struct SmColorTokenTableEntry
172 SmColorTokenTableEntry()
179 SmColorTokenTableEntry(const SmColorTokenTableEntry
* amColorTokenTableEntry
)
180 : pIdent(amColorTokenTableEntry
->pIdent
)
181 , eType(amColorTokenTableEntry
->eType
)
182 , cColor(amColorTokenTableEntry
->cColor
)
186 SmColorTokenTableEntry(const std::unique_ptr
<SmColorTokenTableEntry
> amColorTokenTableEntry
)
187 : pIdent(amColorTokenTableEntry
->pIdent
)
188 , eType(amColorTokenTableEntry
->eType
)
189 , cColor(amColorTokenTableEntry
->cColor
)
193 SmColorTokenTableEntry(const char* name
, SmTokenType ctype
, Color ncolor
)
200 SmColorTokenTableEntry(const char* name
, SmTokenType ctype
, sal_uInt32 ncolor
)
203 , cColor(ColorTransparency
, ncolor
)
207 bool equals(const OUString
& colorname
) const
209 return colorname
.compareToIgnoreAsciiCaseAscii(pIdent
) == 0;
212 bool equals(sal_uInt32 colorcode
) const { return colorcode
== static_cast<sal_uInt32
>(cColor
); }
214 bool equals(Color colorcode
) const { return colorcode
== cColor
; }
219 OUString aText
; // token text
220 SmTokenType eType
; // token info
235 SmToken(SmTokenType eTokenType
, sal_Unicode cMath
, const char* pText
, TG nTokenGroup
= TG::NONE
,
236 sal_uInt16 nTokenLevel
= 0)
237 : aText(OUString::createFromAscii(pText
))
240 , nGroup(nTokenGroup
)
241 , nLevel(nTokenLevel
)
245 void operator=(const SmTokenTableEntry
& aTokenTableEntry
)
247 aText
= aTokenTableEntry
.pIdent
;
248 eType
= aTokenTableEntry
.eType
;
249 cMathChar
= OUString(&aTokenTableEntry
.cMathChar
, 1);
250 nGroup
= aTokenTableEntry
.nGroup
;
251 nLevel
= aTokenTableEntry
.nLevel
;
254 void operator=(const SmTokenTableEntry
* aTokenTableEntry
)
256 aText
= aTokenTableEntry
->pIdent
;
257 eType
= aTokenTableEntry
->eType
;
258 cMathChar
= OUString(&aTokenTableEntry
->cMathChar
, 1);
259 nGroup
= aTokenTableEntry
->nGroup
;
260 nLevel
= aTokenTableEntry
->nLevel
;
263 void operator=(const SmColorTokenTableEntry
& aTokenTableEntry
)
266 eType
= aTokenTableEntry
.eType
;
267 cMathChar
= OUString::number(static_cast<sal_uInt32
>(aTokenTableEntry
.cColor
), 16);
272 void operator=(const SmColorTokenTableEntry
* aTokenTableEntry
)
275 eType
= aTokenTableEntry
->eType
;
276 cMathChar
= OUString::number(static_cast<sal_uInt32
>(aTokenTableEntry
->cColor
), 16);
281 void operator=(const std::unique_ptr
<SmColorTokenTableEntry
>& aTokenTableEntry
)
284 eType
= aTokenTableEntry
->eType
;
285 cMathChar
= OUString::number(static_cast<sal_uInt32
>(aTokenTableEntry
->cColor
), 16);
290 void setChar(sal_Unicode cChar
) { cMathChar
= OUString(&cChar
, 1); }
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */