From 9a9c29dd828a4caae28260f4636b08a63a888913 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 4 Oct 2016 17:03:46 +0200 Subject: [PATCH] QmlJS: Extending QmlJSSimpleReader With this patch bindings are parsed as strings. Change-Id: I92014052947c595b220640d827dd77ee2db8f655 Reviewed-by: Tim Jenssen --- src/libs/qmljs/qmljssimplereader.cpp | 13 +++++++++++-- src/libs/qmljs/qmljssimplereader.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libs/qmljs/qmljssimplereader.cpp b/src/libs/qmljs/qmljssimplereader.cpp index c8761c2a973..bdc686a5245 100644 --- a/src/libs/qmljs/qmljssimplereader.cpp +++ b/src/libs/qmljs/qmljssimplereader.cpp @@ -127,6 +127,8 @@ bool SimpleAbstractStreamReader::readFromSource(const QString &source) m_errors.clear(); m_currentSourceLocation = AST::SourceLocation(); + m_source = source; + Engine engine; Lexer lexer(&engine); Parser parser(&engine); @@ -176,6 +178,8 @@ bool SimpleAbstractStreamReader::readDocument(AST::UiProgram *ast) } readChild(uiObjectDefinition); + m_source.clear(); + return errors().isEmpty(); } @@ -271,8 +275,7 @@ QVariant SimpleAbstractStreamReader::parsePropertyExpression(AST::ExpressionNode if (numericLiteral) return numericLiteral->value; - addError(tr("Expected expression statement to be a literal."), expressionNode->firstSourceLocation()); - return QVariant(); + return textAt(expressionNode->firstSourceLocation(), expressionNode->lastSourceLocation()); } void SimpleAbstractStreamReader::setSourceLocation(const AST::SourceLocation &sourceLocation) @@ -280,6 +283,12 @@ void SimpleAbstractStreamReader::setSourceLocation(const AST::SourceLocation &so m_currentSourceLocation = sourceLocation; } +QString SimpleAbstractStreamReader::textAt(const AST::SourceLocation &from, + const AST::SourceLocation &to) +{ + return m_source.mid(from.offset, to.end() - from.begin()); +} + SimpleReader::SimpleReader() { } diff --git a/src/libs/qmljs/qmljssimplereader.h b/src/libs/qmljs/qmljssimplereader.h index a0ff03f4557..f2fe168a25b 100644 --- a/src/libs/qmljs/qmljssimplereader.h +++ b/src/libs/qmljs/qmljssimplereader.h @@ -101,9 +101,11 @@ private: QVariant parsePropertyScriptBinding(AST::UiScriptBinding *ExpressionNode); QVariant parsePropertyExpression(AST::ExpressionNode *expressionNode); void setSourceLocation(const AST::SourceLocation &sourceLocation); + QString textAt(const AST::SourceLocation &from, const AST::SourceLocation &to); QStringList m_errors; AST::SourceLocation m_currentSourceLocation; + QString m_source; }; class QMLJS_EXPORT SimpleReader: public SimpleAbstractStreamReader