QmlJS: Extending QmlJSSimpleReader

With this patch bindings are parsed as strings.

Change-Id: I92014052947c595b220640d827dd77ee2db8f655
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2016-10-04 17:03:46 +02:00
parent 038f18ea9c
commit 9a9c29dd82
2 changed files with 13 additions and 2 deletions

View File

@@ -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()
{
}

View File

@@ -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