Skip to content

Commit

Permalink
:not(X) support — css/csso#111
Browse files Browse the repository at this point in the history
  • Loading branch information
afelix committed Nov 23, 2012
1 parent 0e561e8 commit b8e69dd
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Gomzales changelog
-------------------------

- Typo fix (global variable leak): https://github.com/css/csso/pull/110
- Attribute selectors extended by `|`.
- `not(..)` pseudo-class special support: https://github.com/css/csso/issues/111

28.10.2012, Version 1.0.5
-------------------------
Expand Down
29 changes: 27 additions & 2 deletions lib/gonzales.cssp.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ function getCSSPAST(_tokens, rule, _needInfo) {
//attrselector = (seq('=') | seq('~=') | seq('^=') | seq('$=') | seq('*=') | seq('|=')):x -> [#attrselector, x]
function checkAttrselector(_i) {
if (tokens[_i].type === TokenType.EqualsSign) return 1;
if (tokens[_i].type === TokenType.VerticalLine && (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign)) return 1;

if (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign) return fail(tokens[_i]);

Expand Down Expand Up @@ -1205,7 +1206,9 @@ function getCSSPAST(_tokens, rule, _needInfo) {

pos++;

var body = getFunctionBody();
var body = ident[needInfo? 2 : 1] !== 'not'?
getFunctionBody() :
getNotFunctionBody(); // ok, here we have CSS3 initial draft: http://dev.w3.org/csswg/selectors3/#negation

return needInfo?
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunktionType, ident, body] :
Expand All @@ -1220,11 +1223,33 @@ function getCSSPAST(_tokens, rule, _needInfo) {
while (tokens[pos].type !== TokenType.RightParenthesis) {
if (checkTset(pos)) {
x = getTset();

if ((needInfo && typeof x[1] === 'string') || typeof x[0] === 'string') body.push(x);
else body = body.concat(x);
} else if (checkClazz(pos)) {
body.push(getClazz());
} else {
throwError();
}
}

pos++;

return (needInfo?
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunctionBodyType] :
[CSSPNodeType.FunctionBodyType]
).concat(body);
}

function getNotFunctionBody() {
var startPos = pos,
body = [],
x;

while (tokens[pos].type !== TokenType.RightParenthesis) {
if (checkSimpleselector(pos)) {
body.push(getSimpleSelector());
} else {
throwError();
}
}

Expand Down
29 changes: 27 additions & 2 deletions src/cssp.ast.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ function getCSSPAST(_tokens, rule, _needInfo) {
//attrselector = (seq('=') | seq('~=') | seq('^=') | seq('$=') | seq('*=') | seq('|=')):x -> [#attrselector, x]
function checkAttrselector(_i) {
if (tokens[_i].type === TokenType.EqualsSign) return 1;
if (tokens[_i].type === TokenType.VerticalLine && (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign)) return 1;

if (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign) return fail(tokens[_i]);

Expand Down Expand Up @@ -933,7 +934,9 @@ function getCSSPAST(_tokens, rule, _needInfo) {

pos++;

var body = getFunctionBody();
var body = ident[needInfo? 2 : 1] !== 'not'?
getFunctionBody() :
getNotFunctionBody(); // ok, here we have CSS3 initial draft: http://dev.w3.org/csswg/selectors3/#negation

return needInfo?
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunktionType, ident, body] :
Expand All @@ -948,11 +951,33 @@ function getCSSPAST(_tokens, rule, _needInfo) {
while (tokens[pos].type !== TokenType.RightParenthesis) {
if (checkTset(pos)) {
x = getTset();

if ((needInfo && typeof x[1] === 'string') || typeof x[0] === 'string') body.push(x);
else body = body.concat(x);
} else if (checkClazz(pos)) {
body.push(getClazz());
} else {
throwError();
}
}

pos++;

return (needInfo?
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunctionBodyType] :
[CSSPNodeType.FunctionBodyType]
).concat(body);
}

function getNotFunctionBody() {
var startPos = pos,
body = [],
x;

while (tokens[pos].type !== TokenType.RightParenthesis) {
if (checkSimpleselector(pos)) {
body.push(getSimpleSelector());
} else {
throwError();
}
}

Expand Down
1 change: 1 addition & 0 deletions test/cssp/data/test_attrselector/attrselector.5.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|
1 change: 1 addition & 0 deletions test/cssp/data/test_attrselector/attrselector.5.l
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|
1 change: 1 addition & 0 deletions test/cssp/data/test_attrselector/attrselector.5.p
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
['attrselector', '|']
3 changes: 2 additions & 1 deletion test/cssp/data/test_simpleselector/simpleselector.11.p
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
['funktion',
['ident', 'not'],
['functionBody',
['ident', '*']]]]]
['simpleselector',
['ident', '*']]]]]]
5 changes: 3 additions & 2 deletions test/cssp/data/test_simpleselector/simpleselector.12.p
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
['funktion',
['ident', 'not'],
['functionBody',
['braces', '[', ']',
['ident', 'ABC']]]]]]
['simpleselector',
['attrib',
['ident', 'ABC']]]]]]]
7 changes: 4 additions & 3 deletions test/cssp/data/test_simpleselector/simpleselector.13.p
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
['funktion',
['ident', 'not'],
['functionBody',
['ident', 'el'],
['clazz',
['ident', 'class-postfix']]]]]]
['simpleselector',
['ident', 'el'],
['clazz',
['ident', 'class-postfix']]]]]]]
1 change: 1 addition & 0 deletions test/cssp/data/test_stylesheet/issue111.test1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body:not([x|x]) {}
1 change: 1 addition & 0 deletions test/cssp/data/test_stylesheet/issue111.test1.l
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body:not([x|x]) {}
16 changes: 16 additions & 0 deletions test/cssp/data/test_stylesheet/issue111.test1.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
['stylesheet',
['ruleset',
['selector',
['simpleselector',
['ident', 'body'],
['pseudoc',
['funktion',
['ident', 'not'],
['functionBody',
['simpleselector',
['attrib',
['ident', 'x'],
['attrselector', '|'],
['ident', 'x']]]]]],
['s', ' ']]],
['block']]]
29 changes: 27 additions & 2 deletions web/gonzales.cssp.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ function getCSSPAST(_tokens, rule, _needInfo) {
//attrselector = (seq('=') | seq('~=') | seq('^=') | seq('$=') | seq('*=') | seq('|=')):x -> [#attrselector, x]
function checkAttrselector(_i) {
if (tokens[_i].type === TokenType.EqualsSign) return 1;
if (tokens[_i].type === TokenType.VerticalLine && (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign)) return 1;

if (!tokens[_i + 1] || tokens[_i + 1].type !== TokenType.EqualsSign) return fail(tokens[_i]);

Expand Down Expand Up @@ -1205,7 +1206,9 @@ function getCSSPAST(_tokens, rule, _needInfo) {

pos++;

var body = getFunctionBody();
var body = ident[needInfo? 2 : 1] !== 'not'?
getFunctionBody() :
getNotFunctionBody(); // ok, here we have CSS3 initial draft: http://dev.w3.org/csswg/selectors3/#negation

return needInfo?
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunktionType, ident, body] :
Expand All @@ -1220,11 +1223,33 @@ function getCSSPAST(_tokens, rule, _needInfo) {
while (tokens[pos].type !== TokenType.RightParenthesis) {
if (checkTset(pos)) {
x = getTset();

if ((needInfo && typeof x[1] === 'string') || typeof x[0] === 'string') body.push(x);
else body = body.concat(x);
} else if (checkClazz(pos)) {
body.push(getClazz());
} else {
throwError();
}
}

pos++;

return (needInfo?
[{ ln: tokens[startPos].ln }, CSSPNodeType.FunctionBodyType] :
[CSSPNodeType.FunctionBodyType]
).concat(body);
}

function getNotFunctionBody() {
var startPos = pos,
body = [],
x;

while (tokens[pos].type !== TokenType.RightParenthesis) {
if (checkSimpleselector(pos)) {
body.push(getSimpleSelector());
} else {
throwError();
}
}

Expand Down

0 comments on commit b8e69dd

Please sign in to comment.