Libksieve

impl/parser.h
1 /* -*- c++ -*-
2  impl/parser.h
3 
4  Internal header file. Subject to change without notice. DO NOT USE.
5 
6  This file is part of KSieve,
7  the KDE internet mail/usenet news message filtering library.
8  Copyright (c) 2003 Marc Mutz <[email protected]>
9 
10  KSieve is free software; you can redistribute it and/or modify it
11  under the terms of the GNU General Public License, version 2, as
12  published by the Free Software Foundation.
13 
14  KSieve is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  In addition, as a special exception, the copyright holders give
24  permission to link the code of this program with any edition of
25  the Qt library by Trolltech AS, Norway (or with modified versions
26  of Qt that use the same license as Qt), and distribute linked
27  combinations including the two. You must obey the GNU General
28  Public License in all respects for all of the code used other than
29  Qt. If you modify this file, you may extend this exception to
30  your version of the file, but you are not obligated to do so. If
31  you do not wish to do so, delete this exception statement from
32  your version.
33 */
34 
35 #ifndef KSIEVE_IMPL_PARSER_H
36 #define KSIEVE_IMPL_PARSER_H
37 
38 #include <ksieve/parser.h>
39 
40 #include <ksieve/error.h>
41 #include <ksieve/lexer.h>
42 #include <impl/lexer.h>
43 
44 #include <ksieve/scriptbuilder.h>
45 
46 namespace KSieve {
47 class Parser::Impl
48 {
49  friend class Parser;
50 private:
51  Impl(const char *scursor, const char *const send, int options = 0);
52 
53  void setScriptBuilder(ScriptBuilder *builder)
54  {
55  mBuilder = builder;
56  }
57 
58  ScriptBuilder *scriptBuilder() const
59  {
60  return mBuilder;
61  }
62 
63  bool parse();
64 
65  const Error &error() const
66  {
67  return mError == Error::None ? lexer.error() : mError;
68  }
69 
70  bool parseCommandList();
71 
72  bool parseCommand();
73 
74  bool parseArgumentList();
75 
76  bool parseArgument();
77 
78  bool parseTestList();
79 
80  bool parseTest();
81 
82  bool parseBlock();
83 
84  bool parseStringList();
85 
86  bool parseNumber();
87 
88  Lexer::Token token() const
89  {
90  return mToken;
91  }
92 
93  QString tokenValue() const
94  {
95  return mTokenValue;
96  }
97 
98  bool atEnd() const
99  {
100  return !mToken && lexer.atEnd();
101  }
102 
103  bool obtainToken();
104  void consumeToken()
105  {
106  mToken = Lexer::None;
107  mTokenValue.clear();
108  }
109 
110  void makeError(Error::Type e, int line, int col)
111  {
112  mError = Error(e, line, col);
113  if (scriptBuilder()) {
114  scriptBuilder()->error(mError);
115  }
116  }
117 
118  void makeError(Error::Type e)
119  {
120  makeError(e, lexer.line(), lexer.column());
121  }
122 
123  void makeUnexpectedTokenError(Error::Type e)
124  {
125  makeError(e); // ### save wrong token...
126  }
127 
128  bool isArgumentToken() const;
129  bool isStringToken() const;
130 
131  Error mError;
132  Lexer::Token mToken;
133  QString mTokenValue;
134  Lexer::Impl lexer;
135  ScriptBuilder *mBuilder = nullptr;
136 };
137 }
138 
139 #endif
QVector< QVariant > parse(const QString &message, const QDate &externalIssueDate=QDate())
void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 6 2020 23:07:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.