File indexing completed on 2024-11-17 04:50:40

0001 /*  -*- c++ -*-
0002     ksieve/lexer.h
0003 
0004     This file is part of KSieve,
0005     the KDE internet mail/usenet news message filtering library.
0006     SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org>
0007 
0008     SPDX-License-Identifier: GPL-2.0-only
0009 */
0010 
0011 #pragma once
0012 
0013 #include "ksieve_export.h"
0014 
0015 class QString;
0016 
0017 namespace KSieve
0018 {
0019 class Error;
0020 
0021 class KSIEVE_EXPORT Lexer
0022 {
0023 public:
0024     enum Options { IncludeComments = 0, IgnoreComments = 1, IncludeLineFeeds = 0, IgnoreLineFeeds = 2 };
0025 
0026     Lexer(const char *scursor, const char *send, int options = 0);
0027     ~Lexer();
0028 
0029     /** Return whether comments are returned by @ref
0030         nextToken. Default is to not ignore comments. Ignoring them
0031         can speed up script parsing a bit, and can be used when the
0032         internal representation of the script won't be serialized into
0033         string form again (or if you simply want to delete all
0034         comments)
0035     **/
0036     bool ignoreComments() const;
0037 
0038     /** Return whether line feeds are returned by @ref
0039         nextToken. Default is to not ignore line feeds. Ignoring them
0040         can speed up script parsing a bit, and can be used when the
0041         internal representation of the script won't be serialized into
0042         string form again.
0043     **/
0044     bool ignoreLineFeeds() const;
0045 
0046     const Error &error() const;
0047 
0048     bool atEnd() const;
0049     int column() const;
0050     int line() const;
0051 
0052     enum Token {
0053         None = 0,
0054         Number, // 1, 100, 1M, 10k, 1G, 2g, 3m
0055         Identifier, // atom
0056         Tag, // :tag
0057         Special, // {} [] () ,;
0058         QuotedString, // "foo\"bar" -> foo"bar
0059         MultiLineString, // text: \nfoo\n. -> foo
0060         HashComment, // # foo
0061         BracketComment, // /* foo */
0062         LineFeeds // the number of line feeds encountered
0063     };
0064 
0065     /** Parse the next token and return it's type. @p result will contain
0066         the value of the token. */
0067     Token nextToken(QString &result);
0068 
0069     void save();
0070     void restore();
0071 
0072     class Impl;
0073 
0074 private:
0075     Impl *i = nullptr;
0076 
0077 private:
0078     const Lexer &operator=(const Lexer &);
0079     Lexer(const Lexer &);
0080 };
0081 } // namespace KSieve