Changeset View
Changeset View
Standalone View
Standalone View
src/indexer/katehighlightingindexer.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 78 | #endif | |||
---|---|---|---|---|---|
108 | // all checks passed | 108 | // all checks passed | ||
109 | return true; | 109 | return true; | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | //! Check that a regular expression in a RegExpr rule: | 112 | //! Check that a regular expression in a RegExpr rule: | ||
113 | //! - is not empty | 113 | //! - is not empty | ||
114 | //! - isValid() | 114 | //! - isValid() | ||
115 | //! - character ranges such as [A-Z] are valid and not accidentally e.g. [A-z]. | 115 | //! - character ranges such as [A-Z] are valid and not accidentally e.g. [A-z]. | ||
116 | //! - dynamic=true but no place holder used? | ||||
116 | bool checkRegularExpression(const QString &hlFilename, QXmlStreamReader &xml) | 117 | bool checkRegularExpression(const QString &hlFilename, QXmlStreamReader &xml) | ||
117 | { | 118 | { | ||
118 | if (xml.name() == QLatin1String("RegExpr") || xml.name() == QLatin1String("emptyLine")) { | 119 | if (xml.name() == QLatin1String("RegExpr") || xml.name() == QLatin1String("emptyLine")) { | ||
119 | // get right attribute | 120 | // get right attribute | ||
120 | const QString string(xml.attributes().value((xml.name() == QLatin1String("RegExpr")) ? QLatin1String("String") : QLatin1String("regexpr")).toString()); | 121 | const QString string(xml.attributes().value((xml.name() == QLatin1String("RegExpr")) ? QLatin1String("String") : QLatin1String("regexpr")).toString()); | ||
121 | 122 | | |||
122 | // validate regexp | 123 | // validate regexp | ||
123 | const QRegularExpression regexp(string); | 124 | const QRegularExpression regexp(string); | ||
124 | if (!regexp.isValid()) { | 125 | if (!regexp.isValid()) { | ||
125 | qWarning() << hlFilename << "line" << xml.lineNumber() << "broken regex:" << string << "problem:" << regexp.errorString() << "at offset" << regexp.patternErrorOffset(); | 126 | qWarning() << hlFilename << "line" << xml.lineNumber() << "broken regex:" << string << "problem:" << regexp.errorString() << "at offset" << regexp.patternErrorOffset(); | ||
126 | return false; | 127 | return false; | ||
127 | } else if (string.isEmpty()) { | 128 | } else if (string.isEmpty()) { | ||
128 | qWarning() << hlFilename << "line" << xml.lineNumber() << "empty regex not allowed."; | 129 | qWarning() << hlFilename << "line" << xml.lineNumber() << "empty regex not allowed."; | ||
129 | return false; | 130 | return false; | ||
130 | } | 131 | } | ||
131 | 132 | | |||
132 | // catch possible case typos: [A-z] or [a-Z] | 133 | // catch possible case typos: [A-z] or [a-Z] | ||
133 | const int azOffset = std::max(string.indexOf(QStringLiteral("A-z")), string.indexOf(QStringLiteral("a-Z"))); | 134 | const int azOffset = std::max(string.indexOf(QStringLiteral("A-z")), string.indexOf(QStringLiteral("a-Z"))); | ||
134 | if (azOffset >= 0) { | 135 | if (azOffset >= 0) { | ||
135 | qWarning() << hlFilename << "line" << xml.lineNumber() << "broken regex:" << string << "problem: [a-Z] or [A-z] at offset" << azOffset; | 136 | qWarning() << hlFilename << "line" << xml.lineNumber() << "broken regex:" << string << "problem: [a-Z] or [A-z] at offset" << azOffset; | ||
136 | return false; | 137 | return false; | ||
137 | } | 138 | } | ||
139 | | ||||
140 | // dynamic == true and no place holder? | ||||
141 | if (xml.name() == QLatin1String("RegExpr") && xml.attributes().value(QStringLiteral("dynamic")) == QStringLiteral("true")) { | ||||
142 | static const QRegularExpression placeHolder(QStringLiteral("%\\d+")); | ||||
143 | if (!string.contains(placeHolder)) { | ||||
144 | qWarning() << hlFilename << "line" << xml.lineNumber() << "broken regex:" << string << "problem: dynamic=true but no %\\d+ placeholder"; | ||||
145 | return false; | ||||
146 | } | ||||
147 | } | ||||
138 | } | 148 | } | ||
139 | 149 | | |||
140 | return true; | 150 | return true; | ||
141 | } | 151 | } | ||
142 | 152 | | |||
143 | //! Check that keyword list items do not have trailing or leading spaces, | 153 | //! Check that keyword list items do not have trailing or leading spaces, | ||
144 | //! e.g.: <item> keyword </item> | 154 | //! e.g.: <item> keyword </item> | ||
145 | bool checkItemsTrimmed(const QString &hlFilename, QXmlStreamReader &xml) | 155 | bool checkItemsTrimmed(const QString &hlFilename, QXmlStreamReader &xml) | ||
▲ Show 20 Lines • Show All 626 Lines • Show Last 20 Lines |