forked from qt-creator/qt-creator
QmlJS: Use new Lexer::scanDirectives.
Change-Id: Id9f4cd6a53dc0d3f4cf0a0b3c846eca0e48372fc Reviewed-on: http://codereview.qt-project.org/5144 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
@@ -223,11 +223,14 @@ bool Document::parse_helper(int startToken)
|
||||
Parser parser(_engine);
|
||||
|
||||
QString source = _source;
|
||||
if (startToken == QmlJSGrammar::T_FEED_JS_PROGRAM)
|
||||
extractPragmas(&source);
|
||||
|
||||
lexer.setCode(source, /*line = */ 1, /*qmlMode = */_language == QmlLanguage);
|
||||
|
||||
if (startToken == QmlJSGrammar::T_FEED_JS_PROGRAM) {
|
||||
// ### use directives
|
||||
Directives directives;
|
||||
lexer.scanDirectives(&directives);
|
||||
}
|
||||
|
||||
switch (startToken) {
|
||||
case QmlJSGrammar::T_FEED_UI_PROGRAM:
|
||||
_parsedCorrectly = parser.parse();
|
||||
@@ -278,86 +281,6 @@ Bind *Document::bind() const
|
||||
return _bind;
|
||||
}
|
||||
|
||||
// this is essentially a copy of QDeclarativeScriptParser::extractPragmas
|
||||
void Document::extractPragmas(QString *source)
|
||||
{
|
||||
const QChar forwardSlash(QLatin1Char('/'));
|
||||
const QChar star(QLatin1Char('*'));
|
||||
const QChar newline(QLatin1Char('\n'));
|
||||
const QChar dot(QLatin1Char('.'));
|
||||
const QChar semicolon(QLatin1Char(';'));
|
||||
const QChar space(QLatin1Char(' '));
|
||||
const QString pragma(QLatin1String(".pragma "));
|
||||
|
||||
const QChar *pragmaData = pragma.constData();
|
||||
|
||||
QString &script = *source;
|
||||
const QChar *data = script.constData();
|
||||
const int length = script.count();
|
||||
for (int ii = 0; ii < length; ++ii) {
|
||||
const QChar &c = data[ii];
|
||||
|
||||
if (c.isSpace())
|
||||
continue;
|
||||
|
||||
if (c == forwardSlash) {
|
||||
++ii;
|
||||
if (ii >= length)
|
||||
return;
|
||||
|
||||
const QChar &c = data[ii];
|
||||
if (c == forwardSlash) {
|
||||
// Find next newline
|
||||
while (ii < length && data[++ii] != newline) {};
|
||||
} else if (c == star) {
|
||||
// Find next star
|
||||
while (true) {
|
||||
while (ii < length && data[++ii] != star) {};
|
||||
if (ii + 1 >= length)
|
||||
return;
|
||||
|
||||
if (data[ii + 1] == forwardSlash) {
|
||||
++ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (c == dot) {
|
||||
// Could be a pragma!
|
||||
if (ii + pragma.length() >= length ||
|
||||
0 != ::memcmp(data + ii, pragmaData, sizeof(QChar) * pragma.length()))
|
||||
return;
|
||||
|
||||
int pragmaStatementIdx = ii;
|
||||
|
||||
ii += pragma.length();
|
||||
|
||||
while (ii < length && data[ii].isSpace()) { ++ii; }
|
||||
|
||||
int startIdx = ii;
|
||||
|
||||
while (ii < length && data[ii].isLetter()) { ++ii; }
|
||||
|
||||
int endIdx = ii;
|
||||
|
||||
if (ii != length && data[ii] != forwardSlash && !data[ii].isSpace() && data[ii] != semicolon)
|
||||
return;
|
||||
|
||||
QString p(data + startIdx, endIdx - startIdx);
|
||||
|
||||
if (p != QLatin1String("library"))
|
||||
return;
|
||||
|
||||
for (int jj = pragmaStatementIdx; jj < endIdx; ++jj) script[jj] = space;
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LibraryInfo::LibraryInfo(Status status)
|
||||
: _status(status)
|
||||
, _dumpStatus(NoTypeInfo)
|
||||
|
Reference in New Issue
Block a user