wxMaxima
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 "precomp.h"
33 #include <wx/xml/xml.h>
34 
35 #include <wx/filesys.h>
36 #include <wx/fs_arc.h>
37 #include <wx/regex.h>
38 #include <wx/hashmap.h>
39 #include "Cell.h"
40 #include "TextCell.h"
41 #include "EditorCell.h"
42 #include "FracCell.h"
43 #include "GroupCell.h"
44 
51 {
52 public:
58  explicit MathParser(Configuration **cfg, const wxString &zipfile = {});
60  MathParser(const MathParser&) = delete;
62  MathParser& operator=(const MathParser&) = delete;
63  ~MathParser();
64 
65  void SetUserLabel(wxString label){ m_userDefinedLabel = label; }
66  /***
67  * Parse the string s, which is (correct) xml fragment.
68  * Put the result in line.
69  */
70  std::unique_ptr<Cell> ParseLine(wxString s, CellType style = MC_TYPE_DEFAULT);
71  /***
72  * Parse the node and return the corresponding tag.
73  */
74 
75  std::unique_ptr<Cell> ParseTag(wxXmlNode *node, bool all = true);
76  std::unique_ptr<Cell> ParseRowTag(wxXmlNode *node);
77 
79  void SetGroup(GroupCell *group) { m_group = group; }
80 
81 private:
83  using MathCellFunc = std::unique_ptr<Cell> (MathParser::*)(wxXmlNode *node);
84  WX_DECLARE_STRING_HASH_MAP(MathCellFunc, MathCellFunctionHash);
85 
87  using GroupCellFunc = std::unique_ptr<GroupCell> (MathParser::*)(wxXmlNode *node);
88  WX_DECLARE_STRING_HASH_MAP(GroupCellFunc, GroupCellFunctionHash);
89 
91  static MathCellFunctionHash m_innerTags;
93  static GroupCellFunctionHash m_groupTags;
94 
96  static void ParseCommonAttrs(wxXmlNode *node, Cell *cell);
97  template <typename T>
98  static void ParseCommonAttrs(wxXmlNode *node, const std::unique_ptr<T> &cell)
99  { ParseCommonAttrs(node, cell.get()); }
100 
102  static void ParseCommonGroupCellAttrs(wxXmlNode *node, const std::unique_ptr<GroupCell> &group);
103 
105  std::unique_ptr<Cell> HandleNullPointer(std::unique_ptr<Cell> &&cell);
106 
119  wxXmlNode *GetNextTag(wxXmlNode *node);
120 
122  int CountChildren(wxXmlNode *node);
123 
129  wxXmlNode *SkipWhitespaceNode(wxXmlNode *node);
130 
142  std::unique_ptr<Cell> ParseCellTag(wxXmlNode *node);
144  std::unique_ptr<GroupCell> GroupCellFromCodeTag(wxXmlNode *node);
146  std::unique_ptr<GroupCell> GroupCellFromImageTag(wxXmlNode *node);
148  std::unique_ptr<GroupCell> GroupCellFromTitleTag(wxXmlNode *WXUNUSED(node));
150  std::unique_ptr<GroupCell> GroupCellFromSectionTag(wxXmlNode *WXUNUSED(node));
152  std::unique_ptr<GroupCell> GroupCellFromPagebreakTag(wxXmlNode *WXUNUSED(node));
154  std::unique_ptr<GroupCell> GroupCellFromSubsectionTag(wxXmlNode *node);
156  std::unique_ptr<GroupCell> GroupCellFromSubsubsectionTag(wxXmlNode *WXUNUSED(node));
158  std::unique_ptr<GroupCell> GroupCellHeading5Tag(wxXmlNode *WXUNUSED(node));
160  std::unique_ptr<GroupCell> GroupCellHeading6Tag(wxXmlNode *WXUNUSED(node));
162  std::unique_ptr<GroupCell> GroupCellFromTextTag(wxXmlNode *WXUNUSED(node));
163  /* @} */
164 
168  std::unique_ptr<Cell> ParseEditorTag(wxXmlNode *node);
171  std::unique_ptr<Cell> ParseFracTag(wxXmlNode *node);
173  std::unique_ptr<Cell> ParseText(wxXmlNode *node, TextStyle style = TS_DEFAULT);
175  std::unique_ptr<Cell> ParseVariableNameTag(wxXmlNode *node){return ParseText(node->GetChildren(), TS_VARIABLE);}
177  std::unique_ptr<Cell> ParseOperatorNameTag(wxXmlNode *node){return ParseText(node->GetChildren(), TS_FUNCTION);}
179  std::unique_ptr<Cell> ParseMiscTextTag(wxXmlNode *node);
181  std::unique_ptr<Cell> ParseNumberTag(wxXmlNode *node){return ParseText(node->GetChildren(), TS_NUMBER);}
183  std::unique_ptr<Cell> ParseHiddenOperatorTag(wxXmlNode *node);
185  std::unique_ptr<Cell> ParseGreekTag(wxXmlNode *node){return ParseText(node->GetChildren(), TS_GREEK_CONSTANT);}
187  std::unique_ptr<Cell> ParseSpecialConstantTag(wxXmlNode *node){return ParseText(node->GetChildren(), TS_SPECIAL_CONSTANT);}
189  std::unique_ptr<Cell> ParseFunctionNameTag(wxXmlNode *node){return ParseText(node->GetChildren(), TS_FUNCTION);}
191  std::unique_ptr<Cell> ParseSpaceTag(wxXmlNode *WXUNUSED(node)){return std::make_unique<TextCell>(m_group, m_configuration, wxT(" "));}
196  std::unique_ptr<Cell> ParseMthTag(wxXmlNode *node);
198  std::unique_ptr<Cell> ParseOutputLabelTag(wxXmlNode *node);
200  std::unique_ptr<Cell> ParseStringTag(wxXmlNode *node);
202  std::unique_ptr<Cell> ParseHighlightTag(wxXmlNode *node);
204  std::unique_ptr<Cell> ParseImageTag(wxXmlNode *node);
206  std::unique_ptr<Cell> ParseAnimationTag(wxXmlNode *node);
208  std::unique_ptr<Cell> ParseCharCode(wxXmlNode *node);
210  std::unique_ptr<Cell> ParseSupTag(wxXmlNode *node);
212  std::unique_ptr<Cell> ParseSubTag(wxXmlNode *node);
214  std::unique_ptr<Cell> ParseAbsTag(wxXmlNode *node);
216  std::unique_ptr<Cell> ParseConjugateTag(wxXmlNode *node);
217 #if 0
218  std::unique_ptr<Cell> ParseUnderTag(wxXmlNode *node);
220 #endif
221  std::unique_ptr<Cell> ParseTableTag(wxXmlNode *node);
224  std::unique_ptr<Cell> ParseAtTag(wxXmlNode *node);
226  std::unique_ptr<Cell> ParseDiffTag(wxXmlNode *node);
228  std::unique_ptr<Cell> ParseSumTag(wxXmlNode *node);
230  std::unique_ptr<Cell> ParseIntTag(wxXmlNode *node);
232  std::unique_ptr<Cell> ParseFunTag(wxXmlNode *node);
234  std::unique_ptr<Cell> ParseSqrtTag(wxXmlNode *node);
236  std::unique_ptr<Cell> ParseLimitTag(wxXmlNode *node);
238  std::unique_ptr<Cell> ParseParenTag(wxXmlNode *node);
240  std::unique_ptr<Cell> ParseSubSupTag(wxXmlNode *node);
242  std::unique_ptr<Cell> ParseMmultiscriptsTag(wxXmlNode *node);
244  std::unique_ptr<Cell> ParseOutputTag(wxXmlNode *node);
246  std::unique_ptr<Cell> ParseMtdTag(wxXmlNode *node);
247  // @}
249  wxString m_userDefinedLabel;
251  static wxRegEx m_graphRegex;
252 
253  CellType m_ParserStyle;
254  FracCell::FracType m_FracStyle;
255  CellPtr<GroupCell> m_group;
256  Configuration **m_configuration;
257  bool m_highlight;
258  std::shared_ptr<wxFileSystem> m_fileSystem; // used for loading pictures in <img> and <slide>
259  static wxString m_unknownXMLTagToolTip;
260 };
261 
262 #endif // MATHPARSER_H
CellPtr< GroupCell >
MathParser::MathParser
MathParser(Configuration **cfg, const wxString &zipfile={})
Definition: MathParser.cpp:91
Cell.h
TextStyle
TextStyle
Definition: TextStyle.h:307
GroupCell.h
FracCell.h
MathParser::SetGroup
void SetGroup(GroupCell *group)
Sets the group the newly parsed cells are provided with.
Definition: MathParser.h:79
FracCell::FracType
FracType
All types of fractions we support.
Definition: FracCell.h:57
Cell
Definition: Cell.h:139
MathParser::operator=
MathParser & operator=(const MathParser &)=delete
This class doesn't have a = operator.
CellType
CellType
Definition: Cell.h:63
Configuration
Definition: Configuration.h:83
MathParser
Definition: MathParser.h:50
EditorCell.h
GroupCell
Definition: GroupCell.h:68