-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement custom customers for know at-rules and related changes
- custom customers for at-rules can be defined via parser.atrule - move default at-rule expression customer to parser/sequence.js - accept option for parse() to specify at-rule for atruleExpression context - define custom customer for @media expression - implement MediaQueryList, MediaQuery and Media feature node types
- Loading branch information
Showing
18 changed files
with
418 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
expression: function() { | ||
return this.MediaQueryList(); | ||
}, | ||
block: function() { | ||
return this.Block(this.Rule); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,31 @@ | ||
var List = require('../../utils/list'); | ||
var TYPE = require('../../scanner').TYPE; | ||
|
||
var WHITESPACE = TYPE.Whitespace; | ||
var STRING = TYPE.String; | ||
var COMMENT = TYPE.Comment; | ||
var LEFTPARENTHESIS = TYPE.LeftParenthesis; | ||
var LEFTCURLYBRACKET = TYPE.LeftCurlyBracket; | ||
var COMMA = TYPE.Comma; | ||
var COLON = TYPE.Colon; | ||
var SEMICOLON = TYPE.Semicolon; | ||
|
||
module.exports = function AtruleExpression() { | ||
var start; | ||
var children = null; | ||
var wasSpace = false; | ||
var lastNonSpace = null; | ||
var child; | ||
|
||
this.readSC(); | ||
start = this.scanner.tokenStart; | ||
|
||
scan: | ||
while (!this.scanner.eof) { | ||
switch (this.scanner.tokenType) { | ||
case SEMICOLON: | ||
case LEFTCURLYBRACKET: | ||
break scan; | ||
|
||
case WHITESPACE: | ||
wasSpace = true; | ||
this.scanner.next(); | ||
continue; | ||
|
||
case COMMENT: // ignore comments | ||
this.scanner.next(); | ||
continue; | ||
|
||
case COMMA: | ||
child = this.Operator(); | ||
break; | ||
|
||
case COLON: | ||
child = this.Pseudo(); | ||
break; | ||
|
||
case LEFTPARENTHESIS: | ||
child = this.Parentheses(this.scopeAtruleExpression); | ||
break; | ||
|
||
case STRING: | ||
child = this.String(); | ||
break; | ||
|
||
default: | ||
child = this.Any(this.scopeAtruleExpression); | ||
module.exports = function AtruleExpression(name) { | ||
// custom consumer | ||
if (this.atrule.hasOwnProperty(name)) { | ||
if (typeof this.atrule[name].expression === 'function') { | ||
return this.atrule[name].expression.call(this); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
if (children === null) { | ||
children = new List(); | ||
} | ||
// default consumer | ||
this.readSC(); | ||
|
||
if (wasSpace) { | ||
wasSpace = false; | ||
children.appendData(this.SPACE_NODE); | ||
} | ||
var start = this.scanner.tokenStart; | ||
var end = start; | ||
var children = this.readAtruleExpression(); | ||
|
||
lastNonSpace = this.scanner.tokenStart; | ||
children.appendData(child); | ||
if (children === null || children.isEmpty()) { | ||
return null; | ||
} | ||
|
||
if (children === null) { | ||
return null; | ||
if (this.needPositions) { | ||
end = children.last().loc.end.offset; | ||
} | ||
|
||
return { | ||
type: 'AtruleExpression', | ||
loc: this.getLocation(start, lastNonSpace !== null ? lastNonSpace : this.scanner.tokenStart), | ||
loc: this.getLocation(start, end), | ||
children: children | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var TYPE = require('../../scanner').TYPE; | ||
|
||
var IDENTIFIER = TYPE.Identifier; | ||
var NUMBER = TYPE.Number; | ||
var LEFTPARENTHESIS = TYPE.LeftParenthesis; | ||
var RIGHTPARENTHESIS = TYPE.RightParenthesis; | ||
var COLON = TYPE.Colon; | ||
var DISALLOW_VAR = false; | ||
|
||
module.exports = function MediaFeature() { | ||
var start = this.scanner.tokenStart; | ||
var name; | ||
var value = null; | ||
|
||
this.scanner.eat(LEFTPARENTHESIS); | ||
this.readSC(); | ||
|
||
name = this.readIdent(DISALLOW_VAR); | ||
this.readSC(); | ||
|
||
if (this.scanner.tokenType === COLON) { | ||
this.scanner.next(); | ||
this.readSC(); | ||
|
||
switch (this.scanner.tokenType) { | ||
case NUMBER: | ||
if (this.scanner.lookupType(1) === IDENTIFIER) { | ||
value = this.Dimension(); | ||
} else { | ||
value = this.Number(); | ||
} | ||
|
||
break; | ||
|
||
case IDENTIFIER: | ||
value = this.Identifier(DISALLOW_VAR); | ||
|
||
break; | ||
|
||
default: | ||
this.scanner.error('Number, dimension or identifier is expected'); | ||
} | ||
|
||
this.readSC(); | ||
} | ||
|
||
this.scanner.eat(RIGHTPARENTHESIS); | ||
|
||
return { | ||
type: 'MediaFeature', | ||
loc: this.getLocation(start, this.scanner.tokenStart), | ||
name: name, | ||
value: value | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var List = require('../../utils/list'); | ||
var TYPE = require('../../scanner').TYPE; | ||
|
||
var IDENTIFIER = TYPE.Identifier; | ||
var LEFTPARENTHESIS = TYPE.LeftParenthesis; | ||
var DISALLOW_VAR = false; | ||
|
||
module.exports = function MediaQuery() { | ||
this.readSC(); | ||
|
||
var start = this.scanner.tokenStart; | ||
var end = start; | ||
var children = new List(); | ||
|
||
if (this.scanner.lookupValue(0, 'only') || | ||
this.scanner.lookupValue(0, 'not')) { | ||
// [ not | only ] s+ ident | ||
children.appendData(this.Identifier(DISALLOW_VAR)); | ||
this.readSC(); | ||
|
||
children.appendData(this.Identifier(DISALLOW_VAR)); | ||
this.readSC(); | ||
} else if (this.scanner.tokenType === IDENTIFIER) { | ||
// ident | ||
children.appendData(this.Identifier(DISALLOW_VAR)); | ||
this.readSC(); | ||
} else if (this.scanner.tokenType === LEFTPARENTHESIS) { | ||
// <MediaFeature> | ||
children.appendData(this.MediaFeature()); | ||
this.readSC(); | ||
} else { | ||
this.scanner.error('Identifier or open parenthesis is expected'); | ||
} | ||
|
||
while (!this.scanner.eof) { | ||
if (this.scanner.lookupValue(0, 'and')) { | ||
if (children.isEmpty()) { | ||
this.scanner.error('Unexpected `and` keyword'); | ||
} | ||
|
||
children.appendData(this.Identifier(DISALLOW_VAR)); | ||
this.readSC(); | ||
} else { | ||
if (this.scanner.tokenType === LEFTPARENTHESIS) { | ||
this.scanner.error('`and` keyword is expected'); | ||
} | ||
break; | ||
} | ||
|
||
children.appendData(this.MediaFeature()); | ||
this.readSC(); | ||
} | ||
|
||
if (this.needPositions) { | ||
end = children.last().loc.end.offset; | ||
} | ||
|
||
return { | ||
type: 'MediaQuery', | ||
loc: this.getLocation(start, end), | ||
children: children | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var List = require('../../utils/list'); | ||
var COMMA = require('../../scanner').TYPE.Comma; | ||
|
||
module.exports = function MediaQueryList(relative) { | ||
this.readSC(); | ||
|
||
var start = this.scanner.tokenStart; | ||
var end = start; | ||
var children = new List(); | ||
var mediaQuery = null; | ||
|
||
while (!this.scanner.eof) { | ||
mediaQuery = this.MediaQuery(relative); | ||
children.appendData(mediaQuery); | ||
|
||
if (this.needPositions) { | ||
end = mediaQuery.children.last().loc.end.offset; | ||
} | ||
|
||
if (this.scanner.tokenType === COMMA) { | ||
this.scanner.next(); | ||
continue; | ||
} | ||
|
||
break; | ||
} | ||
|
||
return { | ||
type: 'MediaQueryList', | ||
loc: this.getLocation(start, end), | ||
children: children | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.