wxMaxima
MaximaTokenizer.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) 2014-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // SPDX-License-Identifier: GPL-2.0+
22 
23 #ifndef MAXIMATOKENIZER_H
24 #define MAXIMATOKENIZER_H
25 
26 #include "precomp.h"
27 #include <wx/wx.h>
28 #include <wx/string.h>
29 #include <wx/arrstr.h>
30 #include "TextStyle.h"
31 #include "Configuration.h"
32 #include <vector>
33 #include <memory>
34 
46 {
47 public:
48  MaximaTokenizer(wxString commands, Configuration *configuration);
49 
50  class Token
51  {
52  public:
53  Token() = default;
54  explicit Token(wxString&& text) : m_text(std::move(text)) {}
55  explicit Token(const wxString &text) : m_text(text) {}
56  Token(wxString&& text, TextStyle style) : m_text(std::move(text)), m_style(style) {}
57  Token(const wxString& text, TextStyle style) : m_text(text), m_style(style) {}
58  Token& operator=(Token&& t) { m_text = std::move(t.m_text); m_style = t.m_style; return *this; }
59  Token& operator=(const Token& t) { m_text = t.m_text; m_style = t.m_style; return *this; }
60  Token(Token&& token) { *this = std::move(token); }
61  Token(const Token &token) { *this = token ;}
62  TextStyle GetStyle() const { return m_style; }
63  const wxString &GetText() const { return m_text; }
64  operator const wxString &() const { return m_text; }
65  private:
66  wxString m_text;
67  TextStyle m_style = TS_DEFAULT;
68  };
69  static bool IsAlpha(wxChar ch);
70  static bool IsNum(wxChar ch);
71  static bool IsAlphaNum(wxChar ch);
72  static bool IsSpace(wxChar ch);
73  static const wxString &UnicodeNumbers() { return m_unicodeNumbers; }
74  static const wxString &Operators() { return m_operators; }
75 
76  using TokenList = std::vector<Token>;
77  TokenList PopTokens() && { return std::move(m_tokens); }
78 
80  MaximaTokenizer(wxString commands, Configuration *configuration,
81  const TokenList &initialTokens);
82 
83 protected:
85  TokenList m_tokens;
87  static const wxString m_additional_alphas;
89  static const wxString m_not_alphas;
91  static const wxString m_spaces;
93  static const wxString m_plusSigns;
95  static const wxString m_minusSigns;
97  static const wxString m_linebreaks;
99  static const wxString m_unicodeNumbers;
101  static const wxString m_operators;
102 
103  Configuration *m_configuration;
104 
105  WX_DECLARE_STRING_HASH_MAP(int, StringHash);
113  static StringHash m_hardcodedFunctions;
114 };
115 
116 #endif // MAXIMATOKENIZER_H
TextStyle
TextStyle
Definition: TextStyle.h:307
MaximaTokenizer::m_unicodeNumbers
static const wxString m_unicodeNumbers
Unicode numbers.
Definition: MaximaTokenizer.h:99
MaximaTokenizer
Definition: MaximaTokenizer.h:45
MaximaTokenizer::m_hardcodedFunctions
static StringHash m_hardcodedFunctions
Definition: MaximaTokenizer.h:113
TextStyle.h
MaximaTokenizer::m_linebreaks
static const wxString m_linebreaks
Linebreak characters.
Definition: MaximaTokenizer.h:97
MaximaTokenizer::Token
Definition: MaximaTokenizer.h:50
MaximaTokenizer::m_not_alphas
static const wxString m_not_alphas
Unicode Operators and other special non-ascii characters.
Definition: MaximaTokenizer.h:89
MaximaTokenizer::m_plusSigns
static const wxString m_plusSigns
Plus sign.
Definition: MaximaTokenizer.h:93
MaximaTokenizer::m_operators
static const wxString m_operators
Operators.
Definition: MaximaTokenizer.h:101
MaximaTokenizer::m_spaces
static const wxString m_spaces
Space characters.
Definition: MaximaTokenizer.h:91
MaximaTokenizer::m_tokens
TokenList m_tokens
The tokens the string is divided into.
Definition: MaximaTokenizer.h:85
Configuration
Definition: Configuration.h:83
MaximaTokenizer::m_additional_alphas
static const wxString m_additional_alphas
ASCII symbols that wxIsalnum() doesn't see as chars, but maxima does.
Definition: MaximaTokenizer.h:87
MaximaTokenizer::m_minusSigns
static const wxString m_minusSigns
Minus sign.
Definition: MaximaTokenizer.h:95