File indexing completed on 2024-04-14 05:44:25

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-only
0005  **/
0006 
0007 #ifndef REGEXP_H
0008 #define REGEXP_H
0009 
0010 #include <QDomDocument>
0011 #include <QDomElement>
0012 #include <QDomNode>
0013 #include <QList>
0014 
0015 class CompoundRegExp;
0016 class ErrorMap;
0017 
0018 /**
0019    Abstract syntax tree for regular expressions.
0020    @internal
0021 */
0022 class RegExp
0023 {
0024 public:
0025     RegExp(bool selected);
0026     virtual ~RegExp();
0027 
0028     virtual int precedence() const = 0;
0029     virtual QDomNode toXml(QDomDocument *doc) const = 0;
0030     virtual bool load(const QDomElement &, const QString &version) = 0;
0031     QString toXmlString() const;
0032 
0033     void check(ErrorMap &);
0034     virtual bool check(ErrorMap &, bool first, bool last) = 0;
0035 
0036     void addChild(RegExp *child);
0037     void removeChild(RegExp *child);
0038     void setParent(RegExp *parent);
0039     RegExp *clone() const;
0040     virtual bool operator==(const RegExp &other) const
0041     {
0042         return type() == other.type();
0043     }
0044 
0045     enum RegExpType { CONC, TEXT, DOT, POSITION, REPEAT, ALTN, COMPOUND, LOOKAHEAD, TEXTRANGE };
0046     virtual RegExpType type() const = 0;
0047     virtual void replacePart(CompoundRegExp * /* replacement */)
0048     {
0049     }
0050 
0051     bool isSelected() const
0052     {
0053         return _selected;
0054     }
0055 
0056     void setSelected(bool b)
0057     {
0058         _selected = b;
0059     }
0060 
0061 protected:
0062     RegExp *readRegExp(const QDomElement &top, const QString &version);
0063 
0064 private:
0065     RegExp()
0066     {
0067     } // disable
0068 
0069     QList<RegExp *> _children;
0070     RegExp *_parent = nullptr;
0071     bool _destructing;
0072     bool _selected;
0073 };
0074 
0075 typedef QList<RegExp *> RegExpList;
0076 typedef QListIterator<RegExp *> RegExpListIt;
0077 typedef QList<RegExp *>::iterator RegExpListStlIt;
0078 
0079 #endif // REGEXP_H