File indexing completed on 2024-11-24 04:49:51

0001 /*  -*- c++ -*-
0002     impl/parser.h
0003 
0004     Internal header file. Subject to change without notice. DO NOT USE.
0005 
0006     This file is part of KSieve,
0007     the KDE internet mail/usenet news message filtering library.
0008     SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org>
0009 
0010     SPDX-License-Identifier: GPL-2.0-only
0011 */
0012 
0013 #pragma once
0014 
0015 #include "parser.h"
0016 
0017 #include "error.h"
0018 #include "lexer.h"
0019 #include "lexer_p.h"
0020 
0021 #include "scriptbuilder.h"
0022 
0023 namespace KSieve
0024 {
0025 class Parser::Impl
0026 {
0027     friend class Parser;
0028 
0029 private:
0030     Impl(const char *scursor, const char *const send, int options = 0);
0031 
0032     void setScriptBuilder(ScriptBuilder *builder)
0033     {
0034         mBuilder = builder;
0035     }
0036 
0037     ScriptBuilder *scriptBuilder() const
0038     {
0039         return mBuilder;
0040     }
0041 
0042     bool parse();
0043 
0044     const Error &error() const
0045     {
0046         return mError == Error::None ? lexer.error() : mError;
0047     }
0048 
0049     bool parseCommandList();
0050 
0051     bool parseCommand();
0052 
0053     bool parseArgumentList();
0054 
0055     bool parseArgument();
0056 
0057     bool parseTestList();
0058 
0059     bool parseTest();
0060 
0061     bool parseBlock();
0062 
0063     bool parseStringList();
0064 
0065     bool parseNumber();
0066 
0067     Lexer::Token token() const
0068     {
0069         return mToken;
0070     }
0071 
0072     QString tokenValue() const
0073     {
0074         return mTokenValue;
0075     }
0076 
0077     bool atEnd() const
0078     {
0079         return !mToken && lexer.atEnd();
0080     }
0081 
0082     bool obtainToken();
0083     void consumeToken()
0084     {
0085         mToken = Lexer::None;
0086         mTokenValue.clear();
0087     }
0088 
0089     void makeError(Error::Type e, int line, int col)
0090     {
0091         mError = Error(e, line, col);
0092         if (scriptBuilder()) {
0093             scriptBuilder()->error(mError);
0094         }
0095     }
0096 
0097     void makeError(Error::Type e)
0098     {
0099         makeError(e, lexer.line(), lexer.column());
0100     }
0101 
0102     void makeUnexpectedTokenError(Error::Type e)
0103     {
0104         makeError(e); // ### save wrong token...
0105     }
0106 
0107     bool isArgumentToken() const;
0108     bool isStringToken() const;
0109 
0110     Error mError;
0111     Lexer::Token mToken;
0112     QString mTokenValue;
0113     Lexer::Impl lexer;
0114     ScriptBuilder *mBuilder = nullptr;
0115 };
0116 }