diff options
author | Erik Verbruggen <erik.verbruggen@nokia.com> | 2009-09-08 13:43:43 (GMT) |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@nokia.com> | 2009-09-08 13:43:43 (GMT) |
commit | 7731e5f7d33d3ec251299c7651e777d7e0054573 (patch) | |
tree | b326e16b1ba93f53e7b5b91f69a61a13a97e24a2 /src/declarative/qml/parser | |
parent | 914e331be160347a031cef131ac1cbc0a6787be0 (diff) | |
download | Qt-7731e5f7d33d3ec251299c7651e777d7e0054573.zip Qt-7731e5f7d33d3ec251299c7651e777d7e0054573.tar.gz Qt-7731e5f7d33d3ec251299c7651e777d7e0054573.tar.bz2 |
Added an option to the lexer to tell the engine of all comments in a QML
file.
Diffstat (limited to 'src/declarative/qml/parser')
-rw-r--r-- | src/declarative/qml/parser/qmljs.g | 1 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsastfwd_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsengine_p.cpp | 6 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsengine_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljslexer.cpp | 16 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljslexer_p.h | 3 |
6 files changed, 28 insertions, 6 deletions
diff --git a/src/declarative/qml/parser/qmljs.g b/src/declarative/qml/parser/qmljs.g index b0ef866..4ed75e8 100644 --- a/src/declarative/qml/parser/qmljs.g +++ b/src/declarative/qml/parser/qmljs.g @@ -80,6 +80,7 @@ %token T_DEBUGGER "debugger" %token T_RESERVED_WORD "reserved word" %token T_MULTILINE_STRING_LITERAL "multiline string literal" +%token T_COMMENT "comment" --- context keywords. %token T_PUBLIC "public" diff --git a/src/declarative/qml/parser/qmljsastfwd_p.h b/src/declarative/qml/parser/qmljsastfwd_p.h index f79cfc2..a6fee1d 100644 --- a/src/declarative/qml/parser/qmljsastfwd_p.h +++ b/src/declarative/qml/parser/qmljsastfwd_p.h @@ -62,9 +62,9 @@ namespace QmlJS { namespace AST { class SourceLocation { public: - SourceLocation(quint32 offset = 0, quint32 length = 0) + SourceLocation(quint32 offset = 0, quint32 length = 0, quint32 line = 0, quint32 column = 0) : offset(offset), length(length), - startLine(0), startColumn(0) + startLine(line), startColumn(column) { } bool isValid() const { return length != 0; } diff --git a/src/declarative/qml/parser/qmljsengine_p.cpp b/src/declarative/qml/parser/qmljsengine_p.cpp index 02d9b9c..eab8944 100644 --- a/src/declarative/qml/parser/qmljsengine_p.cpp +++ b/src/declarative/qml/parser/qmljsengine_p.cpp @@ -178,6 +178,12 @@ Engine::~Engine() QSet<NameId> Engine::literals() const { return _literals; } +void Engine::addComment(int pos, int len, int line, int col) +{ if (len > 0) _comments.append(QmlJS::AST::SourceLocation(pos, len, line, col)); } + +QList<QmlJS::AST::SourceLocation> Engine::comments() const +{ return _comments; } + NameId *Engine::intern(const QChar *u, int s) { return const_cast<NameId *>(&*_literals.insert(NameId(u, s))); } diff --git a/src/declarative/qml/parser/qmljsengine_p.h b/src/declarative/qml/parser/qmljsengine_p.h index 5aea983..877fff2 100644 --- a/src/declarative/qml/parser/qmljsengine_p.h +++ b/src/declarative/qml/parser/qmljsengine_p.h @@ -143,6 +143,7 @@ class Engine Lexer *_lexer; NodePool *_nodePool; QSet<NameId> _literals; + QList<QmlJS::AST::SourceLocation> _comments; public: Engine(); @@ -150,6 +151,9 @@ public: QSet<NameId> literals() const; + void addComment(int pos, int len, int line, int col); + QList<QmlJS::AST::SourceLocation> comments() const; + NameId *intern(const QChar *u, int s); static QString toString(NameId *id); diff --git a/src/declarative/qml/parser/qmljslexer.cpp b/src/declarative/qml/parser/qmljslexer.cpp index 9da6ec0..3be1710 100644 --- a/src/declarative/qml/parser/qmljslexer.cpp +++ b/src/declarative/qml/parser/qmljslexer.cpp @@ -43,6 +43,8 @@ #include "config.h" #endif +#include <QDebug> + #include "qmljsengine_p.h" #include "qmljslexer_p.h" #include "qmljsgrammar_p.h" @@ -71,7 +73,7 @@ extern double integerFromString(const char *buf, int size, int radix); using namespace QmlJS; -Lexer::Lexer(Engine *eng) +Lexer::Lexer(Engine *eng, bool tokenizeComments) : driver(eng), yylineno(0), done(false), @@ -94,8 +96,9 @@ Lexer::Lexer(Engine *eng) check_reserved(true), parenthesesState(IgnoreParentheses), parenthesesCount(0), - prohibitAutomaticSemicolon(false) -{ + prohibitAutomaticSemicolon(false), + tokenizeComments(tokenizeComments) +{qDebug()<<"--- new lexer"; driver->setLexer(this); // allocate space for read buffers buffer8 = new char[size8]; @@ -647,22 +650,29 @@ int Lexer::lex() setDone(Other); } else state = Start; + qDebug() << "--- state is InSingleLineComment @" << startlineno << ":"<<startcolumn; + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (current == 0) { + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); setDone(Eof); } + break; case InMultiLineComment: if (current == 0) { setDone(Bad); err = UnclosedComment; errmsg = QLatin1String("Unclosed comment at end of file"); + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } else if (isLineTerminator()) { shiftWindowsLineBreak(); yylineno++; } else if (current == '*' && next1 == '/') { state = Start; shift(1); + driver->addComment(startpos, tokenLength(), startlineno, startcolumn); } + break; case InIdentifier: if (isIdentLetter(current) || isDecimalDigit(current)) { diff --git a/src/declarative/qml/parser/qmljslexer_p.h b/src/declarative/qml/parser/qmljslexer_p.h index 5817868..6cca45d 100644 --- a/src/declarative/qml/parser/qmljslexer_p.h +++ b/src/declarative/qml/parser/qmljslexer_p.h @@ -67,7 +67,7 @@ class NameId; class Lexer { public: - Lexer(Engine *eng); + Lexer(Engine *eng, bool tokenizeComments = false); ~Lexer(); void setCode(const QString &c, int lineno); @@ -239,6 +239,7 @@ private: ParenthesesState parenthesesState; int parenthesesCount; bool prohibitAutomaticSemicolon; + bool tokenizeComments; }; } // namespace QmlJS |