diff options
author | David Boddie <david.boddie@nokia.com> | 2010-12-06 17:52:38 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2010-12-06 17:52:38 (GMT) |
commit | bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8 (patch) | |
tree | 44614b8add20ea5f89e3cbe5e87ba8b9eff1e781 /tools/qdoc3/qmlcodeparser.cpp | |
parent | 6834727fff1f74e15b2c9f25af1845e7f529afaa (diff) | |
download | Qt-bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8.zip Qt-bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8.tar.gz Qt-bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8.tar.bz2 |
Added missing qmlcodemarker.cpp and qmlcodemarker.h files.
Added code to remove pragmas before parsing and add them to the output.
The extractPragmas() function was copied into both qmlcodeparser.cpp and
qmlcodemarker.cpp from src/declarative/qml/qdeclarativescriptparser.cpp,
and was modified to return either nothing (for the API parser) or a
list of removed pragmas (for the code marker).
Diffstat (limited to 'tools/qdoc3/qmlcodeparser.cpp')
-rw-r--r-- | tools/qdoc3/qmlcodeparser.cpp | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/tools/qdoc3/qmlcodeparser.cpp b/tools/qdoc3/qmlcodeparser.cpp index 329912c..9c1d4ee 100644 --- a/tools/qdoc3/qmlcodeparser.cpp +++ b/tools/qdoc3/qmlcodeparser.cpp @@ -118,7 +118,10 @@ void QmlCodeParser::parseSourceFile(const Location& location, in.close(); Location fileLocation(filePath); - lexer->setCode(document, 1); + + QString newCode = document; + extractPragmas(newCode); + lexer->setCode(newCode, 1); QSet<QString> topicCommandsAllowed = topicCommands(); QSet<QString> otherMetacommandsAllowed = otherMetaCommands(); @@ -129,7 +132,7 @@ void QmlCodeParser::parseSourceFile(const Location& location, if (parser->parse()) { QDeclarativeJS::AST::UiProgram *ast = parser->ast(); - QmlDocVisitor visitor(filePath, document, &engine, tree, metacommandsAllowed); + QmlDocVisitor visitor(filePath, newCode, &engine, tree, metacommandsAllowed); QDeclarativeJS::AST::Node::accept(ast, &visitor); } } @@ -165,4 +168,68 @@ QSet<QString> QmlCodeParser::otherMetaCommands() << COMMAND_QMLDEFAULT; } +/* +Copied and pasted from src/declarative/qml/qdeclarativescriptparser.cpp. +*/ +static void replaceWithSpace(QString &str, int idx, int n) +{ + QChar *data = str.data() + idx; + const QChar space(QLatin1Char(' ')); + for (int ii = 0; ii < n; ++ii) + *data++ = space; +} + +/* +Copied and pasted from src/declarative/qml/qdeclarativescriptparser.cpp then +modified to return no values. + +Searches for ".pragma <value>" declarations within \a script. Currently supported pragmas +are: + library +*/ +void QmlCodeParser::extractPragmas(QString &script) +{ + const QString pragma(QLatin1String("pragma")); + const QString library(QLatin1String("library")); + + QDeclarativeJS::Lexer l(0); + l.setCode(script, 0); + + int token = l.lex(); + + while (true) { + if (token != QDeclarativeJSGrammar::T_DOT) + return; + + int startOffset = l.tokenOffset(); + int startLine = l.currentLineNo(); + + token = l.lex(); + + if (token != QDeclarativeJSGrammar::T_IDENTIFIER || + l.currentLineNo() != startLine || + script.mid(l.tokenOffset(), l.tokenLength()) != pragma) + return; + + token = l.lex(); + + if (token != QDeclarativeJSGrammar::T_IDENTIFIER || + l.currentLineNo() != startLine) + return; + + QString pragmaValue = script.mid(l.tokenOffset(), l.tokenLength()); + int endOffset = l.tokenLength() + l.tokenOffset(); + + token = l.lex(); + if (l.currentLineNo() == startLine) + return; + + if (pragmaValue == QLatin1String("library")) + replaceWithSpace(script, startOffset, endOffset - startOffset); + else + return; + } + return; +} + QT_END_NAMESPACE |