Skip to content

Commit

Permalink
initial work on samples
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jul 14, 2017
1 parent 9c498c0 commit f869021
Show file tree
Hide file tree
Showing 32 changed files with 409 additions and 7 deletions.
234 changes: 234 additions & 0 deletions docs/ast.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/syntax/index.js
Expand Up @@ -153,6 +153,7 @@ function processStructure(name, nodeType) {
}

return {
samples: Array.isArray(nodeType.samples) ? nodeType.samples : null,
docs: docs,
check: createNodeStructureChecker(name, fields),
walk: walkers.length ? {
Expand Down Expand Up @@ -219,6 +220,7 @@ function createSyntax(config) {
var structure = processStructure(name, nodeType);
lexer.structure[name] = {
docs: structure.docs,
samples: structure.samples,
check: structure.check
};
if (structure.walk) {
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax/mix.js
Expand Up @@ -6,7 +6,7 @@ var shape = {
scope: {},
atrule: ['parse'],
pseudo: ['parse'],
node: ['name', 'structure', 'parse', 'generate', 'walkContext']
node: ['name', 'samples', 'structure', 'parse', 'generate', 'walkContext']
};

function mix(dest, src, shape) {
Expand Down
8 changes: 8 additions & 0 deletions lib/syntax/node/AnPlusB.js
Expand Up @@ -31,6 +31,14 @@ function checkTokenIsInteger(scanner, disallowSign) {
// An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
module.exports = {
name: 'AnPlusB',
samples: [
'2n + 1', '2n+1',
'2n - 1', '2n-1',
'3n', '+3n', '-3n',
'1n', '+1n', '-1n',
'n', '+n', '-n',
'1', '+1', '-1'
],
structure: {
a: [String, null],
b: [String, null]
Expand Down
5 changes: 5 additions & 0 deletions lib/syntax/node/Atrule.js
Expand Up @@ -24,6 +24,11 @@ function isBlockAtrule() {

module.exports = {
name: 'Atrule',
samples: [
'@charset "utf8";',
'@import "foo.css";',
'@supports (a: 1) {}'
],
structure: {
name: String,
expression: ['AtruleExpression', null],
Expand Down
6 changes: 6 additions & 0 deletions lib/syntax/node/AttributeSelector.js
Expand Up @@ -80,6 +80,12 @@ function getOperator() {
// '[' S* attrib_name S* attrib_match S* [ IDENT | STRING ] S* attrib_flags? S* ']'
module.exports = {
name: 'AttributeSelector',
samples: [
'[foo]', '[foo i]',
'[foo=bar]', '[foo=bar i]',
'[foo="bar"]', '[foo="bar" i]',
'[foo~=bar]', '[foo^=bar]', '[foo$=bar]', '[foo*=bar]', '[foo|=bar]'
],
structure: {
name: 'Identifier',
operator: [String, null],
Expand Down
5 changes: 5 additions & 0 deletions lib/syntax/node/Block.js
Expand Up @@ -10,6 +10,11 @@ var RIGHTCURLYBRACKET = TYPE.RightCurlyBracket;

module.exports = {
name: 'Block',
samples: [
'{}',
'{ foo: bar }',
'{ @test; }'
],
structure: {
children: [['Atrule', 'Rule', 'Declaration']]
},
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/Brackets.js
Expand Up @@ -7,6 +7,10 @@ var RIGHTSQUAREBRACKET = TYPE.RightSquareBracket;
// [ ident* ]
module.exports = {
name: 'Brackets',
samples: [
'[]',
'[foo bar]'
],
structure: {
children: [[]]
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/CDC.js
Expand Up @@ -2,6 +2,9 @@ var CDC = require('../../tokenizer').TYPE.CDC;

module.exports = {
name: 'CDC',
samples: [
'<!--'
],
structure: [],
parse: function() {
var start = this.scanner.tokenStart;
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/CDO.js
Expand Up @@ -2,6 +2,9 @@ var CDO = require('../../tokenizer').TYPE.CDO;

module.exports = {
name: 'CDO',
samples: [
'-->'
],
structure: [],
parse: function() {
var start = this.scanner.tokenStart;
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/ClassSelector.js
Expand Up @@ -5,6 +5,9 @@ var FULLSTOP = TYPE.FullStop;
// '.' ident
module.exports = {
name: 'ClassSelector',
samples: [
'.name'
],
structure: {
name: String
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/Combinator.js
Expand Up @@ -8,6 +8,9 @@ var TILDE = TYPE.Tilde;
// + | > | ~ | /deep/
module.exports = {
name: 'Combinator',
samples: [
'+', '>', '~', '/deep/'
],
structure: {
name: String
},
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/Comment.js
Expand Up @@ -6,6 +6,10 @@ var SOLIDUS = TYPE.Solidus;
// '/*' .* '*/'
module.exports = {
name: 'Comment',
samples: [
'/* comment */',
'/*! comment */'
],
structure: {
value: String
},
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/Declaration.js
Expand Up @@ -16,6 +16,10 @@ var BALANCED = true;

module.exports = {
name: 'Declaration',
samples: [
'property: value',
'--custom-property: value'
],
structure: {
important: [Boolean, String],
property: String,
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/DeclarationList.js
Expand Up @@ -7,6 +7,9 @@ var SEMICOLON = TYPE.Semicolon;

module.exports = {
name: 'DeclarationList',
samples: [
'foo: 1; bar: 2'
],
structure: {
children: [['Declaration']]
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/Dimension.js
Expand Up @@ -22,6 +22,9 @@ function readUnit(scanner) {
// number ident
module.exports = {
name: 'Dimension',
samples: [
'1px'
],
structure: {
value: String,
unit: String
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/Function.js
Expand Up @@ -7,6 +7,10 @@ var RIGHTPARENTHESIS = TYPE.RightParenthesis;
// ident '(' <sequence> ')'
module.exports = {
name: 'Function',
samples: [
'fn()',
'fn(1, 2)'
],
structure: {
name: String,
children: [[]]
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/HexColor.js
Expand Up @@ -32,6 +32,10 @@ function consumeHexSequence(scanner, required) {
// # ident
module.exports = {
name: 'HexColor',
samples: [
'#abc',
'#abc123'
],
structure: {
value: String
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/IdSelector.js
Expand Up @@ -5,6 +5,9 @@ var NUMBERSIGN = TYPE.NumberSign;
// '#' ident
module.exports = {
name: 'IdSelector',
samples: [
'#id'
],
structure: {
name: String
},
Expand Down
5 changes: 5 additions & 0 deletions lib/syntax/node/Identifier.js
Expand Up @@ -3,6 +3,11 @@ var IDENTIFIER = TYPE.Identifier;

module.exports = {
name: 'Identifier',
samples: [
'ident',
'-prefix-ident',
'--custom'
],
structure: {
name: String
},
Expand Down
7 changes: 7 additions & 0 deletions lib/syntax/node/MediaFeature.js
Expand Up @@ -9,6 +9,13 @@ var SOLIDUS = TYPE.Solidus;

module.exports = {
name: 'MediaFeature',
samples: [
'feature',
'feature: ident',
'feature: 123',
'feature: 123px',
'feature: 1/2'
],
structure: {
name: String,
value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/MediaQuery.js
Expand Up @@ -8,6 +8,9 @@ var LEFTPARENTHESIS = TYPE.LeftParenthesis;

module.exports = {
name: 'MediaQuery',
samples: [
'(feature) and (feature: 2)'
],
structure: {
children: [['Identifier', 'MediaFeature', 'WhiteSpace']]
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/MediaQueryList.js
Expand Up @@ -3,6 +3,9 @@ var COMMA = require('../../tokenizer').TYPE.Comma;

module.exports = {
name: 'MediaQueryList',
samples: [
'all, (feature: test)'
],
structure: {
children: [['MediaQuery']]
},
Expand Down
5 changes: 5 additions & 0 deletions lib/syntax/node/Nth.js
@@ -1,6 +1,11 @@
// https://drafts.csswg.org/css-syntax-3/#the-anb-type
module.exports = {
name: 'Nth',
samples: [
'2n + 1',
'odd',
'even'
],
structure: {
nth: ['AnPlusB', 'Identifier'],
selector: ['SelectorList', null]
Expand Down
6 changes: 6 additions & 0 deletions lib/syntax/node/Number.js
Expand Up @@ -2,6 +2,12 @@ var NUMBER = require('../../tokenizer').TYPE.Number;

module.exports = {
name: 'Number',
samples: [
'1', '-1',
'.2', '-.2',
'3.4', '-3.4',
'1e3', '-1.2e2'
],
structure: {
value: String
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/Percentage.js
Expand Up @@ -5,6 +5,9 @@ var PERCENTSIGN = TYPE.PercentSign;

module.exports = {
name: 'Percentage',
samples: [
'50%'
],
structure: {
value: String
},
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/PseudoClassSelector.js
Expand Up @@ -10,6 +10,10 @@ var BALANCED = true;
// : ident [ '(' .. ')' ]?
module.exports = {
name: 'PseudoClassSelector',
samples: [
':ident',
':ident(content)'
],
structure: {
name: String,
children: [['Raw'], null]
Expand Down
4 changes: 4 additions & 0 deletions lib/syntax/node/PseudoElementSelector.js
Expand Up @@ -10,6 +10,10 @@ var BALANCED = true;
// :: ident [ '(' .. ')' ]?
module.exports = {
name: 'PseudoElementSelector',
samples: [
'::ident',
'::ident(content)'
],
structure: {
name: String,
children: [['Raw'], null]
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/Ratio.js
Expand Up @@ -30,6 +30,9 @@ function consumeNumber(scanner) {
// <positive-integer> S* '/' S* <positive-integer>
module.exports = {
name: 'Ratio',
samples: [
'1/2', '1 / 2'
],
structure: {
left: String,
right: String
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/Raw.js
Expand Up @@ -10,6 +10,9 @@ var RIGHTSQUAREBRACKET = TYPE.RightSquareBracket;

module.exports = {
name: 'Raw',
samples: [
'raw is anything'
],
structure: {
value: String
},
Expand Down
3 changes: 3 additions & 0 deletions lib/syntax/node/Rule.js
Expand Up @@ -4,6 +4,9 @@ var BALANCED = true;

module.exports = {
name: 'Rule',
samples: [
'selector { property: value }'
],
structure: {
selector: ['SelectorList', 'Raw'],
block: ['Block']
Expand Down

0 comments on commit f869021

Please sign in to comment.