Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new one-step parser

  • Loading branch information...
commit 9674958ae82d6f63cd2f7e2ff9af35bbb820a510 1 parent 17a1063
@lvivski authored
View
3  .gitignore
@@ -1,3 +1,2 @@
/node_modules
-/lib/boss
-/lib/css
+/lib/parser.js
View
9 GNUmakefile
@@ -1,9 +1,2 @@
build:
- @mkdir -p lib/{boss,css}
- @node_modules/.bin/ometajs2js -b -i src/boss/parser.ometajs > lib/boss/parser.js
- @node_modules/.bin/ometajs2js -b -i src/boss/transformer.ometajs > lib/boss/transformer.js
- @node_modules/.bin/ometajs2js -b -i src/boss/translator.ometajs > lib/boss/translator.js
-
- @node_modules/.bin/ometajs2js -b -i src/css/parser.ometajs > lib/css/parser.js
- @node_modules/.bin/ometajs2js -b -i src/css/transformer.ometajs > lib/css/transformer.js
- @node_modules/.bin/ometajs2js -b -i src/css/translator.ometajs > lib/css/translator.js
+ @node_modules/.bin/ometajs2js -b -i lib/parser.ometajs > lib/parser.js
View
12 lib/boss.js
@@ -1,10 +1,4 @@
-var Parser = exports.Parser = require('./boss/parser').BOSSParser
-
-var Transformer = exports.Transformer = require('./boss/transformer').BOSSTransformer
-
-var Translator = exports.Translator = require('./boss/translator').BOSSTranslator
-
-var inspect = require('util').inspect
+var Parser = require('./parser').BOSSParser
, q = require('q')
, fs = require('fs')
, Env = require('./env')
@@ -27,9 +21,7 @@ exports.run = function run(options) {
}
var parse = exports.parse = function parse(source) {
- var ast = Parser.matchAll(source, "stylesheet")
- ast = Transformer.match(ast, "stylesheet")
- return Translator.match(ast, "stylesheet")
+ return Parser.matchAll(source, "stylesheet")
}
function mixin(filename) {
View
2  lib/nodes/binop.js
@@ -1,5 +1,5 @@
var BinOp = module.exports = function BinOp(op, left, right) {
- this.op = '' + op
+ this.op = op
this.left = left
this.right = right
}
View
6 lib/nodes/dimension.js
@@ -22,6 +22,12 @@ var coercion = {
, s: {
ms: 1 / 1000
}
+ , rad: {
+ deg: Math.PI / 180
+ }
+ , deg: {
+ rad: 180 / Math.PI
+ }
}
Dimension.prototype = {
View
284 lib/parser.ometajs
@@ -0,0 +1,284 @@
+var nodes = require('./nodes');
+
+ometa BOSSParser {
+
+ // Macros
+
+ m_comment = seq('/*') (~seq('*/') char)*:x seq('*/') -> ('/*' + x.join('') + '*/'),
+
+ m_ident = '-' (char:x m_nmstart(x) -> x):x (escape | :y m_nmchar(y) -> y)*:z -> ('-' + x + z.join(''))
+ | (char:x m_nmstart(x) -> x):x (escape | :y m_nmchar(y) -> y)*:z -> (x + z.join('')),
+
+ escape = '\\' char:x -> ('\\' + x),
+
+ m_name = (:x m_nmchar(x) -> x)+:xx -> xx.join(''),
+
+ m_name2 = (:x m_nmchar2(x) -> x)+:xx -> xx.join(''),
+
+ m_number = digit+:x '.' digit+:y -> (x.join('') + '.' + y.join(''))
+ | '.' digit+:x -> ('.' + x.join(''))
+ | digit+:x -> x.join(''),
+
+ m_string = '"' (m_string_nl1 | ~'"' char)*:s '"' -> ('"' + s.join('') + '"')
+ | '\'' (m_string_nl2 | ~'\'' char)*:s '\'' -> ('\'' + s.join('') + '\''),
+
+ m_string_nl1 = ('\n' | '\r' | seq('\\"')):x -> x,
+ m_string_nl2 = ('\n' | '\r' | seq('\\\'')):x -> x,
+
+ m_nmstart :x = ?BOSSParser._m_nmstart(x),
+ m_unicode :x = ?BOSSParser._m_unicode(x),
+ m_escape :x = ?BOSSParser._m_escape(x),
+ m_nmchar :x = ?BOSSParser._m_nmchar(x),
+ m_nmchar2 :x = ?BOSSParser._m_nmchar2(x),
+ m_nl :x = ?BOSSParser._m_nl(x),
+ m_w :x = ?BOSSParser._m_w(x),
+
+ // Tokens
+
+ ident = m_ident:x -> new nodes.Ident(x),
+
+ atkeyword = '@' ident:x -> '@' + x,
+
+ string = m_string:x -> new nodes.String(x.slice(1, -1), x[0]),
+
+ shash = '#' m_name:x -> '#' + x,
+
+ vhash = '#' m_name2:x -> new nodes.Color(x),
+
+ number = m_number:x -> new nodes.Dimension(x),
+
+ percentage = m_number:x '%' -> new nodes.Dimension(x, '%'),
+
+ dimension = m_number:x m_name2:y -> new nodes.Dimension(x, y),
+
+ cdo = seq('<!--') -> '<!--',
+ cdc = seq('-->') -> '-->',
+
+ s = (:x m_w(x) -> x)+:xx -> xx.join(''),
+
+ attrselector = (seq('=') | seq('~=') | seq('^=') | seq('$=') | seq('*=') | seq('|=')):x -> x,
+
+ delim = ',' -> ',',
+
+ comment = seq('/*') (~seq('*/') char)*:x seq('*/') -> new nodes.Comment(x.join('')),
+
+ sc = s | comment,
+
+ tset = vhash | any | sc | operator,
+
+ stylesheet = (cdo | cdc | sc | statement)*:x -> new nodes.Stylesheet( BOSSParser.filter(x) ),
+
+ definition = ident:x '(' functionBody:y ')' sc* block:z -> new nodes.Definition(x.name, y, z),
+
+ assignment = property:p '=' value:v decldelim? sc* -> new nodes.Ident(p, v),
+
+ variable = '$' ident:x -> x,
+
+ statement = definition | ruleset | atrule | assignment,
+
+ atrulerq = tset*:ap -> ap.join(''),
+
+ atruleb = atkeyword:ak atrulerq:aq block:b -> new nodes.Atrule(ak + aq, b),
+
+ atrules = atkeyword:ak atrulerq:aq ';' -> new nodes.Atrule(ak + aq),
+
+ atrule = atruleb | atrules,
+
+ blockdecl = sc* (filter | declaration):x decldelim? sc* -> x
+ | sc* ruleset:x sc* -> x
+ | sc* decldelim sc* -> ' '
+ | sc+:s0 -> ' ',
+
+ decldelim = ';' -> ';',
+
+ block = '{' blockdecl*:x '}' -> new nodes.Block(x),
+
+ ruleset = selector:s block:b -> new nodes.Ruleset(s, b),
+
+ combinator = ('+' | '>' | '~' | '&'):x -> x,
+
+ attrib = '[' sc* ident:x sc* attrselector:a sc* (ident | string):y sc* ']' -> '[' + [x, a, y].join('') + ']'
+ | '[' sc* ident:x sc* ']' -> '[' + x.join('') + ']',
+
+ clazz = '.' ident:x -> '.' + x,
+
+ pseudoe = seq('::') ident:x -> '::' + x,
+
+ pseudoc = ':' (pseudof | ident):x -> ':' + x,
+
+ pseudof = ident:x '(' pseudofBody:y ')' -> new nodes.Call(x.name, y),
+
+ pseudofBody = (simpleselector)*:x -> BOSSParser.createExpression( BOSSParser.filter(x) , true),
+
+ pseudo = pseudoe | pseudoc,
+
+ nthf = ':' seq('nth-'):x (seq('child') | seq('last-child') | seq('of-type') | seq('last-of-type')):y -> x + y,
+
+ nth = (digit | 'n')+:x -> x.join('')
+ | (seq('even') | seq('odd')):x -> x,
+
+ nthselector = nthf:x '(' (sc | ('+' | '-'):op -> new nodes.Literal(op) | nth)*:y ')'
+ -> ':' + new nodes.Ident(x) + '(' +y.join('') + ')',
+
+ namespace = '|' -> '|',
+
+ simpleselector = (nthselector | combinator | attrib | pseudo | clazz | shash | any | sc | namespace)+:x
+ -> new nodes.Selector(x),
+
+ selector = (simpleselector | delim)+:x -> x.filter(function (selector) { return selector !== ',' }),
+
+ declaration = property:x ':' value:y -> new nodes.Declaration(x, y),
+
+ filterp = (seq('-filter') | seq('_filter') | seq('*filter') | seq('-ms-filter') | seq('filter')):t sc*
+ -> new nodes.Ident(t),
+
+ progid = sc* seq('progid:DXImageTransform.Microsoft.'):x letter+:y '(' (m_string | m_comment | ~')' char)+:z ')' sc*
+ -> new nodes.Literal(x + y.join('') + '(' + z.join('') + ')'),
+
+ filterv = progid+:x -> x,
+
+ filter = filterp:x ':' filterv:y -> new nodes.Declaration(p, v),
+
+ property = (ident | variable):x sc* -> x.toString(),
+
+ important = '!' sc* seq('important') -> new nodes.Literal('!important'),
+
+ primary = percentage | dimension | number,
+
+ unary = ('-' | '+'):op primary:x -> x.operate('*', new nodes.Dimension(op + 1))
+ | primary,
+
+ multiplicative = multiplicative:x sc+ ('*' | '/' | '%'):op sc+ unary:y -> new nodes.BinOp(op, x, y)
+ | unary,
+
+ additive = additive:x sc+ ('+' | '-'):op sc+ multiplicative:y -> new nodes.BinOp(op, x, y)
+ | multiplicative,
+
+ expression = additive,
+
+ operator = ('/' | ',' | ':' | '='):x -> new nodes.Literal(x),
+
+ uri = seq('url(') sc* string:x sc* ')' -> new nodes.Call('url', new nodes.Arguments(false, [x]))
+ | seq('url(') sc* (~')' ~m_w char)*:x sc* ')'
+ -> new nodes.Call('url', new nodes.Arguments(false, [new nodes.Literal(x.join(''))])),
+
+ value = (sc | vhash | any | block | atkeyword | operator | important)+:x
+ -> BOSSParser.createExpression( BOSSParser.filter(x) ),
+
+ funktion = ident:x '(' functionBody:y ')' -> new nodes.Call(x.name, y),
+
+ functionBody = (tset | clazz)*:x -> BOSSParser.createExpression( BOSSParser.filter(x) , true),
+
+ braces = '(' tset*:x ')' -> '(' + x.join('') + ')'
+ | '[' tset*:x ']' -> '[' + x.join('') + ']',
+
+// Don't reuse CSS-grammar elements to parse JS-grammar basics!
+
+ jsLT = '\n' | '\r',
+
+ jsComment = jsMLComment | jsSLComment,
+
+ jsMLComment = ``/*'' (~``*/'' char)*:x ``*/'' -> ('/*' + x.join('') + '*/'),
+
+ jsSLComment = ``//'' (~jsLT char)*:x -> ('//' + x.join('')),
+
+ jsString = '"' jsDSChar*:x '"' -> ('"' + x.join('') + '"')
+ | '\'' jsSSChar*:x '\'' -> ('\'' + x.join('') + '\''),
+
+ jsDSChar = ~'"' ~'\\' ~jsLT char
+ | jsEscapeChar
+ | jsLineContinuation,
+
+ jsSSChar = ~'\'' ~'\\' ~jsLT char
+ | jsEscapeChar
+ | jsLineContinuation,
+
+ jsLineContinuation = '\\' jsLT*:x -> ('\\' + x.join('')),
+
+ jsEscapeChar = '\\' char:x -> ('\\' + x),
+
+ jsInBraceChar = ~'(' ~')' char:x -> x,
+
+ jsBracesContent = (jsComment | jsString | jsEscapeChar | jsInBraceChar)+:x -> x.join(''),
+
+ functionExpressionBody = '(' jsBracesContent*:x (
+ functionExpressionBody:y jsBracesContent*:z -> (y + z.join(''))
+ )*:xx
+ ')' -> ('(' + x.join('') + xx.join('') + ')')
+ | jsBracesContent*:x functionExpressionBody:y jsBracesContent*:z -> (x.join('') + y + z.join(''))
+ | jsBracesContent+:x -> x.join(''),
+
+ functionExpression = ``expression('' functionExpressionBody*:x ')' -> 'expression(' + x.join('') + ')',
+
+ any = braces | string | expression | uri | functionExpression | funktion | ident | variable
+}
+
+BOSSParser.concat = function() {
+ var x = [];
+ for (var i in arguments) {
+ x = x.concat(arguments[i]);
+ };
+
+ return x;
+};
+
+// CSS 2.1 / 4.1.1 Tokenization / macro section
+
+// [_a-z]|{nonascii}|{escape}
+BOSSParser._m_nmstart = function(x) {
+ return /^[_a-zA-Z\*]+$/.test(x) || this._m_escape(x);
+};
+
+// \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
+BOSSParser._m_unicode = function(x) {
+ return /^\\[0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?$/.test(x);
+};
+
+// {unicode}|\\[^\n\r\f0-9a-f]
+BOSSParser._m_escape = function(x) {
+ return this._m_unicode(x) || /^\\[^\n\r\f0-9a-fA-F]+$/.test(x);
+}
+
+// [_a-z0-9-]|{nonascii}|{escape}
+BOSSParser._m_nmchar = function(x) {
+ return /^[_a-zA-Z0-9\-]+$/.test(x) || this._m_escape(x);
+};
+
+// [a-z0-9]|{nonascii}|{escape}
+BOSSParser._m_nmchar2 = function(x) {
+ return /^[a-zA-Z0-9]+$/.test(x) || this._m_escape(x);
+};
+
+// [\n\r\f]
+BOSSParser._m_nl = function(x) {
+ return /^[\n\r\f]+$/.test(x);
+};
+
+// [ \t\r\n\f]*
+BOSSParser._m_w = function(x) {
+ return /^[ \t\r\n\f]+$/.test(x);
+};
+
+BOSSParser.createExpression = function (x, isArgs) {
+ var ctor = isArgs ? 'Arguments' : 'Expression',
+ expr = new nodes[ctor],
+ list = isArgs ? new nodes[ctor](true) : undefined;
+
+ x.forEach(function (node) {
+ if (node.value === ',') {
+ list = list || new nodes[ctor](true);
+ list.push(expr);
+ expr = new nodes.Expression;
+ return;
+ }
+ expr.push(node);
+ })
+
+ list && list.push(expr);
+
+ return list || expr;
+}
+
+BOSSParser.filter = function (arr) {
+ return arr.filter(function (any) { return !(typeof any === 'string' && /^[\n\s]+$/.test(any)) })
+}
View
51 src/boss/parser.ometajs
@@ -1,51 +0,0 @@
-var CSSParser = require('../css/parser').CSSParser;
-
-ometa BOSSParser <: CSSParser {
-
- statement = definition | ruleset | atrule | assignment,
-
- definition = ident:x '(' functionBody:y ')' sc* block:z -> [#definition, x, y, z],
-
- string = m_string:x -> [#string, x.slice(1, -1), x[0]],
-
- variable = '$' ident:x -> [#variable, x],
-
- combinator = ('+' | '>' | '~' | '&'):x -> [#combinator, x],
-
- property = (ident | variable):x sc* -> [#property, x],
-
- assignment = property:p '=' value:v decldelim? sc* -> [#assignment, p, v],
-
- important = '!' sc* seq('important') -> [#important],
-
- primary = percentage | dimension | number,
-
- unary = ('-' | '+'):op primary:x -> [#unary, [#operator, op], x]
- | primary,
-
- multiplicative = multiplicative:x sc+ ('*' | '/' | '%'):op sc+ unary:y -> [#binary, [#operator, op], x, y]
- | unary,
-
- additive = additive:x sc+ ('+' | '-'):op sc+ multiplicative:y -> [#binary, [#operator, op], x, y]
- | multiplicative,
-
- expression = additive,
-
- nthselector = nthf:x '(' (sc | ('+' | '-'):op -> [#operator, op] | nth)*:y ')' -> [#nthselector, [#ident, x]].concat(y),
-
- blockdecl = sc* (filter | declaration):x decldelim? sc* -> [x]
- | sc* ruleset:x sc* -> [x]
- | sc* decldelim sc* -> []
- | sc+:s0 -> [],
-
- uri = seq('url(') sc* string:x sc* ')' -> CSSParser.concat([#uri], [x])
- | seq('url(') sc* (~')' ~m_w char)*:x sc* ')' -> CSSParser.concat([#uri], [[#raw, x.join('')]]),
-
- pseudoc = ':' (pseudof | ident):x -> [#pseudoc, x],
-
- pseudof = ident:x '(' pseudofBody:y ')' -> [#funktion, x, y],
-
- pseudofBody = (simpleselector)*:x -> [#functionBody].concat(x),
-
- any = braces | string | expression | uri | functionExpression | funktion | ident | variable
-}
View
92 src/boss/transformer.ometajs
@@ -1,92 +0,0 @@
-var CSSTransformer = require('../css/transformer').CSSTransformer;
-
-ometa BOSSTransformer <: CSSTransformer {
-
- any = before
- | ident
- | atkeyword
- | string
- | shash
- | vhash
- | number
- | percentage
- | dimension
- | cdo
- | cdc
- | decldelim
- | s
- | attrselector
- | attrib
- | nth
- | nthselector
- | namespace
- | clazz
- | pseudoe
- | pseudoc
- | delim
- | stylesheet
- | atruleb
- | atrules
- | atrulerq
- | atrulers
- | atruler
- | block
- | ruleset
- | combinator
- | simpleselector
- | selector
- | declaration
- | property
- | important
- | binary
- | unary
- | operator
- | braces
- | value
- | progid
- | filterv
- | filter
- | comment
- | uri
- | raw
- | functionBody
- | funktion
- | functionExpression
- | definition
- | assignment
- | variable
- | after,
-
- assignment = ['assignment':t any:x any:y] -> [t, x, y],
-
- definition = ['definition':t any:x any:y any:z] -> [t, x, y, z],
-
- binary = ['binary':t any:o any:x any:y] -> [t, o, x, y],
-
- ruleset = ['ruleset':t any:x any:y] -> [t, x, y],
-
- unary = ['unary':t any:o any:x] -> [t, o, x],
-
- variable = ['variable':t any:v] -> [t, v],
-
- string = ['string':t :x :y] -> [t, x, y],
-
- stylesheet = ['stylesheet':t anys:x] -> [t].concat( filter(x) ),
-
- atrulers = ['atrulers':t anys:x] -> [t].concat( filter(x) ),
-
- value = ['value':t anys:x] -> [t].concat( filter(x) ),
-
- important = ['important':t] -> [t],
-
- property = ['property':t anys:x] -> [t].concat( filter(x) ),
-
- progid = ['progid':t anys:x] -> [t].concat( filter(x) ),
-
- functionBody = ['functionBody':t anys:x] -> [t].concat( filter(x) )
-
-}
-
-var filter = function (arr) {
- return arr.filter(function (any) { return any[0] !== 's' })
-}
View
150 src/boss/translator.ometajs
@@ -1,150 +0,0 @@
-var CSSTranslator = require("../css/translator").CSSTranslator;
-
-var nodes = require("../nodes");
-
-ometa BOSSTranslator <: CSSTranslator {
-
- any = before
- | ident
- | atkeyword
- | string
- | shash
- | vhash
- | number
- | percentage
- | dimension
- | cdo
- | cdc
- | decldelim
- | s
- | attrselector
- | attrib
- | nth
- | nthselector
- | namespace
- | clazz
- | pseudoe
- | pseudoc
- | delim
- | stylesheet
- | atruleb
- | atrules
- | atrulerq
- | atrulers
- | atruler
- | block
- | ruleset
- | combinator
- | simpleselector
- | selector
- | declaration
- | property
- | important
- | binary
- | unary
- | operator
- | braces
- | value
- | progid
- | filterv
- | filter
- | comment
- | uri
- | raw
- | functionBody
- | funktion
- | functionExpression
- | definition
- | assignment
- | variable
- | after,
-
- assignment = ['assignment' any:x any:y] -> new nodes.Ident(x.trim(), y),
-
- clazz = ['clazz' any:x] -> '.' + x,
-
- vhash = ['vhash' :x] -> new nodes.Color(x),
-
- dimension = ['dimension' any:x any:y] -> new nodes.Dimension(x, y),
-
- percentage = ['percentage' any:x] -> new nodes.Dimension(x, '%'),
-
- number = ['number' :x] -> new nodes.Dimension(x),
-
- funktion = ['funktion' any:x any:y] -> new nodes.Call(x, y),
-
- definition = ['definition' any:x any:y any:z] -> new nodes.Definition(x.name, y, z),
-
- binary = ['binary' any:o any:x any:y] -> new nodes.BinOp(o, x, y),
-
- unary = ['unary' any:o any:x] -> x.operate('*', new nodes.Dimension(o + 1)),
-
- variable = ['variable' any:x] -> x,
-
- comment = ['comment' :x] -> new nodes.Comment(x),
-
- string = ['string' :x :y] -> new nodes.String(x, y),
-
- raw = ['raw' :x] -> new nodes.Literal(x),
-
- uri = ['uri' any:x] -> new nodes.Call('url', new nodes.Arguments(false, [x])),
-
- stylesheet = ['stylesheet' anys:x] -> new nodes.Stylesheet(x),
-
- block = ['block' anys:x] -> new nodes.Block(x),
-
- declaration = ['declaration' any:p any:v] -> new nodes.Declaration(p, v),
-
- simpleselector = ['simpleselector' anys:x] -> new nodes.Selector(x),
-
- selector = ['selector' anys:x] -> x.filter(function (selector) { return selector !== ',' }),
-
- ruleset = ['ruleset' any:x any:y] -> new nodes.Ruleset(x, y),
-
- ident = ['ident' :x] -> new nodes.Ident(x),
-
- pseudoe = ['pseudoe' any:x] -> '::' + x,
-
- pseudoc = ['pseudoc' any:x] -> ':' + x,
-
- value = ['value' anys:x] -> createExpression(x),
-
- functionBody = ['functionBody' anys:x] -> createExpression(x, true),
-
- operator = ['operator' :x] -> new nodes.Literal(x),
-
- important = ['important'] -> new nodes.Literal('!important'),
-
- atruler = ['atruler' any:x any:y any:z] -> new nodes.Atrule(x + y, z),
-
- atrulers = ['atrulers' anys:x] -> new nodes.Block(x),
-
- atrules = ['atrules' anys:x] -> new nodes.Atrule(x.join('')),
-
- progid = ['progid' any:x] -> x,
-
- filter = ['filter' any:p any:v] -> new nodes.Declaration(p, v),
-
- filterv = ['filterv' any:x] -> x,
-
-}
-
-var createExpression = function (x, isArgs) {
- var ctor = isArgs ? 'Arguments' : 'Expression',
- expr = new nodes[ctor],
- list = isArgs ? new nodes[ctor](true) : undefined;
-
- x.forEach(function (node) {
- if (node.value === ',') {
- list = list || new nodes[ctor](true);
- list.push(expr);
- expr = new nodes.Expression;
- return;
- }
- expr.push(node);
- })
-
- list && list.push(expr);
-
- return list || expr;
-}
View
244 src/css/parser.ometajs
@@ -1,244 +0,0 @@
-ometa CSSParser {
-
- // Macros
-
- m_comment = seq('/*') (~seq('*/') char)*:x seq('*/') -> ('/*' + x.join('') + '*/'),
-
- m_ident = '-' (char:x m_nmstart(x) -> x):x (escape | :y m_nmchar(y) -> y)*:z -> ('-' + x + z.join(''))
- | (char:x m_nmstart(x) -> x):x (escape | :y m_nmchar(y) -> y)*:z -> (x + z.join('')),
-
- escape = '\\' char:x -> ('\\' + x),
-
- m_name = (:x m_nmchar(x) -> x)+:xx -> xx.join(''),
-
- m_name2 = (:x m_nmchar2(x) -> x)+:xx -> xx.join(''),
-
- m_number = digit+:x '.' digit+:y -> (x.join('') + '.' + y.join(''))
- | '.' digit+:x -> ('.' + x.join(''))
- | digit+:x -> x.join(''),
-
- m_string = '"' (m_string_nl1 | ~'"' char)*:s '"' -> ('"' + s.join('') + '"')
- | '\'' (m_string_nl2 | ~'\'' char)*:s '\'' -> ('\'' + s.join('') + '\''),
-
- m_string_nl1 = ('\n' | '\r' | seq('\\"')):x -> x,
- m_string_nl2 = ('\n' | '\r' | seq('\\\'')):x -> x,
-
- m_nmstart :x = ?CSSParser._m_nmstart(x),
- m_unicode :x = ?CSSParser._m_unicode(x),
- m_escape :x = ?CSSParser._m_escape(x),
- m_nmchar :x = ?CSSParser._m_nmchar(x),
- m_nmchar2 :x = ?CSSParser._m_nmchar2(x),
- m_nl :x = ?CSSParser._m_nl(x),
- m_w :x = ?CSSParser._m_w(x),
-
- // Tokens
-
- ident = m_ident:x -> [#ident, x],
-
- atkeyword = '@' ident:x -> [#atkeyword, x],
-
- string = m_string:x -> [#string, x],
-
- shash = '#' m_name:x -> [#shash, x],
-
- vhash = '#' m_name2:x -> [#vhash, x],
-
- number = m_number:x -> [#number, x],
-
- percentage = number:x '%' -> [#percentage, x],
-
- dimension = number:x m_name2:y -> [#dimension, x, [#ident, y]],
-
- cdo = seq('<!--') -> [#cdo],
- cdc = seq('-->') -> [#cdc],
-
- s = (:x m_w(x) -> x)+:xx -> [#s, xx.join('')],
-
- attrselector = (seq('=') | seq('~=') | seq('^=') | seq('$=') | seq('*=') | seq('|=')):x -> [#attrselector, x],
-
- delim = ',' -> [#delim],
-
- comment = seq('/*') (~seq('*/') char)*:x seq('*/') -> [#comment, x.join('')],
-
- sc = s | comment,
-
- tset = vhash | any | sc | operator,
-
- stylesheet = (cdo | cdc | sc | statement)*:x -> CSSParser.concat([#stylesheet], x),
-
- statement = ruleset | atrule,
-
- atruleb = atkeyword:ak tset*:ap block:b -> CSSParser.concat([#atruleb, ak], ap, [b]),
-
- atrules = atkeyword:ak tset*:ap ';' -> CSSParser.concat([#atrules, ak], ap),
-
- atrulerq = tset*:ap -> [#atrulerq].concat(ap),
-
- atrulers = sc*:s0 ruleset*:r sc*:s1 -> CSSParser.concat([#atrulers], s0, r, s1),
-
- atruler = atkeyword:ak atrulerq:x '{' atrulers:y '}' -> [#atruler, ak, x, y],
-
- atrule = atruler | atruleb | atrules,
-
- blockdecl = sc*:s0 (filter | declaration):x decldelim:y sc*:s1 -> CSSParser.concat(s0, [x], [y], s1)
- | sc*:s0 (filter | declaration):x sc*:s1 -> CSSParser.concat(s0, [x], s1)
- | sc*:s0 decldelim:x sc*:s1 -> CSSParser.concat(s0, [x], s1)
- | sc+:s0 -> s0,
-
- decldelim = ';' -> [#decldelim],
-
- block = '{' blockdecl*:x '}' -> CSSParser.concatContent([#block], x),
-
- ruleset = selector*:x block:y -> CSSParser.concat([#ruleset], x, [y]),
-
- combinator = ('+' | '>' | '~'):x -> [#combinator, x],
-
- attrib = '[' sc*:s0 ident:x sc*:s1 attrselector:a sc*:s2 (ident | string):y sc*:s3 ']' -> CSSParser.concat([#attrib], s0, [x], s1, [a], s2, [y], s3)
- | '[' sc*:s0 ident:x sc*:s1 ']' -> CSSParser.concat([#attrib], s0, [x], s1),
-
- clazz = '.' ident:i -> [#clazz, i],
-
- pseudoe = seq('::') ident:x -> [#pseudoe, x],
-
- pseudoc = ':' (funktion | ident):x -> [#pseudoc, x],
-
- pseudo = pseudoe | pseudoc,
-
- nthf = ':' seq('nth-'):x (seq('child') | seq('last-child') | seq('of-type') | seq('last-of-type')):y -> (x + y),
-
- nth = (digit | 'n')+:x -> [#nth, x.join('')]
- | (seq('even') | seq('odd')):x -> [#nth, x],
-
- nthselector = nthf:x '(' (sc | unary | nth)*:y ')' -> [#nthselector, [#ident, x]].concat(y),
-
- namespace = '|' -> [#namespace],
-
- simpleselector = (nthselector | combinator | attrib | pseudo | clazz | shash | any | sc | namespace)+:x -> CSSParser.concatContent([#simpleselector], [x]),
-
- selector = (simpleselector | delim)+:x -> CSSParser.concat([#selector], x),
-
- declaration = property:x ':' value:y -> [#declaration, x, y],
-
- filterp = (seq('-filter') | seq('_filter') | seq('*filter') | seq('-ms-filter') | seq('filter')):t sc*:s0 -> CSSParser.concat([#property, [#ident, t]], s0),
-
- progid = sc*:s0 seq('progid:DXImageTransform.Microsoft.'):x letter+:y '(' (m_string | m_comment | ~')' char)+:z ')' sc*:s1
- -> CSSParser.concat([#progid], s0, [[#raw, x + y.join('') + '(' + z.join('') + ')']], s1),
-
- filterv = progid+:x -> [#filterv].concat(x),
-
- filter = filterp:x ':' filterv:y -> [#filter, x, y],
-
- property = ident:x sc*:s0 -> CSSParser.concat([#property, x], s0),
-
- important = '!' sc*:s0 seq('important') -> [#important].concat(s0),
-
- unary = ('-' | '+'):x -> [#unary, x],
-
- operator = ('/' | ',' | ':' | '='):x -> [#operator, x],
-
- uri = seq('url(') sc*:s0 string:x sc*:s1 ')' -> CSSParser.concat([#uri], s0, [x], s1)
- | seq('url(') sc*:s0 (~')' ~m_w char)*:x sc*:s1 ')' -> CSSParser.concat([#uri], s0, [[#raw, x.join('')]], s1),
-
- value = (sc | vhash | any | block | atkeyword | operator | important)+:x -> CSSParser.concat([#value], x),
-
- funktion = ident:x '(' functionBody:y ')' -> [#funktion, x, y],
-
- functionBody = (tset | clazz)*:x -> [#functionBody].concat(x),
-
- braces = '(' tset*:x ')' -> CSSParser.concat([#braces, '(', ')'], x)
- | '[' tset*:x ']' -> CSSParser.concat([#braces, '[', ']'], x),
-
-// Don't reuse CSS-grammar elements to parse JS-grammar basics!
-
- jsLT = '\n' | '\r',
-
- jsComment = jsMLComment | jsSLComment,
-
- jsMLComment = ``/*'' (~``*/'' char)*:x ``*/'' -> ('/*' + x.join('') + '*/'),
-
- jsSLComment = ``//'' (~jsLT char)*:x -> ('//' + x.join('')),
-
- jsString = '"' jsDSChar*:x '"' -> ('"' + x.join('') + '"')
- | '\'' jsSSChar*:x '\'' -> ('\'' + x.join('') + '\''),
-
- jsDSChar = ~'"' ~'\\' ~jsLT char
- | jsEscapeChar
- | jsLineContinuation,
-
- jsSSChar = ~'\'' ~'\\' ~jsLT char
- | jsEscapeChar
- | jsLineContinuation,
-
- jsLineContinuation = '\\' jsLT*:x -> ('\\' + x.join('')),
-
- jsEscapeChar = '\\' char:x -> ('\\' + x),
-
- jsInBraceChar = ~'(' ~')' char:x -> x,
-
- jsBracesContent = (jsComment | jsString | jsEscapeChar | jsInBraceChar)+:x -> x.join(''),
-
- functionExpressionBody = '(' jsBracesContent*:x (
- functionExpressionBody:y jsBracesContent*:z -> (y + z.join(''))
- )*:xx
- ')' -> ('(' + x.join('') + xx.join('') + ')')
- | jsBracesContent*:x functionExpressionBody:y jsBracesContent*:z -> (x.join('') + y + z.join(''))
- | jsBracesContent+:x -> x.join(''),
-
- functionExpression = ``expression('' functionExpressionBody*:x ')' -> [#functionExpression, x.join('')],
-
- any = braces | string | percentage | dimension | number | uri | functionExpression | funktion | ident | unary
-}
-
-CSSParser.concatContent = function(x, y) {
- y.forEach(function(e) {
- x = x.concat(e);
- });
-
- return x;
-};
-
-CSSParser.concat = function() {
- var x = [];
- for (var i in arguments) {
- x = x.concat(arguments[i]);
- };
-
- return x;
-};
-
-// CSS 2.1 / 4.1.1 Tokenization / macro section
-
-// [_a-z]|{nonascii}|{escape}
-CSSParser._m_nmstart = function(x) {
- return /^[_a-zA-Z\*]+$/.test(x) || this._m_escape(x);
-};
-
-// \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
-CSSParser._m_unicode = function(x) {
- return /^\\[0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?$/.test(x);
-};
-
-// {unicode}|\\[^\n\r\f0-9a-f]
-CSSParser._m_escape = function(x) {
- return this._m_unicode(x) || /^\\[^\n\r\f0-9a-fA-F]+$/.test(x);
-}
-
-// [_a-z0-9-]|{nonascii}|{escape}
-CSSParser._m_nmchar = function(x) {
- return /^[_a-zA-Z0-9\-]+$/.test(x) || this._m_escape(x);
-};
-
-// [a-z0-9]|{nonascii}|{escape}
-CSSParser._m_nmchar2 = function(x) {
- return /^[a-zA-Z0-9]+$/.test(x) || this._m_escape(x);
-};
-
-// [\n\r\f]
-CSSParser._m_nl = function(x) {
- return /^[\n\r\f]+$/.test(x);
-};
-
-// [ \t\r\n\f]*
-CSSParser._m_w = function(x) {
- return /^[ \t\r\n\f]+$/.test(x);
-};
View
152 src/css/transformer.ometajs
@@ -1,152 +0,0 @@
-ometa CSSTransformer {
- anys = any*,
- before = [],
- after = [],
-
- any = before
- | ident
- | atkeyword
- | string
- | shash
- | vhash
- | number
- | percentage
- | dimension
- | cdo
- | cdc
- | decldelim
- | s
- | attrselector
- | attrib
- | nth
- | nthselector
- | namespace
- | clazz
- | pseudoe
- | pseudoc
- | delim
- | stylesheet
- | atruleb
- | atrules
- | atrulerq
- | atrulers
- | atruler
- | block
- | ruleset
- | combinator
- | simpleselector
- | selector
- | declaration
- | property
- | important
- | unary
- | operator
- | braces
- | value
- | progid
- | filterv
- | filter
- | comment
- | uri
- | raw
- | functionBody
- | funktion
- | functionExpression
- | after,
-
- ident = ['ident':t :x] -> [t, x],
-
- atkeyword = ['atkeyword':t any:x] -> [t, x],
-
- string = ['string':t :x] -> [t, x],
-
- shash = ['shash':t :x] -> [t, x],
-
- vhash = ['vhash':t :x] -> [t, x],
-
- number = ['number':t :x] -> [t, x],
-
- percentage = ['percentage':t any:x] -> [t, x],
-
- dimension = ['dimension':t any:x any:y] -> [t, x, y],
-
- cdo = ['cdo':t] -> [t],
-
- cdc = ['cdc':t] -> [t],
-
- decldelim = ['decldelim':t] -> [t],
-
- s = ['s':t :x] -> [t, x],
-
- attrselector = ['attrselector':t :x] -> [t, x],
-
- attrib = ['attrib':t anys:x] -> [t].concat(x),
-
- nth = ['nth':t :x] -> [t, x],
-
- nthselector = ['nthselector':t any:x anys:y] -> [t, x].concat(y),
-
- namespace = ['namespace':t] -> [t],
-
- clazz = ['clazz':t :x] -> [t, x],
-
- pseudoe = ['pseudoe':t :x] -> [t, x],
-
- pseudoc = ['pseudoc':t :x] -> [t, x],
-
- delim = ['delim':t] -> [t],
-
- stylesheet = ['stylesheet':t anys:x] -> [t].concat(x),
-
- atruleb = ['atruleb':t anys:x] -> [t].concat(x),
-
- atrules = ['atrules':t anys:x] -> [t].concat(x),
-
- atrulerq = ['atrulerq':t anys:x] -> [t].concat(x),
-
- atrulers = ['atrulers':t anys:x] -> [t].concat(x),
-
- atruler = ['atruler':t anys:x] -> [t].concat(x),
-
- block = ['block':t anys:x] -> [t].concat(x),
-
- ruleset = ['ruleset':t anys:x] -> [t].concat(x),
-
- combinator = ['combinator':t :x] -> [t, x],
-
- simpleselector = ['simpleselector':t anys:x] -> [t].concat(x),
-
- selector = ['selector':t anys:x] -> [t].concat(x),
-
- declaration = ['declaration':t any:p any:v] -> [t, p, v],
-
- property = ['property':t anys:x] -> [t].concat(x),
-
- important = ['important':t anys:x] -> [t].concat(x),
-
- unary = ['unary':t :x] -> [t, x],
-
- operator = ['operator':t :x] -> [t, x],
-
- braces = ['braces':t :x :y anys:z] -> [t, x, y].concat(z),
-
- value = ['value':t anys:x] -> [t].concat(x),
-
- progid = ['progid':t anys:x] -> [t].concat(x),
-
- filterv = ['filterv':t anys:x] -> [t].concat(x),
-
- filter = ['filter':t any:p any:v] -> [t, p, v],
-
- comment = ['comment':t :x] -> [t, x],
-
- uri = ['uri':t anys:x] -> [t].concat(x),
-
- raw = ['raw':t :x] -> [t, x],
-
- functionBody = ['functionBody':t anys:x] -> [t].concat(x),
-
- funktion = ['funktion':t any:x any:y] -> [t, x, y],
-
- functionExpression = ['functionExpression':t :x] -> [t, x]
-}
View
152 src/css/translator.ometajs
@@ -1,152 +0,0 @@
-ometa CSSTranslator {
- anys = any*,
- before = [],
- after = [],
-
- any = before
- | ident
- | atkeyword
- | string
- | shash
- | vhash
- | number
- | percentage
- | dimension
- | cdo
- | cdc
- | decldelim
- | s
- | attrselector
- | attrib
- | nth
- | nthselector
- | namespace
- | clazz
- | pseudoe
- | pseudoc
- | delim
- | stylesheet
- | atruleb
- | atrules
- | atrulerq
- | atrulers
- | atruler
- | block
- | ruleset
- | combinator
- | simpleselector
- | selector
- | declaration
- | property
- | important
- | unary
- | operator
- | braces
- | value
- | progid
- | filterv
- | filter
- | comment
- | uri
- | raw
- | functionBody
- | funktion
- | functionExpression
- | after,
-
- ident = ['ident' :x] -> x,
-
- atkeyword = ['atkeyword' any:x] -> ('@' + x),
-
- string = ['string' :x] -> x,
-
- shash = ['shash' :x] -> ('#' + x),
-
- vhash = ['vhash' :x] -> ('#' + x),
-
- number = ['number' :x] -> x,
-
- percentage = ['percentage' any:x] -> (x + '%'),
-
- dimension = ['dimension' any:x any:y] -> (x + y),
-
- cdo = ['cdo'] -> '<!--',
-
- cdc = ['cdc'] -> '-->',
-
- decldelim = ['decldelim'] -> ';',
-
- s = ['s' :x] -> x,
-
- attrselector = ['attrselector' :x] -> x,
-
- attrib = ['attrib' anys:x] -> ('[' + x.join('') + ']'),
-
- nth = ['nth' :x] -> x,
-
- nthselector = ['nthselector' any:x anys:y] -> (':' + x + '(' + y.join('') + ')'),
-
- namespace = ['namespace'] -> '|',
-
- clazz = ['clazz' any:x] -> ('.' + x),
-
- pseudoe = ['pseudoe' anys:x] -> ('::' + x.join('')),
-
- pseudoc = ['pseudoc' anys:x] -> (':' + x.join('')),
-
- delim = ['delim'] -> ',',
-
- stylesheet = ['stylesheet' anys:x] -> x.join(''),
-
- atruleb = ['atruleb' anys:x] -> x.join(''),
-
- atrules = ['atrules' anys:x] -> (x.join('') + ';'),
-
- atrulerq = ['atrulerq' anys:x] -> x.join(''),
-
- atrulers = ['atrulers' anys:x] -> x.join(''),
-
- atruler = ['atruler' any:x any:y any:z] -> (x + y + '{' + z + '}'),
-
- block = ['block' anys:x] -> ('{' + x.join('') + '}'),
-
- ruleset = ['ruleset' anys:x] -> x.join(''),
-
- combinator = ['combinator' :x] -> x,
-
- simpleselector = ['simpleselector' anys:x] -> x.join(''),
-
- selector = ['selector' anys:x] -> x.join(''),
-
- declaration = ['declaration' any:p any:v] -> (p + ':' + v),
-
- property = ['property' anys:x] -> x.join(''),
-
- important = ['important' anys:x] -> ('!' + x.join('') + 'important'),
-
- unary = ['unary' :x] -> x,
-
- operator = ['operator' :x] -> x,
-
- braces = ['braces' :x :y anys:z] -> (x + z.join('') + y),
-
- value = ['value' anys:x] -> x.join(''),
-
- progid = ['progid' anys:x] -> x.join(''),
-
- filterv = ['filterv' anys:x] -> x.join(''),
-
- filter = ['filter' any:p any:v] -> (p + ':' + v),
-
- comment = ['comment' :x] -> ('/*' + x + '*/'),
-
- uri = ['uri' anys:x] -> ('url(' + x.join('') + ')'),
-
- raw = ['raw' :x] -> x,
-
- functionBody = ['functionBody' anys:x] -> x.join(''),
-
- funktion = ['funktion' any:x any:y] -> (x + '(' + y + ')'),
-
- functionExpression = ['functionExpression' :x] -> ('expression(' + x + ')')
-}
View
3  test/media.boss
@@ -1,5 +1,6 @@
@media all and (min-width:500px) {
body {
- font-size: 1.5em
+ font-size: 1.5em;
+ margin: 1 * 1px
}
}
View
1  test/media.css
@@ -1,5 +1,6 @@
@media all and (min-width:500px) {
body {
font-size: 1.5em;
+ margin: 1px;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.