Changeset View
Changeset View
Standalone View
Standalone View
src/backends/sage/sagehighlighter.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | 16 | | |||
17 | --- | 17 | --- | ||
18 | Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com> | 18 | Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com> | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "sagehighlighter.h" | 21 | #include "sagehighlighter.h" | ||
22 | #include "sagekeywords.h" | 22 | #include "sagekeywords.h" | ||
23 | 23 | | |||
24 | using namespace Cantor; | ||||
25 | | ||||
24 | SageHighlighter::SageHighlighter(QObject* parent) : Cantor::DefaultHighlighter(parent) | 26 | SageHighlighter::SageHighlighter(QObject* parent) : Cantor::DefaultHighlighter(parent) | ||
25 | { | 27 | { | ||
26 | addRule(QRegExp(QLatin1String("[A-Za-z0-9_]+(?=\\()")), functionFormat()); | 28 | addRule(QRegExp(QLatin1String("[A-Za-z0-9_]+(?=\\()")), functionFormat()); | ||
27 | 29 | | |||
28 | addKeywords(SageKeywords::instance()->keywords()); | 30 | addKeywords(SageKeywords::instance()->keywords()); | ||
29 | addFunctions(SageKeywords::instance()->functions()); | 31 | addFunctions(SageKeywords::instance()->functions()); | ||
30 | addVariables(SageKeywords::instance()->variables()); | 32 | addVariables(SageKeywords::instance()->variables()); | ||
31 | 33 | | |||
32 | addRule(QRegExp(QLatin1String("#[^\n]*")), commentFormat()); | 34 | addRule(QRegExp(QLatin1String("#[^\n]*")), commentFormat()); | ||
33 | } | 35 | } | ||
36 | | ||||
37 | DefaultHighlighter::Section SageHighlighter::findNextCodeSection(const QString& text, DefaultHighlighter::Section previous) | ||||
38 | { | ||||
39 | DefaultHighlighter::Section section; | ||||
40 | | ||||
41 | if (previous.end >= text.size()) | ||||
42 | { | ||||
43 | section.begin = -1; | ||||
44 | section.end = -1; | ||||
45 | } | ||||
46 | else | ||||
47 | { | ||||
48 | const int begin = text.indexOf(QLatin1String(" sage: "), std::max(previous.end, 0)); | ||||
49 | if (begin != -1) | ||||
50 | { | ||||
51 | // size of " sage: " == 10 | ||||
52 | section.begin = begin + 10; | ||||
53 | section.end = text.size(); | ||||
54 | } | ||||
55 | else | ||||
56 | { | ||||
57 | section.begin = -1; | ||||
58 | section.end = -1; | ||||
59 | } | ||||
60 | } | ||||
61 | | ||||
62 | return section; | ||||
63 | } |