File: syntax.h

package info (click to toggle)
antimony 0.9.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,476 kB
  • sloc: cpp: 42,596; ansic: 28,661; python: 1,093; yacc: 128; lex: 114; sh: 90; makefile: 10
file content (43 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (3)
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
#pragma once

#include <QSyntaxHighlighter>
#include <QRegularExpression>

class ScriptHighlighter : public QSyntaxHighlighter
{
public:
    explicit ScriptHighlighter(QTextDocument* doc);

protected:
    /*
     *  Function called by the highlighting engine
     */
    void highlightBlock(const QString& text) override;

    /*
     *  Define states to keep track of multiline strings.
     *  (with single quotes ''' or double quotes """)
     */
    enum State { BASE = -1,
                 MULTILINE_SINGLE = 1,
                 MULTILINE_DOUBLE = 2 };

    /*
     *  Structure to use as a rule when highlighting
     */
    struct Rule
    {
        Rule() { /* Nothing to do here */ }
        Rule(QString r, QTextCharFormat f,
             State si=BASE, State so=BASE)
            : regex(QRegularExpression(r)), format(f),
              state_in(si), state_out(so)
        { /* Nothing to do here */ }

        QRegularExpression regex;
        QTextCharFormat format;
        State state_in, state_out;
    };

    QList<Rule> rules;
};