forked from qt-creator/qt-creator
make quote/escape parsing more qmake-compatible
This commit is contained in:
@@ -151,6 +151,8 @@ public:
|
|||||||
QString m_pendingComment;
|
QString m_pendingComment;
|
||||||
bool m_syntaxError;
|
bool m_syntaxError;
|
||||||
bool m_contNextLine;
|
bool m_contNextLine;
|
||||||
|
bool m_inQuote;
|
||||||
|
int m_parens;
|
||||||
|
|
||||||
/////////////// Evaluating pro file contents
|
/////////////// Evaluating pro file contents
|
||||||
|
|
||||||
@@ -251,6 +253,8 @@ bool ProFileEvaluator::Private::read(ProFile *pro)
|
|||||||
// Parser state
|
// Parser state
|
||||||
m_block = 0;
|
m_block = 0;
|
||||||
m_commentItem = 0;
|
m_commentItem = 0;
|
||||||
|
m_inQuote = false;
|
||||||
|
m_parens = 0;
|
||||||
m_contNextLine = false;
|
m_contNextLine = false;
|
||||||
m_syntaxError = false;
|
m_syntaxError = false;
|
||||||
m_lineNo = 1;
|
m_lineNo = 1;
|
||||||
@@ -274,32 +278,37 @@ bool ProFileEvaluator::Private::parseLine(const QString &line0)
|
|||||||
if (m_blockstack.isEmpty())
|
if (m_blockstack.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ushort quote = 0;
|
int parens = m_parens;
|
||||||
int parens = 0;
|
bool inQuote = m_inQuote;
|
||||||
bool contNextLine = false;
|
bool escaped = false;
|
||||||
QString line = line0.simplified();
|
QString line = line0.simplified();
|
||||||
|
|
||||||
for (int i = 0; !m_syntaxError && i < line.length(); ++i) {
|
for (int i = 0; !m_syntaxError && i < line.length(); ++i) {
|
||||||
ushort c = line.at(i).unicode();
|
ushort c = line.at(i).unicode();
|
||||||
if (quote && c == quote)
|
if (c == '#') { // Yep - no escaping possible
|
||||||
quote = 0;
|
|
||||||
else if (c == '(')
|
|
||||||
++parens;
|
|
||||||
else if (c == ')')
|
|
||||||
--parens;
|
|
||||||
else if (c == '"' && (i == 0 || line.at(i - 1).unicode() != '\\'))
|
|
||||||
quote = c;
|
|
||||||
else if (!parens && !quote) {
|
|
||||||
if (c == '#') {
|
|
||||||
insertComment(line.mid(i + 1));
|
insertComment(line.mid(i + 1));
|
||||||
contNextLine = m_contNextLine;
|
escaped = m_contNextLine;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c == '\\' && i >= line.count() - 1) {
|
if (!escaped) {
|
||||||
updateItem();
|
if (c == '\\') {
|
||||||
contNextLine = true;
|
escaped = true;
|
||||||
|
m_proitem += c;
|
||||||
|
continue;
|
||||||
|
} else if (c == '"') {
|
||||||
|
inQuote = !inQuote;
|
||||||
|
m_proitem += c;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
escaped = false;
|
||||||
|
}
|
||||||
|
if (!inQuote) {
|
||||||
|
if (c == '(') {
|
||||||
|
++parens;
|
||||||
|
} else if (c == ')') {
|
||||||
|
--parens;
|
||||||
|
} else if (!parens) {
|
||||||
if (m_block && (m_block->blockKind() & ProBlock::VariableKind)) {
|
if (m_block && (m_block->blockKind() & ProBlock::VariableKind)) {
|
||||||
if (c == ' ')
|
if (c == ' ')
|
||||||
updateItem();
|
updateItem();
|
||||||
@@ -328,11 +337,17 @@ bool ProFileEvaluator::Private::parseLine(const QString &line0)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_proitem += c;
|
m_proitem += c;
|
||||||
}
|
}
|
||||||
m_contNextLine = contNextLine;
|
m_inQuote = inQuote;
|
||||||
|
m_parens = parens;
|
||||||
|
m_contNextLine = escaped;
|
||||||
|
if (escaped) {
|
||||||
|
m_proitem.chop(1);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
if (!m_syntaxError) {
|
if (!m_syntaxError) {
|
||||||
updateItem();
|
updateItem();
|
||||||
if (!m_contNextLine)
|
if (!m_contNextLine)
|
||||||
@@ -340,6 +355,7 @@ bool ProFileEvaluator::Private::parseLine(const QString &line0)
|
|||||||
}
|
}
|
||||||
return !m_syntaxError;
|
return !m_syntaxError;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ProFileEvaluator::Private::finalizeBlock()
|
void ProFileEvaluator::Private::finalizeBlock()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user