Update qcssscanner so it can parse our normal offline documentation CSS

Adds the three CSS3 attribute selectors.

During this the internal naming of the existing attribute-selectors have
been changed to be more clear, and the dash-matching has been fixed to
not just be beginsWith.

A non-breaking space have also been removed from the CSS.

Change-Id: Ia4db4a5a19e3ceee8c3c8a4b744149edd1d32bdc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2016-07-19 17:27:44 +02:00 committed by Allan Sandfeld Jensen
parent a12cc29cf5
commit b3959b515f
6 changed files with 664 additions and 586 deletions

View File

@ -47,7 +47,7 @@ tt {
text-align: left
}
.main {
.main {
display: none;
}
/*

View File

@ -1914,18 +1914,38 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node)
if (attrValue.isNull())
return false;
if (a.valueMatchCriterium == QCss::AttributeSelector::MatchContains) {
switch (a.valueMatchCriterium) {
case QCss::AttributeSelector::NoMatch:
break;
case QCss::AttributeSelector::MatchEqual:
if (attrValue != a.value)
return false;
break;
case QCss::AttributeSelector::MatchIncludes: {
const auto lst = attrValue.splitRef(QLatin1Char(' '));
if (!lst.contains(QStringRef(&a.value)))
return false;
} else if (
(a.valueMatchCriterium == QCss::AttributeSelector::MatchEqual
&& attrValue != a.value)
||
(a.valueMatchCriterium == QCss::AttributeSelector::MatchBeginsWith
&& !attrValue.startsWith(a.value))
)
return false;
break;
}
case QCss::AttributeSelector::MatchDashMatch: {
const QString dashPrefix = a.value + QLatin1Char('-');
if (attrValue != a.value && !attrValue.startsWith(dashPrefix))
return false;
break;
}
case QCss::AttributeSelector::MatchBeginsWith:
if (!attrValue.startsWith(a.value))
return false;
break;
case QCss::AttributeSelector::MatchEndsWith:
if (!attrValue.endsWith(a.value))
return false;
break;
case QCss::AttributeSelector::MatchContains:
if (!attrValue.contains(a.value))
return false;
break;
}
}
}
@ -2439,7 +2459,7 @@ bool Parser::parseSimpleSelector(BasicSelector *basicSel)
onceMore = true;
AttributeSelector a;
a.name = QLatin1String("class");
a.valueMatchCriterium = AttributeSelector::MatchContains;
a.valueMatchCriterium = AttributeSelector::MatchIncludes;
if (!parseClass(&a.value)) return false;
basicSel->attributeSelectors.append(a);
} else if (testAttrib()) {
@ -2485,9 +2505,15 @@ bool Parser::parseAttrib(AttributeSelector *attr)
if (test(EQUAL)) {
attr->valueMatchCriterium = AttributeSelector::MatchEqual;
} else if (test(INCLUDES)) {
attr->valueMatchCriterium = AttributeSelector::MatchContains;
attr->valueMatchCriterium = AttributeSelector::MatchIncludes;
} else if (test(DASHMATCH)) {
attr->valueMatchCriterium = AttributeSelector::MatchDashMatch;
} else if (test(BEGINSWITH)) {
attr->valueMatchCriterium = AttributeSelector::MatchBeginsWith;
} else if (test(ENDSWITH)) {
attr->valueMatchCriterium = AttributeSelector::MatchEndsWith;
} else if (test(CONTAINS)) {
attr->valueMatchCriterium = AttributeSelector::MatchContains;
} else {
return next(RBRACKET);
}

View File

@ -539,8 +539,11 @@ struct AttributeSelector
enum ValueMatchType {
NoMatch,
MatchEqual,
MatchContains,
MatchBeginsWith
MatchIncludes,
MatchDashMatch,
MatchBeginsWith,
MatchEndsWith,
MatchContains
};
inline AttributeSelector() : valueMatchCriterium(NoMatch) {}
@ -679,6 +682,9 @@ enum TokenType {
CDC,
INCLUDES,
DASHMATCH,
BEGINSWITH,
ENDSWITH,
CONTAINS,
LBRACE,
PLUS,

File diff suppressed because it is too large Load Diff

View File

@ -113,6 +113,9 @@ static const char *tokenName(QCss::TokenType t)
case QCss::CDC: return "CDC";
case QCss::INCLUDES: return "INCLUDES";
case QCss::DASHMATCH: return "DASHMATCH";
case QCss::BEGINSWITH: return "BEGINSWITH";
case QCss::ENDSWITH: return "ENDSWITH";
case QCss::CONTAINS: return "CONTAINS";
case QCss::LBRACE: return "LBRACE";
case QCss::PLUS: return "PLUS";
case QCss::GREATER: return "GREATER";
@ -615,11 +618,11 @@ void tst_QCssParser::selector_data()
QCss::AttributeSelector attrSel;
attrSel.name = "foo";
attrSel.value = "warning";
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchContains;
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchIncludes;
basic.attributeSelectors << attrSel;
sel.basicSelectors << basic;
QTest::newRow("attr-contains") << QString("e[foo~=\"warning\"]") << sel;
QTest::newRow("attr-includes") << QString("e[foo~=\"warning\"]") << sel;
}
{
@ -630,11 +633,26 @@ void tst_QCssParser::selector_data()
QCss::AttributeSelector attrSel;
attrSel.name = "lang";
attrSel.value = "en";
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchBeginsWith;
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchDashMatch;
basic.attributeSelectors << attrSel;
sel.basicSelectors << basic;
QTest::newRow("attr-contains") << QString("e[lang|=\"en\"]") << sel;
QTest::newRow("attr-dash") << QString("e[lang|=\"en\"]") << sel;
}
{
QCss::Selector sel;
QCss::BasicSelector basic;
basic.elementName = "e";
QCss::AttributeSelector attrSel;
attrSel.name = "foo";
attrSel.value = "warning";
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchContains;
basic.attributeSelectors << attrSel;
sel.basicSelectors << basic;
QTest::newRow("attr-contains") << QString("e[foo*=\"warning\"]") << sel;
}
{
@ -645,7 +663,7 @@ void tst_QCssParser::selector_data()
QCss::AttributeSelector attrSel;
attrSel.name = "class";
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchContains;
attrSel.valueMatchCriterium = QCss::AttributeSelector::MatchIncludes;
attrSel.value = "warning";
basic.attributeSelectors.append(attrSel);

View File

@ -5,7 +5,7 @@ classname = QCssScanner_Generated
[Code Generator Options]
MapToCode[a-z] = (ch.unicode() >= 'a' && ch.unicode() <= 'z') || (ch.unicode() >= 'A' && ch.unicode() <= 'Z') || ch.unicode() >= 256
TokenPrefix = QCss::
FileHeader = ../moc/licenseheader.txt
FileHeader = ../../src/tools/moc/util/licenseheader.txt
[Macros]
escape = \\[^\r\n\f0-9a-f]
@ -36,6 +36,9 @@ CDO = "<!--"
CDC = "-->"
INCLUDES = "~="
DASHMATCH = "|="
BEGINSWITH = "^="
ENDSWITH = "$="
CONTAINS = "*="
LBRACE = {w}"{"
PLUS = {w}"+"