File: qnfadefinition.h

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (184 lines) | stat: -rw-r--r-- 4,720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/****************************************************************************
**
** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
**
** This file is part of the Edyuk project <http://edyuk.org>
** 
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef _QNFA_DEFINITION_H_
#define _QNFA_DEFINITION_H_

/*!
	\file qnfadefinition.h
	\brief Definition of the QNFADefinition class.
*/

#include "qlanguagefactory.h"
#include "qlanguagedefinition.h"

#include <QHash>
#include <QPointer>
#include <QStringList>

struct QNFA;

struct QParenthesis;

class QFile;
class QDomDocument;

class QNFAAction
{
public:
	enum
	{
		NoAction	= 0,

		FormatMask	= 0x00000fff,
		ParenMask	= 0x00fff000,

		Highlight	= 0x01000000,
		Indent		= 0x02000000,
		ParenOpen	= 0x04000000,
		ParenClose	= 0x08000000,
		MatchParen	= 0x10000000,
		Fold		= 0x20000000,

		Ambiguous	= 0x40000000,

		Content		= 0x80000000
				  };

	inline static int format(int id)
	{ return id & FormatMask; }

	inline static int parenthesis(int id)
	{ return id & ParenMask; }
};

class QCE_EXPORT QNFADefinition : public QLanguageDefinition
{
public:
	QNFADefinition();
	virtual ~QNFADefinition();

	virtual QString language() const;
	virtual QStringList extensions() const;

	virtual int tokenize(QDocument *d, int line, int count);

	virtual QString singleLineComment() const;

	virtual QString defaultLineMark() const;

	virtual int parenthesisWeight(int id) const;
	virtual const QStringList& openingParenthesis() const;
	//virtual const QHash<int, QString> & closingParenthesis() const;
	virtual QString getClosingParenthesis(const QString& opening) const;
	virtual bool possibleEndingOfOpeningParenthesis(const QString& text) const;

	virtual void clearMatches(QDocument *d);
	virtual void match(QDocumentCursor& c);

	virtual QList<QList<QDocumentCursor> > getMatches(const QDocumentCursor& c) const;
	virtual QDocumentCursor getNextMismatch(const QDocumentCursor& scope) const;
	
	virtual QString indent(const QDocumentCursor& c, int* indentCount);
	virtual bool unindent (const QDocumentCursor& c, const QString& ktxt);

	virtual void expand(QDocument *d, int line);
	virtual void collapse(QDocument *d, int line);
	void fold(QDocument *d, int line, bool expand);
	virtual bool correctFolding(QDocument *d);

	static void load(QFile *f, QLanguageFactory::LangData *d, QFormatScheme *s);
	static void load(const QString& file, QLanguageFactory::LangData *d, QFormatScheme *s);
	static void load(const QDomDocument& doc, QLanguageFactory::LangData *d, QFormatScheme *s);

	static void addContext(const QString& id, QNFA *nfa);
	static void addEmbedRequest(const QString& lang, QNFA *dest);
	static void shareEmbedRequests(QNFA *src, QNFA *dest, int offset);

	static QString getContextName(QNFA* cxt){
		return m_contexts.key(cxt);
	}

private:
	bool m_indentFold;
	QString m_language,
	m_defaultMark,
	m_singleLineComment;

	QStringList m_extensions;

	QNFA *m_root;

	QHash<QPointer<QDocument>, int> m_matchGroups;

	static QHash<QString, int> m_paren;
	static QHash<int, int> m_parenWeight;
	static QHash<QString, QNFA*> m_contexts;
	static QHash<QString, int> m_openingParenthesis;
	static QHash<int, QString> m_closingParenthesis;
	QStringList m_openingParenthesisList;
	bool m_openingParenthesisEnd[256];

	struct PMatch
	{
		PMatch() : type(Invalid)
		{
			line[0] = -1;
			line[1] = -1;

			column[0] = -1;
			column[1] = -1;

			length[0] = 0;
			length[1] = 0;

			weight[0] = weight[1] = 0;
		}

		enum Type
		{
			Invalid,
			Match,
			Mismatch
		};

		char type;

		int line[2];
		int column[2];
		int length[2];
		int weight[2];
	};
	virtual void getPMatches(const QDocumentCursor& c, QList<PMatch>& matches) const;

	void matchOpen(QDocument *d, PMatch& m) const;
	void matchClose(QDocument *d, PMatch& m) const;

	static void flushEmbedRequests(const QString& lang);

	struct EmbedRequest
	{
		inline EmbedRequest(QNFA *nfa, int idx) : index(idx), target(nfa) {}

		int index;
		QNFA *target;
	};

	typedef QList<EmbedRequest> EmbedRequestList;

	static QHash<QString, EmbedRequestList> m_pendingEmbeds;
};

#endif // !_QNFA_DEFINITION_H_