/src/libreoffice/starmath/inc/parse5.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | /** Parses the starmath code and creates the nodes. |
21 | | * |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include "parsebase.hxx" |
27 | | #include <unotools/charclass.hxx> |
28 | | |
29 | | class SmParser5 final : public AbstractSmParser |
30 | | { |
31 | | OUString m_aBufferString; |
32 | | SmToken m_aCurToken; |
33 | | ESelection m_aCurESelection; |
34 | | std::vector<SmErrorDesc> m_aErrDescList; |
35 | | int m_nCurError; |
36 | | sal_Int32 m_nBufferIndex, m_nTokenIndex; |
37 | | sal_Int32 m_nRow, // 1-based |
38 | | m_nColOff; // 0-based |
39 | | bool m_bImportSymNames, m_bExportSymNames; |
40 | | sal_Int32 m_nParseDepth; |
41 | | |
42 | | // map of used symbols (used to reduce file size by exporting only actually used symbols) |
43 | | std::set<OUString> m_aUsedSymbols; |
44 | | |
45 | | // CharClass representing a locale for parsing numbers |
46 | | CharClass m_aNumCC; |
47 | | // pointer to System locale's CharClass, which is alive inside SM_MOD() |
48 | | const CharClass* m_pSysCC; |
49 | | |
50 | | SmParser5(const SmParser5&) = delete; |
51 | | SmParser5& operator=(const SmParser5&) = delete; |
52 | | |
53 | | // Moves between tokens inside starmath code. |
54 | | void NextToken(); |
55 | | void NextTokenColor(SmTokenType dvipload); |
56 | | void NextTokenFontSize(); |
57 | 0 | sal_Int32 GetTokenIndex() const { return m_nTokenIndex; } |
58 | | void Replace(sal_Int32 nPos, sal_Int32 nLen, std::u16string_view aText); |
59 | | |
60 | | inline bool TokenInGroup(TG nGroup); |
61 | | |
62 | | // grammar |
63 | | std::unique_ptr<SmTableNode> DoTable(); |
64 | | std::unique_ptr<SmNode> DoLine(); |
65 | | std::unique_ptr<SmNode> DoExpression(bool bUseExtraSpaces = true); |
66 | | std::unique_ptr<SmNode> DoRelation(); |
67 | | std::unique_ptr<SmNode> DoSum(); |
68 | | std::unique_ptr<SmNode> DoProduct(); |
69 | | std::unique_ptr<SmNode> DoSubSup(TG nActiveGroup, std::unique_ptr<SmNode> xGivenNode); |
70 | | std::unique_ptr<SmNode> DoSubSupEvaluate(std::unique_ptr<SmNode> xGivenNode); |
71 | | std::unique_ptr<SmNode> DoOpSubSup(); |
72 | | std::unique_ptr<SmNode> DoPower(); |
73 | | std::unique_ptr<SmBlankNode> DoBlank(); |
74 | | std::unique_ptr<SmNode> DoTerm(bool bGroupNumberIdent); |
75 | | std::unique_ptr<SmNode> DoEscape(); |
76 | | std::unique_ptr<SmOperNode> DoOperator(); |
77 | | std::unique_ptr<SmNode> DoOper(); |
78 | | std::unique_ptr<SmStructureNode> DoUnOper(); |
79 | | std::unique_ptr<SmNode> DoAlign(bool bUseExtraSpaces = true); |
80 | | std::unique_ptr<SmStructureNode> DoFontAttribute(); |
81 | | std::unique_ptr<SmStructureNode> DoAttribute(); |
82 | | std::unique_ptr<SmStructureNode> DoFont(); |
83 | | std::unique_ptr<SmStructureNode> DoFontSize(); |
84 | | std::unique_ptr<SmStructureNode> DoColor(); |
85 | | std::unique_ptr<SmStructureNode> DoBrace(); |
86 | | std::unique_ptr<SmBracebodyNode> DoBracebody(bool bIsLeftRight); |
87 | | std::unique_ptr<SmNode> DoEvaluate(); |
88 | | std::unique_ptr<SmTextNode> DoFunction(); |
89 | | std::unique_ptr<SmTableNode> DoBinom(); |
90 | | std::unique_ptr<SmBinVerNode> DoFrac(); |
91 | | std::unique_ptr<SmStructureNode> DoStack(); |
92 | | std::unique_ptr<SmStructureNode> DoMatrix(); |
93 | | std::unique_ptr<SmSpecialNode> DoSpecial(); |
94 | | std::unique_ptr<SmGlyphSpecialNode> DoGlyphSpecial(); |
95 | | std::unique_ptr<SmExpressionNode> DoError(SmParseError Error); |
96 | | // end of grammar |
97 | | |
98 | | public: |
99 | | SmParser5(); |
100 | | virtual ~SmParser5(); |
101 | | |
102 | | /** Parse rBuffer to formula tree */ |
103 | | std::unique_ptr<SmTableNode> Parse(const OUString& rBuffer); |
104 | | /** Parse rBuffer to formula subtree that constitutes an expression */ |
105 | | std::unique_ptr<SmNode> ParseExpression(const OUString& rBuffer); |
106 | | |
107 | 86 | const OUString& GetText() const { return m_aBufferString; }; |
108 | | |
109 | 1.73k | bool IsImportSymbolNames() const { return m_bImportSymNames; } |
110 | 180 | void SetImportSymbolNames(bool bVal) { m_bImportSymNames = bVal; } |
111 | 818 | bool IsExportSymbolNames() const { return m_bExportSymNames; } |
112 | 0 | void SetExportSymbolNames(bool bVal) { m_bExportSymNames = bVal; } |
113 | | |
114 | | const SmErrorDesc* NextError(); |
115 | | const SmErrorDesc* PrevError(); |
116 | | const SmErrorDesc* GetError() const; |
117 | 110 | const std::set<OUString>& GetUsedSymbols() const { return m_aUsedSymbols; } |
118 | | }; |
119 | | |
120 | 3.57M | inline bool SmParser5::TokenInGroup(TG nGroup) { return bool(m_aCurToken.nGroup & nGroup); } |
121 | | |
122 | | const SmTokenTableEntry* GetTokenTableEntry(const OUString& rName); |
123 | | |
124 | | OUString encloseOrEscapeLiteral(const OUString& string, bool force); |
125 | | |
126 | | inline bool isSingleCharMathOperator(sal_Unicode c) |
127 | 0 | { |
128 | 0 | return c == '+' || c == '-' || c == '*' || c == '/' || c == '=' || c == '<' || c == '>'; |
129 | 0 | } |
130 | | |
131 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |