make quote/escape parsing more qmake-compatible

This commit is contained in:
Oswald Buddenhagen
2009-04-15 20:20:17 +02:00
parent 031c7c1658
commit cc09453cb1

View File

@@ -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,71 +278,83 @@ 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; insertComment(line.mid(i + 1));
else if (c == '(') escaped = m_contNextLine;
++parens; break;
else if (c == ')') }
--parens; if (!escaped) {
else if (c == '"' && (i == 0 || line.at(i - 1).unicode() != '\\')) if (c == '\\') {
quote = c; escaped = true;
else if (!parens && !quote) { m_proitem += c;
if (c == '#') { continue;
insertComment(line.mid(i + 1)); } else if (c == '"') {
contNextLine = m_contNextLine; inQuote = !inQuote;
break; m_proitem += c;
}
if (c == '\\' && i >= line.count() - 1) {
updateItem();
contNextLine = true;
continue; continue;
} }
if (m_block && (m_block->blockKind() & ProBlock::VariableKind)) { } else {
if (c == ' ') escaped = false;
updateItem(); }
else if (!inQuote) {
m_proitem += c; if (c == '(') {
continue; ++parens;
} } else if (c == ')') {
if (c == ':') { --parens;
enterScope(false); } else if (!parens) {
continue; if (m_block && (m_block->blockKind() & ProBlock::VariableKind)) {
} if (c == ' ')
if (c == '{') { updateItem();
enterScope(true); else
continue; m_proitem += c;
} continue;
if (c == '}') { }
leaveScope(); if (c == ':') {
continue; enterScope(false);
} continue;
if (c == '=') { }
insertVariable(line, &i); if (c == '{') {
continue; enterScope(true);
} continue;
if (c == '|' || c == '!') { }
insertOperator(c); if (c == '}') {
continue; leaveScope();
continue;
}
if (c == '=') {
insertVariable(line, &i);
continue;
}
if (c == '|' || c == '!') {
insertOperator(c);
continue;
}
} }
} }
m_proitem += c; m_proitem += c;
} }
m_contNextLine = contNextLine; m_inQuote = inQuote;
m_parens = parens;
if (!m_syntaxError) { m_contNextLine = escaped;
updateItem(); if (escaped) {
if (!m_contNextLine) m_proitem.chop(1);
finalizeBlock(); return true;
} else {
if (!m_syntaxError) {
updateItem();
if (!m_contNextLine)
finalizeBlock();
}
return !m_syntaxError;
} }
return !m_syntaxError;
} }
void ProFileEvaluator::Private::finalizeBlock() void ProFileEvaluator::Private::finalizeBlock()