QCodeEdit  2.2
qnfadefinition.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QNFA_DEFINITION_H_
17 #define _QNFA_DEFINITION_H_
18 
24 #include "qlanguagefactory.h"
25 #include "qlanguagedefinition.h"
26 
27 #include <QHash>
28 #include <QPointer>
29 #include <QStringList>
30 
31 struct QNFA;
32 
33 class QParenthesis;
34 
35 class QFile;
36 class QDomDocument;
37 
39 {
40  public:
41  enum
42  {
43  NoAction = 0,
44 
45  FormatMask = 0x00000fff,
46  ParenMask = 0x00fff000,
47 
48  Highlight = 0x01000000,
49  Indent = 0x02000000,
50  ParenOpen = 0x04000000,
51  ParenClose = 0x08000000,
52  MatchParen = 0x10000000,
53  Fold = 0x20000000,
54 
55  Ambiguous = 0x40000000,
56 
57  Content = 0x80000000
58  };
59 
60  inline static int format(int id)
61  { return id & FormatMask; }
62 
63  inline static int parenthesis(int id)
64  { return id & ParenMask; }
65 };
66 
68 {
69  public:
71  virtual ~QNFADefinition();
72 
73  virtual QString language() const;
74  virtual QStringList extensions() const;
75 
76  virtual int tokenize(QDocument *d, int line, int count);
77 
78  virtual QString singleLineComment() const;
79 
80  virtual QString defaultLineMark() const;
81 
82  virtual void clearMatches(QDocument *d);
83  virtual void match(QDocumentCursor& c);
84 
85  virtual QString indent(const QDocumentCursor& c);
86  virtual bool unindent (const QDocumentCursor& c, const QString& ktxt);
87 
88  virtual void expand(QDocument *d, int line);
89  virtual void collapse(QDocument *d, int line);
90  virtual int blockFlags(QDocument *d, int line, int depth) const;
91 
92  static void load(QFile *f, QLanguageFactory::LangData *d, QFormatScheme *s);
93  static void load(const QString& file, QLanguageFactory::LangData *d, QFormatScheme *s);
94  static void load(const QDomDocument& doc, QLanguageFactory::LangData *d, QFormatScheme *s);
95 
96  static void addContext(const QString& id, QNFA *nfa);
97  static void addEmbedRequest(const QString& lang, QNFA *dest);
98  static void shareEmbedRequests(QNFA *src, QNFA *dest, int offset);
99 
100  private:
101  bool m_indentFold;
102  QString m_language,
103  m_defaultMark,
104  m_singleLineComment;
105 
106  QStringList m_extensions;
107 
108  QNFA *m_root;
109 
110  QHash<QPointer<QDocument>, int> m_matchGroups;
111 
112  static QHash<QString, int> m_paren;
113  static QHash<QString, QNFA*> m_contexts;
114 
115  struct PMatch
116  {
117  PMatch() : type(Invalid)
118  {
119  line[0] = -1;
120  line[1] = -1;
121 
122  column[0] = -1;
123  column[1] = -1;
124 
125  length[0] = 0;
126  length[1] = 0;
127  }
128 
129  enum Type
130  {
131  Invalid,
132  Match,
133  Mismatch
134  };
135 
136  char type;
137 
138  int line[2];
139  int column[2];
140  int length[2];
141  };
142 
143  void matchOpen(QDocument *d, PMatch& m);
144  void matchClose(QDocument *d, PMatch& m);
145 
146  int findBlockEnd(QDocument *d, int line, bool *open = 0);
147 
148  static void flushEmbedRequests(const QString& lang);
149 
150  struct EmbedRequest
151  {
152  inline EmbedRequest(QNFA *nfa, int idx) : index(idx), target(nfa) {}
153 
154  int index;
155  QNFA *target;
156  };
157 
158  typedef QList<EmbedRequest> EmbedRequestList;
159 
160  static QHash<QString, EmbedRequestList> m_pendingEmbeds;
161 };
162 
163 #endif // !_QNFA_DEFINITION_H_
Definition: qdocumentline.h:36
#define QCE_EXPORT
Macro needed for cross-platform shared libraries creation.
Definition: qce-config.h:40
virtual int blockFlags(QDocument *d, int line, int depth=0) const
Compute the collapse state of a line.
Definition: qlanguagedefinition.cpp:164
virtual QString indent(const QDocumentCursor &c)
Return the indent to use when inserting a line at a given cursor position.
Definition: qlanguagedefinition.cpp:125
Definition: qnfa.h:109
virtual void collapse(QDocument *d, int line)
Collapse a text block at a given line.
Definition: qlanguagedefinition.cpp:155
A class storing a document.
Definition: qdocument.h:62
virtual void match(QDocumentCursor &c)
Brace matching entry point.
Definition: qlanguagedefinition.cpp:117
virtual bool unindent(const QDocumentCursor &c, const QString &ktxt)
Determines whether the given key event at the given position should cause unindent to happen.
Definition: qlanguagedefinition.cpp:135
Definition: qnfadefinition.h:38
Definition: qnfadefinition.h:67
A storage/configuration class for shared highlighting formats.
Definition: qformatscheme.h:41
virtual int tokenize(QDocument *d, int line, int count)
Entry point for syntax highlighting.
Definition: qlanguagedefinition.cpp:82
virtual QString language() const =0
Definition of the QLanguageDefinition class.
Definition: qlanguagefactory.h:46
virtual void expand(QDocument *d, int line)
Expand a collapsed block at a given line.
Definition: qlanguagedefinition.cpp:146
Definition of the QLanguageFactory class.
Interface for language definition.
Definition: qlanguagedefinition.h:40
virtual void clearMatches(QDocument *d)
Brace matching entry point.
Definition: qlanguagedefinition.cpp:109
A cursor to navigate within documents and edit them.
Definition: qdocumentcursor.h:36
virtual QStringList extensions() const =0
virtual QString singleLineComment() const
Return the string starting a single line comment, if any offered by the language.
Definition: qlanguagedefinition.cpp:93
virtual QString defaultLineMark() const
Let language specify which line mark should be toggled by left clicking a line mark panel.
Definition: qlanguagedefinition.cpp:101