wxMaxima
Loading...
Searching...
No Matches
MathParser.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2004-2015 Gunter Königsmann <wxMaxima@physikbuch.de>
5// (C) 2020 Kuba Ober <kuba@bertec.com>
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// SPDX-License-Identifier: GPL-2.0+
23
29#ifndef MATHPARSER_H
30#define MATHPARSER_H
31
32#include <memory>
33#include "precomp.h"
34#include <wx/xml/xml.h>
35
36#include <wx/filesys.h>
37#include <wx/fs_arc.h>
38#include <wx/regex.h>
39#include <wx/hashmap.h>
40#include "cells/Cell.h"
41#include "cells/TextCell.h"
42#include "cells/EditorCell.h"
43#include "cells/FracCell.h"
44#include "cells/GroupCell.h"
45#include "AttachmentSource.h"
46#include <unordered_map>
47#include <unordered_set>
48
55{
56public:
62 explicit MathParser(Configuration *cfg, const wxString &zipfile = {});
68 MathParser(Configuration *cfg, AttachmentSource attachments);
70 MathParser(const MathParser&) = delete;
72 MathParser& operator=(const MathParser&) = delete;
73 virtual ~MathParser();
74
81 void SetUserLabel(const wxString &label){ m_userDefinedLabel = label; }
82 /***
83 * Parse the string s, which is (correct) xml fragment.
84 * Put the result in line.
85 */
86 std::unique_ptr<Cell> ParseLine(wxString s, CellType style = MC_TYPE_DEFAULT);
87 std::unique_ptr<Cell> ParseLine(const wxXmlDocument &xml, CellType style = MC_TYPE_DEFAULT);
88 /***
89 * Parse the node and return the corresponding tag.
90 */
91
92 std::unique_ptr<Cell> ParseTag(wxXmlNode *node, bool all = true, int depth = 0);
93 std::unique_ptr<Cell> ParseRowTag(wxXmlNode *node, int depth = 0);
94
95 std::unique_ptr<GroupCell> CreateTreeFromXMLNode(wxXmlNode *xmlcells);
96
98 void SetGroup(GroupCell *group) { m_group = group; }
99
100private:
102 using MathCellFunc = std::unique_ptr<Cell> (MathParser::*)(wxXmlNode *node, int depth);
103
105 using GroupCellFunc = std::unique_ptr<GroupCell> (MathParser::*)(wxXmlNode *node);
106
107 using MathCellFunctionHash = std::unordered_map<wxString, MathCellFunc, wxStringHash>;
108 using GroupCellFunctionHash = std::unordered_map<wxString, GroupCellFunc, wxStringHash>;
109
111 static MathCellFunctionHash m_innerTags;
113 static GroupCellFunctionHash m_groupTags;
115 static std::unordered_set<wxString, wxStringHash> m_knownAttributes;
116
118 static void ParseCommonAttrs(wxXmlNode *node, Cell *cell);
119 template <typename T>
120 static void ParseCommonAttrs(wxXmlNode *node, const std::unique_ptr<T> &cell)
121 { ParseCommonAttrs(node, cell.get()); }
122
124 static void ParseCommonGroupCellAttrs(wxXmlNode *node, const std::unique_ptr<GroupCell> &group);
125
127 std::unique_ptr<Cell> HandleNullPointer(std::unique_ptr<Cell> &&cell);
128
141 static wxXmlNode *GetNextTag(wxXmlNode *node);
142
144 static int CountChildren(wxXmlNode *node);
145
151 static wxXmlNode *SkipWhitespaceNode(wxXmlNode *node);
152
164 std::unique_ptr<Cell> ParseCellTag(wxXmlNode *node, int depth = 0);
166 std::unique_ptr<GroupCell> GroupCellFromCodeTag(wxXmlNode *node);
168 std::unique_ptr<GroupCell> GroupCellFromImageTag(wxXmlNode *node);
170 std::unique_ptr<GroupCell> GroupCellFromTitleTag(wxXmlNode *WXUNUSED(node));
172 std::unique_ptr<GroupCell> GroupCellFromSectionTag(wxXmlNode *WXUNUSED(node));
174 std::unique_ptr<GroupCell> GroupCellFromPagebreakTag(wxXmlNode *WXUNUSED(node));
176 std::unique_ptr<GroupCell> GroupCellFromSubsectionTag(wxXmlNode *node);
178 std::unique_ptr<GroupCell> GroupCellFromSubsubsectionTag(wxXmlNode *WXUNUSED(node));
180 std::unique_ptr<GroupCell> GroupCellHeading5Tag(wxXmlNode *WXUNUSED(node));
182 std::unique_ptr<GroupCell> GroupCellHeading6Tag(wxXmlNode *WXUNUSED(node));
184 std::unique_ptr<GroupCell> GroupCellFromTextTag(wxXmlNode *WXUNUSED(node));
185 /* @} */
186
191 std::unique_ptr<Cell> ParseEditorTag(wxXmlNode *node, int depth = 0);
193 std::unique_ptr<Cell> ParseFracTag(wxXmlNode *node, int depth = 0);
195 std::unique_ptr<Cell> ParseText(wxXmlNode *node, TextStyle style = TS_MATH, int depth = 0);
200 std::unique_ptr<Cell> ParseVariableNameTag(wxXmlNode *node, int depth = 0);
202 std::unique_ptr<Cell> ParseOperatorNameTag(wxXmlNode *node, int depth = 0){return ParseText(node->GetChildren(), TS_FUNCTION, depth);}
204 std::unique_ptr<Cell> ParseMiscTextTag(wxXmlNode *node, int depth = 0);
206 std::unique_ptr<Cell> ParseNumberTag(wxXmlNode *node, int depth = 0){return ParseText(node->GetChildren(), TS_NUMBER, depth);}
208 std::unique_ptr<Cell> ParseHiddenOperatorTag(wxXmlNode *node, int depth = 0);
210 std::unique_ptr<Cell> ParseGreekTag(wxXmlNode *node, int depth = 0){return ParseText(node->GetChildren(), TS_GREEK_CONSTANT, depth);}
212 std::unique_ptr<Cell> ParseSpecialConstantTag(wxXmlNode *node, int depth = 0){return ParseText(node->GetChildren(), TS_SPECIAL_CONSTANT, depth);}
214 std::unique_ptr<Cell> ParseFunctionNameTag(wxXmlNode *node, int depth = 0){return ParseText(node->GetChildren(), TS_FUNCTION, depth);}
216 std::unique_ptr<Cell> ParseSpaceTag(wxXmlNode *WXUNUSED(node), int WXUNUSED(depth) = 0){return std::make_unique<TextCell>(m_group, m_configuration, wxS(" "));}
221 std::unique_ptr<Cell> ParseMthTag(wxXmlNode *node, int depth = 0);
223 std::unique_ptr<Cell> ParseOutputLabelTag(wxXmlNode *node, int depth = 0);
225 std::unique_ptr<Cell> ParseStringTag(wxXmlNode *node, int depth = 0);
227 std::unique_ptr<Cell> ParseHighlightTag(wxXmlNode *node, int depth = 0);
229 std::unique_ptr<Cell> ParseImageTag(wxXmlNode *node, int depth = 0);
231 std::unique_ptr<Cell> ParseAnimationTag(wxXmlNode *node, int depth = 0);
233 std::unique_ptr<Cell> ParseCharCode(wxXmlNode *node, int depth = 0);
235 std::unique_ptr<Cell> ParseSupTag(wxXmlNode *node, int depth = 0);
237 std::unique_ptr<Cell> ParseSubTag(wxXmlNode *node, int depth = 0);
239 std::unique_ptr<Cell> ParseAbsTag(wxXmlNode *node, int depth = 0);
241 std::unique_ptr<Cell> ParseConjugateTag(wxXmlNode *node, int depth = 0);
242#if 0
244 std::unique_ptr<Cell> ParseUnderTag(wxXmlNode *node, int depth = 0);
245#endif
247 std::unique_ptr<Cell> ParseTableTag(wxXmlNode *node, int depth = 0);
249 std::unique_ptr<Cell> ParseAtTag(wxXmlNode *node, int depth = 0);
251 std::unique_ptr<Cell> ParseDiffTag(wxXmlNode *node, int depth = 0);
253 std::unique_ptr<Cell> ParseSumTag(wxXmlNode *node, int depth = 0);
255 std::unique_ptr<Cell> ParseIntTag(wxXmlNode *node, int depth = 0);
257 std::unique_ptr<Cell> ParseFunTag(wxXmlNode *node, int depth = 0);
259 std::unique_ptr<Cell> ParseSqrtTag(wxXmlNode *node, int depth = 0);
261 std::unique_ptr<Cell> ParseLimitTag(wxXmlNode *node, int depth = 0);
263 std::unique_ptr<Cell> ParseParenTag(wxXmlNode *node, int depth = 0);
265 std::unique_ptr<Cell> ParseSubSupTag(wxXmlNode *node, int depth = 0);
267 std::unique_ptr<Cell> ParseMmultiscriptsTag(wxXmlNode *node, int depth = 0);
269 std::unique_ptr<Cell> ParseOutputTag(wxXmlNode *node, int depth = 0);
271 std::unique_ptr<Cell> ParseMtdTag(wxXmlNode *node, int depth = 0);
272 // @}
274 wxString m_userDefinedLabel;
276 static wxRegEx m_graphRegex;
277
278 CellType m_ParserStyle = MC_TYPE_DEFAULT;
279 FracCell::FracType m_FracStyle;
280 CellPtr<GroupCell> m_group;
281 Configuration *m_configuration = nullptr;
282 bool m_highlight = false;
284 AttachmentSource m_attachments;
285 static wxString m_unknownXMLTagToolTip;
286};
287
288#endif // MATHPARSER_H
Where the files a worksheet's XML refers to (images, gnuplot sources and data) can be read from.
The definition of the base class of all cells the worksheet consists of.
CellType
The supported types of math cells.
Definition: Cell.h:64
This file contains the definition of the class EditorCell.
This file declares the class FracCell.
This file defines the class GroupCell that bundles input and output in the worksheet.
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:230
int group
Neighbouring sections of the same group aren't separated.
Definition: ToolBarSections.cpp:45
The files a worksheet's XML refers to by name.
Definition: AttachmentSource.h:49
A weak non-owning pointer that becomes null whenever the observed object is destroyed.
Definition: CellPtr.h:539
The base class all cell types the worksheet can consist of are derived from.
Definition: Cell.h:148
The configuration storage for the current worksheet.
Definition: Configuration.h:101
FracType
All types of fractions we support.
Definition: FracCell.h:80
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
This class handles parsing the xml representation of a cell tree.
Definition: MathParser.h:55
void SetUserLabel(const wxString &label)
Tells the parser what user label to assign to the next label cell.
Definition: MathParser.h:81
MathParser & operator=(const MathParser &)=delete
This class doesn't have a = operator.
MathParser(const MathParser &)=delete
This class doesn't have a copy constructor.
void SetGroup(GroupCell *group)
Sets the group the newly parsed cells are provided with.
Definition: MathParser.h:98