wxMaxima
Loading...
Searching...
No Matches
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 <utility>
27#include <vector>
28#include <memory>
29#include <wx/wx.h>
30#include <wx/string.h>
31#include <wx/arrstr.h>
32#include "precomp.h"
33#include "cells/TextStyle.h"
34#include "Configuration.h"
35#include <unordered_map>
36
51{
52public:
58 MaximaTokenizer(const wxString &commands, const Configuration * const configuration);
59
61 class Token
62 {
63 public:
64 Token() = default;
65 explicit Token(wxString&& text) : m_text(std::move(text)) {}
66 explicit Token(const wxString &text) : m_text(text) {}
67 Token(wxString&& text, TextStyle style) : m_text(std::move(text)), m_style(style) {}
68 Token(const wxString& text, TextStyle style) : m_text(text), m_style(style) {}
69 Token& operator=(Token&& t) noexcept { m_text = std::move(t.m_text); m_style = t.m_style; return *this; }
70 Token& operator=(const Token& t) { m_text = t.m_text; m_style = t.m_style; return *this; }
71 Token(Token&& token) noexcept { *this = std::move(token); }
72 Token(const Token &token) { *this = token ;}
73 TextStyle GetTextStyle() const { return m_style; }
74 const wxString &GetText() const { return m_text; }
75 operator const wxString &() const { return m_text; }
76 private:
77 wxString m_text;
78 TextStyle m_style = TS_CODE_DEFAULT;
79 };
80 static bool IsAlpha(wxChar ch);
81 static bool IsNum(wxChar ch);
82 static bool IsAlphaNum(wxChar ch);
83 static bool IsSpace(wxChar ch);
84 static const wxString &UnicodeNumbers() { return m_unicodeNumbers; }
85 static const wxString &Operators() { return m_operators; }
86
87 using TokenList = std::vector<Token>;
88 TokenList PopTokens() && { return std::move(m_tokens); }
89
91 MaximaTokenizer(const wxString &commands, const Configuration * const configuration,
92 const TokenList &initialTokens);
93
94protected:
96 TokenList m_tokens;
98 static const wxString m_additional_alphas;
100 static const wxString m_not_alphas;
102 static const wxString m_spaces;
104 static const wxString m_plusSigns;
106 static const wxString m_minusSigns;
108 static const wxString m_linebreaks;
110 static const wxString m_unicodeNumbers;
112 static const wxString m_operators;
113
114 const Configuration * const m_configuration = NULL;
115
116 typedef std::unordered_map <wxString, int, wxStringHash> StringHash;
124 static StringHash m_hardcodedFunctions;
125};
126
127#endif // MAXIMATOKENIZER_H
This file declares everything needed for the text style system used to style all the elements on the ...
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:231
The configuration storage for the current worksheet.
Definition: Configuration.h:85
A maxima code snippet from this tokenizer.
Definition: MaximaTokenizer.h:62
Maximatokenizer breaks down maxima input to individual commands.
Definition: MaximaTokenizer.h:51
static const wxString m_plusSigns
Plus sign.
Definition: MaximaTokenizer.h:104
static StringHash m_hardcodedFunctions
Names of functions that don't require parenthesis.
Definition: MaximaTokenizer.h:124
static const wxString m_not_alphas
Unicode Operators and other special non-ascii characters.
Definition: MaximaTokenizer.h:100
static const wxString m_unicodeNumbers
Unicode numbers.
Definition: MaximaTokenizer.h:110
static const wxString m_spaces
Space characters.
Definition: MaximaTokenizer.h:102
static const wxString m_operators
Operators.
Definition: MaximaTokenizer.h:112
static const wxString m_minusSigns
Minus sign.
Definition: MaximaTokenizer.h:106
TokenList m_tokens
The tokens the string is divided into.
Definition: MaximaTokenizer.h:96
static const wxString m_additional_alphas
ASCII symbols that wxIsalnum() doesn't see as chars, but maxima does.
Definition: MaximaTokenizer.h:98
static const wxString m_linebreaks
Linebreak characters.
Definition: MaximaTokenizer.h:108