OpenStructure
Loading...
Searching...
No Matches
python_tokenizer.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of the OpenStructure project <www.openstructure.org>
3//
4// Copyright (C) 2008-2020 by the OpenStructure authors
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License as published by the Free
8// Software Foundation; either version 3.0 of the License, or (at your option)
9// any later version.
10// This library is distributed in the hope that it will be useful, but WITHOUT
11// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this library; if not, write to the Free Software Foundation, Inc.,
17// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18//------------------------------------------------------------------------------
19#ifndef PYTHON_TOKENIZER_HH
20#define PYTHON_TOKENIZER_HH
21
22/*
23 Author: Marco Biasini
24*/
25
26
28#include <QString>
29
30namespace ost { namespace gui {
31
33{
34 size_t location, length;
35
36 Range(size_t loc, size_t len):
37 location(loc),
38 length(len)
39 {
40 }
41
43 location(-1),
44 length(0)
45 {
46 }
47
48 size_t End() const
49 {
50 return location+length;
51 }
52};
53
55{
56public:
69 PythonToken(Type type,const Range& range, const QString& value);
70 Type GetType() const;
71 QString GetTypeAsString() const;
72 const QString& GetValue() const;
73 const Range& GetRange() const;
74
75private:
76 Type type_;
77 Range range_;
78 QString value_;
79};
80
82{
83public:
85 PythonTokenizer(const QString& command, int string_state=0);
86 void SetCommand(const QString& command);
88 const PythonToken& CurrentToken() const;
89 void SetInString(bool in_string);
90 bool InString() const { return in_string_; }
91 const QString& GetDelim() const { return string_delim_; }
92private:
93 void EatWhities();
94 QString GetSubString(const Range& range);
95 PythonToken GetIdentifierSeq();
96 PythonToken GetNumberToken();
97 PythonToken GetKeywordToken();
98 PythonToken GetOperatorToken();
99 PythonToken GetGroupingToken();
100 PythonToken GetStringLiteral();
101 PythonToken GetStringDelim();
102 QString command_;
103 int current_pos_;
104 bool in_string_;
105 QString string_delim_;
106 PythonToken current_token_;
107};
108
109
110}}
111
112#endif
const Range & GetRange() const
QString GetTypeAsString() const
Type GetType() const
PythonToken(Type type, const Range &range, const QString &value)
const QString & GetValue() const
const QString & GetDelim() const
const PythonToken & CurrentToken() const
void SetInString(bool in_string)
PythonTokenizer(const QString &command, int string_state=0)
void SetCommand(const QString &command)
#define DLLEXPORT_OST_GUI
Definition base.dox:1
Range(size_t loc, size_t len)
size_t End() const