forked from qt-creator/qt-creator
QmlJS: Sync parser with Qt 5.10
Change-Id: I87c64edc1235bab10b9f32abeab4386b5cc7390b Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
dba102ff61
commit
3a52a2c3f1
@@ -149,3 +149,4 @@ QDebug &operator<< (QDebug &, const QmlDirParser::Component &);
|
||||
QDebug &operator<< (QDebug &, const QmlDirParser::Script &);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QtCore/qfile.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qvector.h>
|
||||
#include <QtCore/qpointer.h>
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +79,7 @@ public:
|
||||
quint16 line;
|
||||
quint16 column;
|
||||
QtMsgType messageType;
|
||||
QObject *object;
|
||||
QPointer<QObject> object;
|
||||
};
|
||||
|
||||
QmlErrorPrivate::QmlErrorPrivate()
|
||||
@@ -315,7 +316,9 @@ QDebug operator<<(QDebug debug, const QmlError &error)
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
QByteArray data = f.readAll();
|
||||
QTextStream stream(data, QIODevice::ReadOnly);
|
||||
#if QT_CONFIG(textcodec)
|
||||
stream.setCodec("UTF-8");
|
||||
#endif
|
||||
const QString code = stream.readAll();
|
||||
const auto lines = code.splitRef(QLatin1Char('\n'));
|
||||
|
||||
|
||||
@@ -3182,7 +3182,7 @@ PropertyAssignmentListOpt: PropertyAssignmentList ;
|
||||
yylloc.startColumn += yylloc.length;
|
||||
yylloc.length = 0;
|
||||
|
||||
//const QString msg = QCoreApplication::translate("QmlParser", "Missing \";\".");
|
||||
//const QString msg = QCoreApplication::translate("QmlParser", "Missing `;'");
|
||||
//diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, yylloc, msg));
|
||||
|
||||
first_token = &token_buffer[0];
|
||||
@@ -3212,9 +3212,9 @@ PropertyAssignmentListOpt: PropertyAssignmentList ;
|
||||
QString msg;
|
||||
int token = token_buffer[0].token;
|
||||
if (token < 0 || token >= TERMINAL_COUNT)
|
||||
msg = QCoreApplication::translate("QmlParser", "Syntax error.");
|
||||
msg = QCoreApplication::translate("QmlParser", "Syntax error");
|
||||
else
|
||||
msg = QCoreApplication::translate("QmlParser", "Unexpected token \"%1\".").arg(QLatin1String(spell[token]));
|
||||
msg = QCoreApplication::translate("QmlParser", "Unexpected token `%1'").arg(QLatin1String(spell[token]));
|
||||
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
|
||||
|
||||
action = errorState;
|
||||
@@ -3242,7 +3242,7 @@ PropertyAssignmentListOpt: PropertyAssignmentList ;
|
||||
for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) {
|
||||
int a = t_action(errorState, *tk);
|
||||
if (a > 0 && t_action(a, yytoken)) {
|
||||
const QString msg = QCoreApplication::translate("QmlParser", "Expected token \"%1\".").arg(QLatin1String(spell[*tk]));
|
||||
const QString msg = QCoreApplication::translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[*tk]));
|
||||
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
|
||||
|
||||
yytoken = *tk;
|
||||
@@ -3266,7 +3266,7 @@ PropertyAssignmentListOpt: PropertyAssignmentList ;
|
||||
|
||||
int a = t_action(errorState, tk);
|
||||
if (a > 0 && t_action(a, yytoken)) {
|
||||
const QString msg = QCoreApplication::translate("QmlParser", "Expected token \"%1\".").arg(QLatin1String(spell[tk]));
|
||||
const QString msg = QCoreApplication::translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[tk]));
|
||||
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
|
||||
|
||||
yytoken = tk;
|
||||
@@ -3279,7 +3279,7 @@ PropertyAssignmentListOpt: PropertyAssignmentList ;
|
||||
}
|
||||
}
|
||||
|
||||
const QString msg = QCoreApplication::translate("QmlParser", "Syntax error.");
|
||||
const QString msg = QCoreApplication::translate("QmlParser", "Syntax error");
|
||||
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
|
||||
}
|
||||
|
||||
|
||||
@@ -582,7 +582,7 @@ again:
|
||||
|
||||
if (end - begin != chars.size() - 1) {
|
||||
_errorCode = IllegalExponentIndicator;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number");
|
||||
return T_ERROR;
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ again:
|
||||
if (qmlMode())
|
||||
break;
|
||||
_errorCode = IllegalCharacter;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Stray newline in string literal.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Stray newline in string literal");
|
||||
return T_ERROR;
|
||||
} else if (_char == QLatin1Char('\\')) {
|
||||
break;
|
||||
@@ -713,7 +713,7 @@ again:
|
||||
scanChar();
|
||||
if (_codePtr > _endPtr) {
|
||||
_errorCode = IllegalEscapeSequence;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "End of file reached at escape sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "End of file reached at escape sequence");
|
||||
return T_ERROR;
|
||||
}
|
||||
|
||||
@@ -726,7 +726,7 @@ again:
|
||||
u = decodeUnicodeEscapeCharacter(&ok);
|
||||
if (! ok) {
|
||||
_errorCode = IllegalUnicodeEscapeSequence;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence");
|
||||
return T_ERROR;
|
||||
}
|
||||
} break;
|
||||
@@ -737,7 +737,7 @@ again:
|
||||
u = decodeHexEscapeCharacter(&ok);
|
||||
if (!ok) {
|
||||
_errorCode = IllegalHexadecimalEscapeSequence;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal hexadecimal escape sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal hexadecimal escape sequence");
|
||||
return T_ERROR;
|
||||
}
|
||||
} break;
|
||||
@@ -759,7 +759,7 @@ again:
|
||||
u = QLatin1Char('\0');
|
||||
break;
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
// fall through
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
@@ -770,7 +770,7 @@ again:
|
||||
case '8':
|
||||
case '9':
|
||||
_errorCode = IllegalEscapeSequence;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Octal escape sequences are not allowed.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Octal escape sequences are not allowed");
|
||||
return T_ERROR;
|
||||
|
||||
case '\r':
|
||||
@@ -794,7 +794,7 @@ again:
|
||||
}
|
||||
|
||||
_errorCode = UnclosedStringLiteral;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unclosed string at end of line.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unclosed string at end of line");
|
||||
return T_ERROR;
|
||||
}
|
||||
case '0':
|
||||
@@ -818,7 +818,7 @@ again:
|
||||
c = decodeUnicodeEscapeCharacter(&ok);
|
||||
if (! ok) {
|
||||
_errorCode = IllegalUnicodeEscapeSequence;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence");
|
||||
return T_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -843,7 +843,7 @@ again:
|
||||
c = decodeUnicodeEscapeCharacter(&ok);
|
||||
if (! ok) {
|
||||
_errorCode = IllegalUnicodeEscapeSequence;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal unicode escape sequence");
|
||||
return T_ERROR;
|
||||
}
|
||||
if (isIdentifierPart(c))
|
||||
@@ -906,7 +906,7 @@ int Lexer::scanNumber(QChar ch)
|
||||
}
|
||||
} else if (_char.isDigit() && !qmlMode()) {
|
||||
_errorCode = IllegalCharacter;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Decimal numbers can't start with \"0\".");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Decimal numbers can't start with '0'");
|
||||
return T_ERROR;
|
||||
}
|
||||
|
||||
@@ -927,7 +927,7 @@ int Lexer::scanNumber(QChar ch)
|
||||
|
||||
if (chars.size() < 3) {
|
||||
_errorCode = IllegalHexNumber;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "At least one hexadecimal digit is required after \"0%1\".").arg(ch);
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "At least one hexadecimal digit is required after '0%1'").arg(ch);
|
||||
return T_ERROR;
|
||||
}
|
||||
|
||||
@@ -1003,7 +1003,7 @@ int Lexer::scanNumber(QChar ch)
|
||||
|
||||
if (end - begin != chars.size() - 1) {
|
||||
_errorCode = IllegalExponentIndicator;
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Illegal syntax for exponential number");
|
||||
return T_ERROR;
|
||||
}
|
||||
|
||||
@@ -1029,7 +1029,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
|
||||
while (isIdentLetter(_char)) {
|
||||
int flag = regExpFlagFromChar(_char);
|
||||
if (flag == 0 || _patternFlags & flag) {
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Invalid regular expression flag \"%0\".")
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Invalid regular expression flag '%0'")
|
||||
.arg(QChar(_char));
|
||||
return false;
|
||||
}
|
||||
@@ -1046,7 +1046,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
|
||||
scanChar();
|
||||
|
||||
if (_codePtr > _endPtr || isLineTerminator()) {
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression backslash sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression backslash sequence");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1068,7 +1068,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
|
||||
scanChar();
|
||||
|
||||
if (_codePtr > _endPtr || isLineTerminator()) {
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression backslash sequence.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression backslash sequence");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1081,7 +1081,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
|
||||
}
|
||||
|
||||
if (_char != QLatin1Char(']')) {
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression class.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression class");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1091,7 +1091,7 @@ bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
|
||||
|
||||
default:
|
||||
if (_codePtr > _endPtr || isLineTerminator()) {
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression literal.");
|
||||
_errorMessage = QCoreApplication::translate("QmlParser", "Unterminated regular expression literal");
|
||||
return false;
|
||||
} else {
|
||||
_tokenText += _char;
|
||||
@@ -1295,7 +1295,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
|
||||
if (! (directiveName == QLatin1String("pragma") ||
|
||||
directiveName == QLatin1String("import"))) {
|
||||
error->message = QCoreApplication::translate("QmlParser", "Syntax error.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "Syntax error");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false; // not a valid directive name
|
||||
@@ -1305,7 +1305,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
if (directiveName == QLatin1String("pragma")) {
|
||||
// .pragma library
|
||||
if (! (lex() == T_IDENTIFIER && tokenText() == QLatin1String("library"))) {
|
||||
error->message = QCoreApplication::translate("QmlParser", "Syntax error.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "Syntax error");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false; // expected `library
|
||||
@@ -1329,7 +1329,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
pathOrUri = tokenText();
|
||||
|
||||
if (!pathOrUri.endsWith(QLatin1String("js"))) {
|
||||
error->message = QCoreApplication::translate("QmlParser","Imported file must be a script.");
|
||||
error->message = QCoreApplication::translate("QmlParser","Imported file must be a script");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false;
|
||||
@@ -1340,7 +1340,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
|
||||
while (true) {
|
||||
if (!isUriToken(_tokenKind)) {
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid module URI.");
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid module URI");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false;
|
||||
@@ -1350,7 +1350,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
|
||||
lex();
|
||||
if (tokenStartLine() != lineNumber) {
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid module URI.");
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid module URI");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false;
|
||||
@@ -1362,7 +1362,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
|
||||
lex();
|
||||
if (tokenStartLine() != lineNumber) {
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid module URI.");
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid module URI");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false;
|
||||
@@ -1370,7 +1370,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
}
|
||||
|
||||
if (_tokenKind != T_NUMERIC_LITERAL) {
|
||||
error->message = QCoreApplication::translate("QmlParser","Module import requires a version.");
|
||||
error->message = QCoreApplication::translate("QmlParser","Module import requires a version");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false; // expected the module version number
|
||||
@@ -1384,9 +1384,9 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
//
|
||||
if (! (lex() == T_IDENTIFIER && tokenText() == QLatin1String("as") && tokenStartLine() == lineNumber)) {
|
||||
if (fileImport)
|
||||
error->message = QCoreApplication::translate("QmlParser", "File import requires a qualifier.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "File import requires a qualifier");
|
||||
else
|
||||
error->message = QCoreApplication::translate("QmlParser", "Module import requires a qualifier.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "Module import requires a qualifier");
|
||||
if (tokenStartLine() != lineNumber) {
|
||||
error->loc.startLine = lineNumber;
|
||||
error->loc.startColumn = column;
|
||||
@@ -1399,9 +1399,9 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
|
||||
if (lex() != T_IDENTIFIER || tokenStartLine() != lineNumber) {
|
||||
if (fileImport)
|
||||
error->message = QCoreApplication::translate("QmlParser", "File import requires a qualifier.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "File import requires a qualifier");
|
||||
else
|
||||
error->message = QCoreApplication::translate("QmlParser", "Module import requires a qualifier.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "Module import requires a qualifier");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false; // expected module name
|
||||
@@ -1409,7 +1409,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
|
||||
const QString module = tokenText();
|
||||
if (!module.at(0).isUpper()) {
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid import qualifier.");
|
||||
error->message = QCoreApplication::translate("QmlParser","Invalid import qualifier");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false;
|
||||
@@ -1422,7 +1422,7 @@ bool Lexer::scanDirectives(Directives *directives, DiagnosticMessage *error)
|
||||
}
|
||||
|
||||
if (tokenStartLine() != lineNumber) {
|
||||
error->message = QCoreApplication::translate("QmlParser", "Syntax error.");
|
||||
error->message = QCoreApplication::translate("QmlParser", "Syntax error");
|
||||
error->loc.startLine = tokenStartLine();
|
||||
error->loc.startColumn = tokenStartColumn();
|
||||
return false; // the directives cannot span over multiple lines
|
||||
|
||||
Reference in New Issue
Block a user