Quark  0.1
LanguageSyntax.h++
Go to the documentation of this file.
1 #ifndef __libquark_syntax_LanguageSyntax_hxx
2 #define __libquark_syntax_LanguageSyntax_hxx
3 
4 #include <QAtomicInt>
5 #include <QList>
6 #include <QRegExp>
7 
8 #include <quark/Quark.h++>
9 
10 namespace quark {
11 namespace syntax {
12 
20 {
21  public:
22 
24  class HighlightingRule
25  {
26  friend class LanguageSyntax;
27 
28  public:
29 
30  QString element() const
31  { return(_element); }
32 
33  QRegExp pattern() const
34  { return(_pattern); }
35 
36  QRegExp endPattern() const
37  { return(_endPattern); }
38 
39  int identifier() const
40  { return(_identifier); }
41 
42  bool isMultiLine() const
43  { return(_identifier != 0); }
44 
45  private:
46 
47  HighlightingRule(const QString &element, int identifier,
48  const QString &pattern, const QString &endPattern,
49  bool caseInsensitive);
50 
51  QString _element;
52  int _identifier;
53  QRegExp _pattern;
54  QRegExp _endPattern;
55  };
56 
60  virtual ~LanguageSyntax();
61 
63  QString language() const
64  { return(_language); }
65 
68  const QList<HighlightingRule> rules() const
69  { return(_rules); }
70 
71  const HighlightingRule *ruleForIdentifier(int identifier) const;
72 
75  protected:
76 
82  LanguageSyntax(const QString &language);
83 
92  void addHighlightingRule(const QString &element,
93  const QString &pattern,
94  bool caseInsensitive = false);
106  void addMultilineHighlightingRule(const QString &element,
107  const QString &startPattern,
108  const QString &endPattern,
109  bool caseInsensitive = false);
110 
115  static const char *SINGLE_QUOTED_STRING_PATTERN;
116 
121  static const char *DOUBLE_QUOTED_STRING_PATTERN;
122 
123  private:
124 
125  QString _language;
126  QList<HighlightingRule> _rules;
127  QAtomicInt _nextId;
128 };
129 
130 } // namespace syntax
131 } // namespace quark
132 
133 #endif // __libquark_syntax_LanguageSyntax_hxx
Definition: BarChartView.h++:6
static const char * DOUBLE_QUOTED_STRING_PATTERN
A pattern for matching a double-quoted string in which embedded double-quotes are escaped using a bac...
Definition: LanguageSyntax.h++:121
QString language() const
Returns the name of the language.
Definition: LanguageSyntax.h++:63
A base class for recognizing a language syntax.
Definition: LanguageSyntax.h++:19
static const char * SINGLE_QUOTED_STRING_PATTERN
A pattern for matching a single-quoted string in which embedded single-quotes are escaped using a bac...
Definition: LanguageSyntax.h++:115
#define LIBQUARK_API
Definition: Quark.h++:18