QCodeEdit 2.2
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr> 00004 ** 00005 ** This file is part of the Edyuk project <http://edyuk.org> 00006 ** 00007 ** This file may be used under the terms of the GNU General Public License 00008 ** version 3 as published by the Free Software Foundation and appearing in the 00009 ** file GPL.txt included in the packaging of this file. 00010 ** 00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 ** 00014 ****************************************************************************/ 00015 00016 #ifndef _QNFA_DEFINITION_H_ 00017 #define _QNFA_DEFINITION_H_ 00018 00024 #include "qlanguagefactory.h" 00025 #include "qlanguagedefinition.h" 00026 00027 #include <QHash> 00028 #include <QPointer> 00029 #include <QStringList> 00030 00031 struct QNFA; 00032 00033 class QParenthesis; 00034 00035 class QFile; 00036 class QDomDocument; 00037 00038 class QNFAAction 00039 { 00040 public: 00041 enum 00042 { 00043 NoAction = 0, 00044 00045 FormatMask = 0x00000fff, 00046 ParenMask = 0x00fff000, 00047 00048 Highlight = 0x01000000, 00049 Indent = 0x02000000, 00050 ParenOpen = 0x04000000, 00051 ParenClose = 0x08000000, 00052 MatchParen = 0x10000000, 00053 Fold = 0x20000000, 00054 00055 Ambiguous = 0x40000000, 00056 00057 Content = 0x80000000 00058 }; 00059 00060 inline static int format(int id) 00061 { return id & FormatMask; } 00062 00063 inline static int parenthesis(int id) 00064 { return id & ParenMask; } 00065 }; 00066 00067 class QCE_EXPORT QNFADefinition : public QLanguageDefinition 00068 { 00069 public: 00070 QNFADefinition(); 00071 virtual ~QNFADefinition(); 00072 00073 virtual QString language() const; 00074 virtual QStringList extensions() const; 00075 00076 virtual int tokenize(QDocument *d, int line, int count); 00077 00078 virtual QString singleLineComment() const; 00079 00080 virtual QString defaultLineMark() const; 00081 00082 virtual void clearMatches(QDocument *d); 00083 virtual void match(QDocumentCursor& c); 00084 00085 virtual QString indent(const QDocumentCursor& c); 00086 virtual bool unindent (const QDocumentCursor& c, const QString& ktxt); 00087 00088 virtual void expand(QDocument *d, int line); 00089 virtual void collapse(QDocument *d, int line); 00090 virtual int blockFlags(QDocument *d, int line, int depth) const; 00091 00092 static void load(QFile *f, QLanguageFactory::LangData *d, QFormatScheme *s); 00093 static void load(const QString& file, QLanguageFactory::LangData *d, QFormatScheme *s); 00094 static void load(const QDomDocument& doc, QLanguageFactory::LangData *d, QFormatScheme *s); 00095 00096 static void addContext(const QString& id, QNFA *nfa); 00097 static void addEmbedRequest(const QString& lang, QNFA *dest); 00098 static void shareEmbedRequests(QNFA *src, QNFA *dest, int offset); 00099 00100 private: 00101 bool m_indentFold; 00102 QString m_language, 00103 m_defaultMark, 00104 m_singleLineComment; 00105 00106 QStringList m_extensions; 00107 00108 QNFA *m_root; 00109 00110 QHash<QPointer<QDocument>, int> m_matchGroups; 00111 00112 static QHash<QString, int> m_paren; 00113 static QHash<QString, QNFA*> m_contexts; 00114 00115 struct PMatch 00116 { 00117 PMatch() : type(Invalid) 00118 { 00119 line[0] = -1; 00120 line[1] = -1; 00121 00122 column[0] = -1; 00123 column[1] = -1; 00124 00125 length[0] = 0; 00126 length[1] = 0; 00127 } 00128 00129 enum Type 00130 { 00131 Invalid, 00132 Match, 00133 Mismatch 00134 }; 00135 00136 char type; 00137 00138 int line[2]; 00139 int column[2]; 00140 int length[2]; 00141 }; 00142 00143 void matchOpen(QDocument *d, PMatch& m); 00144 void matchClose(QDocument *d, PMatch& m); 00145 00146 int findBlockEnd(QDocument *d, int line, bool *open = 0); 00147 00148 static void flushEmbedRequests(const QString& lang); 00149 00150 struct EmbedRequest 00151 { 00152 inline EmbedRequest(QNFA *nfa, int idx) : index(idx), target(nfa) {} 00153 00154 int index; 00155 QNFA *target; 00156 }; 00157 00158 typedef QList<EmbedRequest> EmbedRequestList; 00159 00160 static QHash<QString, EmbedRequestList> m_pendingEmbeds; 00161 }; 00162 00163 #endif // !_QNFA_DEFINITION_H_