diff --git a/VERSION b/VERSION index 53b61ec..ce4f5af 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.6 \ No newline at end of file +0.3.7 \ No newline at end of file diff --git a/dist/siml.all.js b/dist/siml.all.js index 021a72e..26363bc 100644 --- a/dist/siml.all.js +++ b/dist/siml.all.js @@ -1,594 +1,594 @@ /** * SIML (c) James Padolsey 2013 - * @version 0.3.6 + * @version 0.3.7 * @license https://github.com/padolsey/SIML/blob/master/LICENSE-MIT * @info http://github.com/padolsey/SIML */ -(function() { +(function() { -var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; -(function() { - - 'use strict'; - - var push = [].push; - var unshift = [].unshift; - - var DEFAULT_TAG = 'div'; - var DEFAULT_INDENTATION = ' '; - - var SINGULAR_TAGS = { - input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, - source: 1, area: 1, base: 1, col: 1 - }; - - var DEFAULT_DIRECTIVES = { - _fillHTML: { - type: 'CONTENT', - make: function(_, children, t) { - return t; - } - }, - _default: { - type: 'CONTENT', - make: function(dir) { - throw new Error('SIML: Directive not resolvable: ' + dir); - } - } - }; - - var DEFAULT_ATTRIBUTES = { - _default: { - type: 'ATTR', - make: function(attrName, value) { - if (value == null) { - return attrName; - } - return attrName + '="' + value + '"'; - } - }, - text: { - type: 'CONTENT', - make: function(_, t) { - return t; - } - } - }; - - var DEFAULT_PSEUDOS = { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input') { - return 'type="' + name + '"'; - } - console.warn('Unknown pseudo class used:', name) - } - } - } - - var objCreate = Object.create || function (o) { - function F() {} - F.prototype = o; - return new F(); - }; - - function isArray(a) { - return {}.toString.call(a) === '[object Array]'; - } - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - function trim(s) { - return String(s).replace(/^\s\s*|\s\s*$/g, ''); - } - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - if (isArray(arr[i])) { - out[i] = deepCopyArray(arr[i]); - } else { - out[i] = arr[i]; - } - } - return out; - } - function defaults(defaults, obj) { - for (var i in defaults) { - if (!obj.hasOwnProperty(i)) { - obj[i] = defaults[i]; - } - } - return obj; - } - - function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { - return function ConfigurableProperty(args, config, parentElement, indentation) { - - this.parentElement = parentElement; - this.indentation = indentation; - - args = [].slice.call(args); - - var propName = args[0]; - var propArguments = args[1]; - var propChildren = args[2]; - - if (propChildren) { - propArguments.unshift(propChildren); - } - - propArguments.unshift(propName); - - var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; - if (!propMaker) { - propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; - } - - if (!propMaker) { - throw new Error('SIML: No fallback for' + args.join()); - } - - this.type = propMaker.type; - this.html = propMaker.make.apply(this, propArguments) || ''; - - }; - } - - function Element(spec, config, parentElement, indentation) { - - this.spec = spec; - this.config = config || {}; - this.parentElement = parentElement || this; - this.indentation = indentation || ''; - this.defaultIndentation = config.indent; - - this.tag = null; - this.id = null; - this.attrs = []; - this.classes = []; - this.pseudos = []; - this.prototypes = objCreate(parentElement && parentElement.prototypes || null); - - this.isSingular = false; - this.multiplier = 1; - - this.isPretty = config.pretty; - - this.htmlOutput = []; - this.htmlContent = []; - this.htmlAttributes = []; - - this.selector = spec[0]; - - this.make(); - this.processChildren(spec[1]); - this.collectOutput(); - - this.html = this.htmlOutput.join(''); - - } - - Element.prototype = { - - make: function() { - - var attributeMap = {}; - var selector = this.selector.slice(); - var selectorPortionType; - var selectorPortion; - - this.augmentPrototypeSelector(selector); - - for (var i = 0, l = selector.length; i < l; ++i) { - selectorPortionType = selector[i][0]; - selectorPortion = selector[i][1]; - switch (selectorPortionType) { - case 'Tag': - if (!this.tag) { - this.tag = selectorPortion; - } - break; - case 'Id': - this.id = selectorPortion; break; - case 'Attr': - var attrName = selectorPortion[0]; - var attr = [attrName, [selectorPortion[1]]]; - // Attributes can only be defined once -- latest wins - if (attributeMap[attrName] != null) { - this.attrs[attributeMap[attrName]] = attr; - } else { - attributeMap[attrName] = this.attrs.push(attr) - 1; - } - break; - case 'Class': - this.classes.push(selectorPortion); break; - case 'Pseudo': - this.pseudos.push(selectorPortion); break; - } - } - - this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); - this.isSingular = this.tag in SINGULAR_TAGS; - - if (this.id) { - this.htmlAttributes.push( - 'id="' + this.id + '"' - ); - } - - if (this.classes.length) { - this.htmlAttributes.push( - 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' - ); - } - - for (var i = 0, l = this.attrs.length; i < l; ++ i) { - this.processProperty('Attribute', this.attrs[i]); - } - - for (var i = 0, l = this.pseudos.length; i < l; ++ i) { - var p = this.pseudos[i]; - if (!isNaN(p[0])) { - this.multiplier = p[0]; - continue; - } - this.processProperty('Pseudo', p); - } - - }, - - collectOutput: function() { - - var indent = this.indentation; - var isPretty = this.isPretty; - var output = this.htmlOutput; - var attrs = this.htmlAttributes; - var content = this.htmlContent; - - output.push(indent + '<' + this.tag); - output.push(attrs.length ? ' ' + attrs.join(' ') : ''); - - if (this.isSingular) { - output.push('/>'); - } else { - - output.push('>'); - - if (content.length) { - isPretty && output.push('\n'); - output.push(content.join(isPretty ? '\n': '')); - isPretty && output.push('\n' + indent); - } - - output.push(''); - - } - - if (this.multiplier > 1) { - var all = output.join(''); - for (var m = this.multiplier - 1; m--;) { - output.push(isPretty ? '\n' : ''); - output.push(all); - } - } - - }, - - _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { - - var tail = excGroup[2]; - var exclusives = excGroup[1]; - - var branches = []; - - attachTail(excGroup, tail); - - for (var n = 0, nl = exclusives.length; n < nl; ++n) { - specChildren[specChildIndex] = exclusives[n]; // Mutate - var newBranch = deepCopyArray(this.spec); // Complete copy - specChildren[specChildIndex] = excGroup; // Return to regular - branches.push(newBranch); - } - - return branches; - - // attachTail - // Goes through children (equal candidacy) looking for places to append - // both the tailChild and tailSelector. Note: they may be placed in diff places - // as in the case of `(a 'c', b)>d` - function attachTail(start, tail, hasAttached) { - - var type = start[0]; - - var children = getChildren(start); - var tailChild = tail[0]; - var tailSelector = tail[1]; - var tailChildType = tail[2]; - - var hasAttached = hasAttached || { - child: false, - selector: false - }; - - if (hasAttached.child && hasAttached.selector) { - return hasAttached; - } - - if (children) { - for (var i = children.length; i-->0;) { - var child = children[i]; - - if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild - child = child[2][0]; - } - - if (tailChildType === 'sibling') { - var cChildren = getChildren(child); - if (!cChildren || !cChildren.length) { - // Add tailChild as sibling of child - children[i] = ['IncGroup', [ - child, - deepCopyArray(tailChild) - ]]; - hasAttached.child = true; //? - if (type === 'IncGroup') { - break; - } else { - continue; - } - } - } - hasAttached = attachTail(child, tail, { - child: false, - selector: false - }); - // Prevent descendants from being attached to more than one sibling - // e.g. a,b or a+b -- should only attach last one (i.e. b) - if (type === 'IncGroup' && hasAttached.child) { - break; - } - } - } - - if (!hasAttached.selector) { - if (start[0] === 'Element') { - if (tailSelector) { - push.apply(start[1][0], tailSelector); - } - hasAttached.selector = true; - } - } - - if (!hasAttached.child) { - if (children) { - if (tailChild) { - children.push(deepCopyArray(tailChild)); - } - hasAttached.child = true; - } - } - - return hasAttached; - } - - function getChildren(child) { - return child[0] === 'Element' ? child[1][1] : - child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? - child[1] : null; - } - }, - - processChildren: function(children) { - - var cl = children.length; - var i; - var childType; - - var exclusiveBranches = []; - - for (i = 0; i < cl; ++i) { - if (children[i][0] === 'ExcGroup') { - push.apply( - exclusiveBranches, - this._makeExclusiveBranches(children[i], children, i) - ); - } - } - - if (exclusiveBranches.length) { - - this.collectOutput = function(){}; - var html = []; - - for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { - var branch = exclusiveBranches[ei]; - html.push( - new (branch[0] === 'RootElement' ? RootElement : Element)( - branch, - this.config, - this.parentElement, - this.indentation - ).html - ); - } - - this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); - - } else { - for (i = 0; i < cl; ++i) { - var child = children[i][1]; - var childType = children[i][0]; - switch (childType) { - case 'Element': - this.processElement(child); - break; - case 'Prototype': - this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); - break; - case 'IncGroup': - this.processIncGroup(child); - break; - case 'ExcGroup': - throw new Error('SIML: Found ExcGroup in unexpected location'); - default: - this.processProperty(childType, child); - } - } - } - - }, - - processElement: function(spec) { - this.htmlContent.push( - new Generator.Element( - spec, - this.config, - this, - this.indentation + this.defaultIndentation - ).html - ); - }, - - processIncGroup: function(spec) { - this.processChildren(spec); - }, - - processProperty: function(type, args) { - // type = Attribute | Directive | Pseudo - var property = new Generator.properties[type]( - args, - this.config, - this, - this.indentation + this.defaultIndentation - ); - if (property.html) { - switch (property.type) { - case 'ATTR': - if (property.html) { - this.htmlAttributes.push(property.html); - } - break; - case 'CONTENT': - if (property.html) { - this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); - } - break; - } - } - }, - - augmentPrototypeSelector: function(selector) { - // Assume tag, if specified, to be first selector portion. - if (selector[0][0] !== 'Tag') { - return selector; - } - // Retrieve and unshift prototype selector portions: - unshift.apply(selector, this.prototypes[selector[0][1]] || []); - return selector; - } - }; - - function RootElement() { - Element.apply(this, arguments); - } - - RootElement.prototype = objCreate(Element.prototype); - RootElement.prototype.make = function(){ - // RootElement is just an empty space - }; - RootElement.prototype.collectOutput = function() { - this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; - }; - RootElement.prototype.processChildren = function() { - this.defaultIndentation = ''; - return Element.prototype.processChildren.apply(this, arguments); - }; - - function Generator(defaultGeneratorConfig) { - this.config = defaults(this.defaultConfig, defaultGeneratorConfig); - } - - Generator.escapeHTML = escapeHTML; - Generator.trim = trim; - Generator.isArray = isArray; - - Generator.Element = Element; - Generator.RootElement = RootElement; - - Generator.properties = { - Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), - Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), - Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) - }; - - Generator.prototype = { - - defaultConfig: { - pretty: true, - curly: false, - indent: DEFAULT_INDENTATION, - directives: {}, - attributes: {}, - pseudos: {}, - toTag: function(t) { - return t; - } - }, - - parse: function(spec, singleRunConfig) { - - singleRunConfig = defaults(this.config, singleRunConfig || {}); - - if (!singleRunConfig.pretty) { - singleRunConfig.indent = ''; - } - - if (!/^[\s\n\r]+$/.test(spec)) { - if (singleRunConfig.curly) { - // TODO: Find a nicer way of passing config to the PEGjs parser: - spec += '\n/*siml:curly=true*/'; - } - try { - spec = siml.PARSER.parse(spec); - } catch(e) { - if (e.line !== undefined && e.column !== undefined) { - throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); - } else { - throw new SyntaxError('SIML: ' + e.message); - } - } - } else { - spec = []; - } - - if (spec[0] === 'Element') { - return new Generator.Element( - spec[1], - singleRunConfig - ).html; - } - - return new Generator.RootElement( - ['RootElement', [['IncGroup', [spec]]]], - singleRunConfig - ).html; - } - - }; - - siml.Generator = Generator; - - siml.defaultGenerator = new Generator({ - pretty: true, - indent: DEFAULT_INDENTATION - }); - - siml.parse = function(s, c) { - return siml.defaultGenerator.parse(s, c); - }; - -}()); +var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; +(function() { + + 'use strict'; + + var push = [].push; + var unshift = [].unshift; + + var DEFAULT_TAG = 'div'; + var DEFAULT_INDENTATION = ' '; + + var SINGULAR_TAGS = { + input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, + source: 1, area: 1, base: 1, col: 1 + }; + + var DEFAULT_DIRECTIVES = { + _fillHTML: { + type: 'CONTENT', + make: function(_, children, t) { + return t; + } + }, + _default: { + type: 'CONTENT', + make: function(dir) { + throw new Error('SIML: Directive not resolvable: ' + dir); + } + } + }; + + var DEFAULT_ATTRIBUTES = { + _default: { + type: 'ATTR', + make: function(attrName, value) { + if (value == null) { + return attrName; + } + return attrName + '="' + value + '"'; + } + }, + text: { + type: 'CONTENT', + make: function(_, t) { + return t; + } + } + }; + + var DEFAULT_PSEUDOS = { + _default: { + type: 'ATTR', + make: function(name) { + if (this.parentElement.tag === 'input') { + return 'type="' + name + '"'; + } + console.warn('Unknown pseudo class used:', name) + } + } + } + + var objCreate = Object.create || function (o) { + function F() {} + F.prototype = o; + return new F(); + }; + + function isArray(a) { + return {}.toString.call(a) === '[object Array]'; + } + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + function trim(s) { + return String(s).replace(/^\s\s*|\s\s*$/g, ''); + } + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + if (isArray(arr[i])) { + out[i] = deepCopyArray(arr[i]); + } else { + out[i] = arr[i]; + } + } + return out; + } + function defaults(defaults, obj) { + for (var i in defaults) { + if (!obj.hasOwnProperty(i)) { + obj[i] = defaults[i]; + } + } + return obj; + } + + function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { + return function ConfigurableProperty(args, config, parentElement, indentation) { + + this.parentElement = parentElement; + this.indentation = indentation; + + args = [].slice.call(args); + + var propName = args[0]; + var propArguments = args[1]; + var propChildren = args[2]; + + if (propChildren) { + propArguments.unshift(propChildren); + } + + propArguments.unshift(propName); + + var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; + if (!propMaker) { + propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; + } + + if (!propMaker) { + throw new Error('SIML: No fallback for' + args.join()); + } + + this.type = propMaker.type; + this.html = propMaker.make.apply(this, propArguments) || ''; + + }; + } + + function Element(spec, config, parentElement, indentation) { + + this.spec = spec; + this.config = config || {}; + this.parentElement = parentElement || this; + this.indentation = indentation || ''; + this.defaultIndentation = config.indent; + + this.tag = null; + this.id = null; + this.attrs = []; + this.classes = []; + this.pseudos = []; + this.prototypes = objCreate(parentElement && parentElement.prototypes || null); + + this.isSingular = false; + this.multiplier = 1; + + this.isPretty = config.pretty; + + this.htmlOutput = []; + this.htmlContent = []; + this.htmlAttributes = []; + + this.selector = spec[0]; + + this.make(); + this.processChildren(spec[1]); + this.collectOutput(); + + this.html = this.htmlOutput.join(''); + + } + + Element.prototype = { + + make: function() { + + var attributeMap = {}; + var selector = this.selector.slice(); + var selectorPortionType; + var selectorPortion; + + this.augmentPrototypeSelector(selector); + + for (var i = 0, l = selector.length; i < l; ++i) { + selectorPortionType = selector[i][0]; + selectorPortion = selector[i][1]; + switch (selectorPortionType) { + case 'Tag': + if (!this.tag) { + this.tag = selectorPortion; + } + break; + case 'Id': + this.id = selectorPortion; break; + case 'Attr': + var attrName = selectorPortion[0]; + var attr = [attrName, [selectorPortion[1]]]; + // Attributes can only be defined once -- latest wins + if (attributeMap[attrName] != null) { + this.attrs[attributeMap[attrName]] = attr; + } else { + attributeMap[attrName] = this.attrs.push(attr) - 1; + } + break; + case 'Class': + this.classes.push(selectorPortion); break; + case 'Pseudo': + this.pseudos.push(selectorPortion); break; + } + } + + this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); + this.isSingular = this.tag in SINGULAR_TAGS; + + if (this.id) { + this.htmlAttributes.push( + 'id="' + this.id + '"' + ); + } + + if (this.classes.length) { + this.htmlAttributes.push( + 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' + ); + } + + for (var i = 0, l = this.attrs.length; i < l; ++ i) { + this.processProperty('Attribute', this.attrs[i]); + } + + for (var i = 0, l = this.pseudos.length; i < l; ++ i) { + var p = this.pseudos[i]; + if (!isNaN(p[0])) { + this.multiplier = p[0]; + continue; + } + this.processProperty('Pseudo', p); + } + + }, + + collectOutput: function() { + + var indent = this.indentation; + var isPretty = this.isPretty; + var output = this.htmlOutput; + var attrs = this.htmlAttributes; + var content = this.htmlContent; + + output.push(indent + '<' + this.tag); + output.push(attrs.length ? ' ' + attrs.join(' ') : ''); + + if (this.isSingular) { + output.push('/>'); + } else { + + output.push('>'); + + if (content.length) { + isPretty && output.push('\n'); + output.push(content.join(isPretty ? '\n': '')); + isPretty && output.push('\n' + indent); + } + + output.push(''); + + } + + if (this.multiplier > 1) { + var all = output.join(''); + for (var m = this.multiplier - 1; m--;) { + output.push(isPretty ? '\n' : ''); + output.push(all); + } + } + + }, + + _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { + + var tail = excGroup[2]; + var exclusives = excGroup[1]; + + var branches = []; + + attachTail(excGroup, tail); + + for (var n = 0, nl = exclusives.length; n < nl; ++n) { + specChildren[specChildIndex] = exclusives[n]; // Mutate + var newBranch = deepCopyArray(this.spec); // Complete copy + specChildren[specChildIndex] = excGroup; // Return to regular + branches.push(newBranch); + } + + return branches; + + // attachTail + // Goes through children (equal candidacy) looking for places to append + // both the tailChild and tailSelector. Note: they may be placed in diff places + // as in the case of `(a 'c', b)>d` + function attachTail(start, tail, hasAttached) { + + var type = start[0]; + + var children = getChildren(start); + var tailChild = tail[0]; + var tailSelector = tail[1]; + var tailChildType = tail[2]; + + var hasAttached = hasAttached || { + child: false, + selector: false + }; + + if (hasAttached.child && hasAttached.selector) { + return hasAttached; + } + + if (children) { + for (var i = children.length; i-->0;) { + var child = children[i]; + + if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild + child = child[2][0]; + } + + if (tailChildType === 'sibling') { + var cChildren = getChildren(child); + if (!cChildren || !cChildren.length) { + // Add tailChild as sibling of child + children[i] = ['IncGroup', [ + child, + deepCopyArray(tailChild) + ]]; + hasAttached.child = true; //? + if (type === 'IncGroup') { + break; + } else { + continue; + } + } + } + hasAttached = attachTail(child, tail, { + child: false, + selector: false + }); + // Prevent descendants from being attached to more than one sibling + // e.g. a,b or a+b -- should only attach last one (i.e. b) + if (type === 'IncGroup' && hasAttached.child) { + break; + } + } + } + + if (!hasAttached.selector) { + if (start[0] === 'Element') { + if (tailSelector) { + push.apply(start[1][0], tailSelector); + } + hasAttached.selector = true; + } + } + + if (!hasAttached.child) { + if (children) { + if (tailChild) { + children.push(deepCopyArray(tailChild)); + } + hasAttached.child = true; + } + } + + return hasAttached; + } + + function getChildren(child) { + return child[0] === 'Element' ? child[1][1] : + child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? + child[1] : null; + } + }, + + processChildren: function(children) { + + var cl = children.length; + var i; + var childType; + + var exclusiveBranches = []; + + for (i = 0; i < cl; ++i) { + if (children[i][0] === 'ExcGroup') { + push.apply( + exclusiveBranches, + this._makeExclusiveBranches(children[i], children, i) + ); + } + } + + if (exclusiveBranches.length) { + + this.collectOutput = function(){}; + var html = []; + + for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { + var branch = exclusiveBranches[ei]; + html.push( + new (branch[0] === 'RootElement' ? RootElement : Element)( + branch, + this.config, + this.parentElement, + this.indentation + ).html + ); + } + + this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); + + } else { + for (i = 0; i < cl; ++i) { + var child = children[i][1]; + var childType = children[i][0]; + switch (childType) { + case 'Element': + this.processElement(child); + break; + case 'Prototype': + this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); + break; + case 'IncGroup': + this.processIncGroup(child); + break; + case 'ExcGroup': + throw new Error('SIML: Found ExcGroup in unexpected location'); + default: + this.processProperty(childType, child); + } + } + } + + }, + + processElement: function(spec) { + this.htmlContent.push( + new Generator.Element( + spec, + this.config, + this, + this.indentation + this.defaultIndentation + ).html + ); + }, + + processIncGroup: function(spec) { + this.processChildren(spec); + }, + + processProperty: function(type, args) { + // type = Attribute | Directive | Pseudo + var property = new Generator.properties[type]( + args, + this.config, + this, + this.indentation + this.defaultIndentation + ); + if (property.html) { + switch (property.type) { + case 'ATTR': + if (property.html) { + this.htmlAttributes.push(property.html); + } + break; + case 'CONTENT': + if (property.html) { + this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); + } + break; + } + } + }, + + augmentPrototypeSelector: function(selector) { + // Assume tag, if specified, to be first selector portion. + if (selector[0][0] !== 'Tag') { + return selector; + } + // Retrieve and unshift prototype selector portions: + unshift.apply(selector, this.prototypes[selector[0][1]] || []); + return selector; + } + }; + + function RootElement() { + Element.apply(this, arguments); + } + + RootElement.prototype = objCreate(Element.prototype); + RootElement.prototype.make = function(){ + // RootElement is just an empty space + }; + RootElement.prototype.collectOutput = function() { + this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; + }; + RootElement.prototype.processChildren = function() { + this.defaultIndentation = ''; + return Element.prototype.processChildren.apply(this, arguments); + }; + + function Generator(defaultGeneratorConfig) { + this.config = defaults(this.defaultConfig, defaultGeneratorConfig); + } + + Generator.escapeHTML = escapeHTML; + Generator.trim = trim; + Generator.isArray = isArray; + + Generator.Element = Element; + Generator.RootElement = RootElement; + + Generator.properties = { + Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), + Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), + Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) + }; + + Generator.prototype = { + + defaultConfig: { + pretty: true, + curly: false, + indent: DEFAULT_INDENTATION, + directives: {}, + attributes: {}, + pseudos: {}, + toTag: function(t) { + return t; + } + }, + + parse: function(spec, singleRunConfig) { + + singleRunConfig = defaults(this.config, singleRunConfig || {}); + + if (!singleRunConfig.pretty) { + singleRunConfig.indent = ''; + } + + if (!/^[\s\n\r]+$/.test(spec)) { + if (singleRunConfig.curly) { + // TODO: Find a nicer way of passing config to the PEGjs parser: + spec += '\n/*siml:curly=true*/'; + } + try { + spec = siml.PARSER.parse(spec); + } catch(e) { + if (e.line !== undefined && e.column !== undefined) { + throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); + } else { + throw new SyntaxError('SIML: ' + e.message); + } + } + } else { + spec = []; + } + + if (spec[0] === 'Element') { + return new Generator.Element( + spec[1], + singleRunConfig + ).html; + } + + return new Generator.RootElement( + ['RootElement', [['IncGroup', [spec]]]], + singleRunConfig + ).html; + } + + }; + + siml.Generator = Generator; + + siml.defaultGenerator = new Generator({ + pretty: true, + indent: DEFAULT_INDENTATION + }); + + siml.parse = function(s, c) { + return siml.defaultGenerator.parse(s, c); + }; + +}()); (function() { @@ -608,9 +608,15 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win ]; var INPUT_TYPES = { - button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, 'datetime-local': 1, - email: 1, file: 1, hidden: 1, image: 1, month: 1, number: 1, password: 1, radio: 1, - range: 1, reset: 1, search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + button: { + button: 1, reset: 1, submit: 1 + }, + input: { + button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, + 'datetime-local': 1, email: 1, file: 1, hidden: 1, image: 1, + month: 1, number: 1, password: 1, radio: 1, range: 1, reset: 1, + search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + } }; var HTML_SHORT_MAP = {}; @@ -643,14 +649,20 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win doctype: doctypeDirective, dt: doctypeDirective }, + getPsuedoType: function(tag, name) { + var types = INPUT_TYPES[tag]; + + if (types && types[name]) { + return 'type="' + name + '"'; + } + }, pseudos: { _default: { type: 'ATTR', make: function(name) { - if (this.parentElement.tag === 'input' && INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - throw new Error('Unknown Pseduo: ' + name); + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + throw new Error('Unknown Pseudo: ' + name); } } } @@ -662,43 +674,42 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win }()); -siml.angular = new siml.Generator({ - pretty: true, - toTag: siml.html5.config.toTag, - directives: { - doctype: siml.html5.config.directives.doctype, - dt: siml.html5.config.directives.dt, - _default: { - type: 'ATTR', - make: function(name, children, value) { - // camelCase -> snake-case - name = name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { - return $1 + '-' + $2.toLowerCase(); - }); - if (name.substring(0, 1) === '$') { - name = name.substring(1); - } else { - name = 'ng-' + name; - } - return name + '="' + value + '"'; - } - } - }, - pseudos: { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input' && siml.html5.INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - // camelCase -> snake-case - return 'ng-' + name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { - return $1 + '-' + $2.toLowerCase(); - }); - } - } - } -}); +siml.angular = new siml.Generator({ + pretty: true, + toTag: siml.html5.config.toTag, + directives: { + doctype: siml.html5.config.directives.doctype, + dt: siml.html5.config.directives.dt, + _default: { + type: 'ATTR', + make: function(name, children, value) { + // camelCase -> snake-case + name = name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { + return $1 + '-' + $2.toLowerCase(); + }); + if (name.substring(0, 1) === '$') { + name = name.substring(1); + } else { + name = 'ng-' + name; + } + return name + '="' + value + '"'; + } + } + }, + pseudos: { + _default: { + type: 'ATTR', + make: function(name) { + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + // camelCase -> snake-case + return 'ng-' + name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { + return $1 + '-' + $2.toLowerCase(); + }); + } + } + } +}); siml.PARSER = (function(){ /* @@ -972,22 +983,22 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body) { - if (!head) { - return ['IncGroup', []]; - } - - var all = []; - - if (head[0] !== 'Element' || body.length) { - head = ['IncGroup', [head]]; - } - - for (var i = 0, l = body.length; i < l; ++i) { - head[1].push(body[i][1]); - } - - return head; + result0 = (function(offset, line, column, head, body) { + if (!head) { + return ['IncGroup', []]; + } + + var all = []; + + if (head[0] !== 'Element' || body.length) { + head = ['IncGroup', [head]]; + } + + for (var i = 0, l = body.length; i < l; ++i) { + head[1].push(body[i][1]); + } + + return head; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -1050,11 +1061,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, a, b) { - if (b[3]) { - return ['IncGroup', [a, b[3]], 'CommaGroup']; - } - return a; + result0 = (function(offset, line, column, a, b) { + if (b[3]) { + return ['IncGroup', [a, b[3]], 'CommaGroup']; + } + return a; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1131,47 +1142,47 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, singleA, tail, decl) { - - var seperator = tail[0] && tail[0].join(''); - var singleB = tail[1]; - - if (decl) { - var declarationChildren = decl[1][0]; - if (singleB) { - if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); - } else { - if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); - } - } - - if (!tail.length) { - return singleA; - } - - switch (singleA[0]) { - case 'Element': { - - if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { - return ['IncGroup', [singleA,singleB]]; - } - - // a>b - if (singleA[0] === 'Element') { - singleA[1][1].push(singleB); - } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { - singleA[1].push(singleB); - } - - return singleA; - } - case 'Prototype': - case 'Directive': - case 'Attribute': { - return ['IncGroup', [singleA, singleB]]; - } - } - return 'ERROR'; + result0 = (function(offset, line, column, singleA, tail, decl) { + + var seperator = tail[0] && tail[0].join(''); + var singleB = tail[1]; + + if (decl) { + var declarationChildren = decl[1][0]; + if (singleB) { + if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); + } else { + if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); + } + } + + if (!tail.length) { + return singleA; + } + + switch (singleA[0]) { + case 'Element': { + + if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { + return ['IncGroup', [singleA,singleB]]; + } + + // a>b + if (singleA[0] === 'Element') { + singleA[1][1].push(singleB); + } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { + singleA[1].push(singleB); + } + + return singleA; + } + case 'Prototype': + case 'Directive': + case 'Attribute': { + return ['IncGroup', [singleA, singleB]]; + } + } + return 'ERROR'; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[3]); } if (result0 === null) { @@ -1329,35 +1340,35 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body, selector, tail) { - - var all = []; - var separator = ''; - - body.unshift([,,,head]); - - if (tail) { - if (tail[0] === 'Declaration') { - tail = tail[1][0]; - } else { - separator = tail[1]; - tail = tail[0]; - } - } - - for (var i = 0, l = body.length; i < l; ++i) { - if (body[i][3][2] === 'CommaGroup') { - // Make (a,b,c/g) be considered as ((a/b/c/)/g) - body[i][3][0] = 'ExcGroup'; - body[i][3][2] = []; - } - all.push(body[i][3]); - } - return ['ExcGroup', all, [ - tail, - selector, - separator.indexOf('+') > -1 ? 'sibling' : 'descendent' - ]]; + result0 = (function(offset, line, column, head, body, selector, tail) { + + var all = []; + var separator = ''; + + body.unshift([,,,head]); + + if (tail) { + if (tail[0] === 'Declaration') { + tail = tail[1][0]; + } else { + separator = tail[1]; + tail = tail[0]; + } + } + + for (var i = 0, l = body.length; i < l; ++i) { + if (body[i][3][2] === 'CommaGroup') { + // Make (a,b,c/g) be considered as ((a/b/c/)/g) + body[i][3][0] = 'ExcGroup'; + body[i][3][2] = []; + } + all.push(body[i][3]); + } + return ['ExcGroup', all, [ + tail, + selector, + separator.indexOf('+') > -1 ? 'sibling' : 'descendent' + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3], result0[6], result0[8]); } if (result0 === null) { @@ -1410,8 +1421,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, separator, tail) { - return [tail, separator]; + result0 = (function(offset, line, column, separator, tail) { + return [tail, separator]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1464,8 +1475,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return ['Declaration', [c]]; + result0 = (function(offset, line, column, c) { + return ['Declaration', [c]]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -1503,8 +1514,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_SingleSelector(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Element', [s,[]]]; + result0 = (function(offset, line, column, s) { + return ['Element', [s,[]]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1643,8 +1654,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, s) { - return ['Prototype', [name, s]]; + result0 = (function(offset, line, column, name, s) { + return ['Prototype', [name, s]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -1735,9 +1746,9 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - s[1].unshift(s[0]); - return s[1]; + result0 = (function(offset, line, column, s) { + s[1].unshift(s[0]); + return s[1]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1756,8 +1767,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return s; + result0 = (function(offset, line, column, s) { + return s; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1873,11 +1884,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, f, t) { - return [ - f === '#' ? 'Id' : 'Class', - t.join('') - ]; + result0 = (function(offset, line, column, f, t) { + return [ + f === '#' ? 'Id' : 'Class', + t.join('') + ]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1981,8 +1992,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attr', [name.join(''), value.length ? value[1] : null]]; + result0 = (function(offset, line, column, name, value) { + return ['Attr', [name.join(''), value.length ? value[1] : null]]; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -2066,13 +2077,13 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, t, arg) { - return ['Pseudo', [ - t.join(''), - [ - arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ] - ]]; + result0 = (function(offset, line, column, t, arg) { + return ['Pseudo', [ + t.join(''), + [ + arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3]); } if (result0 === null) { @@ -2138,8 +2149,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2155,8 +2166,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_html(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [s], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [s], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2231,8 +2242,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2281,8 +2292,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [escapeHTML(value)]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [escapeHTML(value)]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2331,8 +2342,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2389,8 +2400,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { // explicit space - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { // explicit space + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2482,12 +2493,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, args, children) { - return ['Directive', [ - name, - args || [], - children || [] - ]]; + result0 = (function(offset, line, column, name, args, children) { + return ['Directive', [ + name, + args || [], + children || [] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[2]); } if (result0 === null) { @@ -2614,8 +2625,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, args) { - return args; + result0 = (function(offset, line, column, args) { + return args; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2625,10 +2636,10 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_braced(); if (result0 !== null) { - result0 = (function(offset, line, column, arg) { - return [ - arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ]; + result0 = (function(offset, line, column, arg) { + return [ + arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2653,8 +2664,8 @@ siml.PARSER = (function(){ } } if (result0 !== null) { - result0 = (function(offset, line, column) { - return []; + result0 = (function(offset, line, column) { + return []; })(pos0.offset, pos0.line, pos0.column); } if (result0 === null) { @@ -2706,8 +2717,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return [c]; + result0 = (function(offset, line, column, c) { + return [c]; })(pos0.offset, pos0.line, pos0.column, result0[2]); } if (result0 === null) { @@ -2751,8 +2762,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, tail) { - return [tail]; + result0 = (function(offset, line, column, tail) { + return [tail]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2816,8 +2827,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, parts) { - return '(' + parts.join('') + ')'; + result0 = (function(offset, line, column, parts) { + return '(' + parts.join('') + ')'; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2944,12 +2955,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, tail) { - var result = [head]; - for (var i = 0; i < tail.length; i++) { - result.push(tail[i][2]); - } - return result; + result0 = (function(offset, line, column, head, tail) { + var result = [head]; + for (var i = 0; i < tail.length; i++) { + result.push(tail[i][2]); + } + return result; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -2965,8 +2976,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return escapeHTML(s); + result0 = (function(offset, line, column, s) { + return escapeHTML(s); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3100,12 +3111,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - // Replace any `...` quotes within the String: - return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { - var str = stringTokens[ $1 ]; - return str[0] + str[1] + str[0]; - }); + result0 = (function(offset, line, column, d) { + // Replace any `...` quotes within the String: + return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { + var str = stringTokens[ $1 ]; + return str[0] + str[1] + str[0]; + }); })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3172,8 +3183,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - return stringTokens[ d.join('') ][1]; + result0 = (function(offset, line, column, d) { + return stringTokens[ d.join('') ][1]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3219,8 +3230,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, simpleString) { - return simpleString.join(''); + result0 = (function(offset, line, column, simpleString) { + return simpleString.join(''); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3685,145 +3696,145 @@ siml.PARSER = (function(){ } - - - var toString = {}.toString; - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; - } - return out; - } - - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - - // Replace all strings with recoverable string tokens: - // This is done to make comment-removal possible and safe. - var stringTokens = [ - // [ 'QUOTE', 'ACTUAL_STRING' ] ... - ]; - function resolveStringToken(tok) { - return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] - } - - // Replace HTML with string tokens first - input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__HTML_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\`/g, '\`')] - ) - 1); - }); - - input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__STRING_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] - ) - 1); - }); - - input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { - return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); - }); - - var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); - - // Remove comments: - input = input.replace(/\/\*[\s\S]*?\*\//g, ''); - input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); - - (function() { - - // Avoid magical whitespace if we're definitely using curlies: - if (isCurly) { - return; - } - - // Here we impose hierarchical curlies on the basis of indentation - // This is used to make, e.g. - // a\n\tb - // into - // a{b} - - input = input.replace(/^(?:\s*\n)+/g, ''); - - var cur; - var lvl = 0; - var lines = []; - var blockedFromClosing = {}; - var step = null; - - var braceDepth = 0; - var curlyDepth = 0; - - input = input.split(/[\r\n]+/); - - for (var i = 0, l = input.length; i < l; ++i) { - - var line = input[i]; - - var indent = line.match(/^\s*/)[0]; - var indentLevel = (indent.match(/\s/g)||[]).length; - - var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; - - if (step == null && nextIndentLevel !== indentLevel) { - step = nextIndentLevel - indentLevel; - } - - braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; - curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; - - if (/^\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (indentLevel < cur) { // dedent - var diff = cur - indentLevel; - while (1) { - diff -= step; - if (lvl === 0 || diff < 0) { - break; - } - if (blockedFromClosing[i-1]) { - continue; - } - lvl--; - lines[i-1] += '}'; - } - } - - if (curlyDepth || braceDepth) { - // Lines within a curly/brace nesting are blocked from future '}' closes - blockedFromClosing[i] = 1; - lines.push(line); - continue; - } - - line = line.substring(indent.length); - - // Don't seek to add curlies to places where curlies already exist: - if (/[{}]\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (nextIndentLevel > indentLevel) { // indent - lvl++; - lines.push(indent + line + '{'); - } else { - lines.push(indent+line); - } - - cur = indentLevel; - - } - - input = lines.join('\n'); //{{ // make curlies BALANCE for peg! - input += Array(lvl+1).join('}'); - }()); - + + + var toString = {}.toString; + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; + } + return out; + } + + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + + // Replace all strings with recoverable string tokens: + // This is done to make comment-removal possible and safe. + var stringTokens = [ + // [ 'QUOTE', 'ACTUAL_STRING' ] ... + ]; + function resolveStringToken(tok) { + return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] + } + + // Replace HTML with string tokens first + input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__HTML_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\`/g, '\`')] + ) - 1); + }); + + input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__STRING_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] + ) - 1); + }); + + input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { + return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); + }); + + var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); + + // Remove comments: + input = input.replace(/\/\*[\s\S]*?\*\//g, ''); + input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); + + (function() { + + // Avoid magical whitespace if we're definitely using curlies: + if (isCurly) { + return; + } + + // Here we impose hierarchical curlies on the basis of indentation + // This is used to make, e.g. + // a\n\tb + // into + // a{b} + + input = input.replace(/^(?:\s*\n)+/g, ''); + + var cur; + var lvl = 0; + var lines = []; + var blockedFromClosing = {}; + var step = null; + + var braceDepth = 0; + var curlyDepth = 0; + + input = input.split(/[\r\n]+/); + + for (var i = 0, l = input.length; i < l; ++i) { + + var line = input[i]; + + var indent = line.match(/^\s*/)[0]; + var indentLevel = (indent.match(/\s/g)||[]).length; + + var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; + + if (step == null && nextIndentLevel !== indentLevel) { + step = nextIndentLevel - indentLevel; + } + + braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; + curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; + + if (/^\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (indentLevel < cur) { // dedent + var diff = cur - indentLevel; + while (1) { + diff -= step; + if (lvl === 0 || diff < 0) { + break; + } + if (blockedFromClosing[i-1]) { + continue; + } + lvl--; + lines[i-1] += '}'; + } + } + + if (curlyDepth || braceDepth) { + // Lines within a curly/brace nesting are blocked from future '}' closes + blockedFromClosing[i] = 1; + lines.push(line); + continue; + } + + line = line.substring(indent.length); + + // Don't seek to add curlies to places where curlies already exist: + if (/[{}]\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (nextIndentLevel > indentLevel) { // indent + lvl++; + lines.push(indent + line + '{'); + } else { + lines.push(indent+line); + } + + cur = indentLevel; + + } + + input = lines.join('\n'); //{{ // make curlies BALANCE for peg! + input += Array(lvl+1).join('}'); + }()); + var result = parseFunctions[startRule](); diff --git a/dist/siml.all.min.js b/dist/siml.all.min.js index dc61bee..c298f13 100644 --- a/dist/siml.all.min.js +++ b/dist/siml.all.min.js @@ -1,3 +1,3 @@ -/** SIML v0.3.6 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ -(function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function e(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function u(l){for(var t=[],e=0,r=l.length;r>e;++e)t[e]=n(l[e])?u(l[e]):l[e];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,e,u,r){this.parentElement=u,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=e[l][o]||n[o];if(i||(i=e[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,e){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=e||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",m={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},A={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},e=this.selector.slice();this.augmentPrototypeSelector(e);for(var u=0,r=e.length;r>u;++u)switch(l=e[u][0],n=e[u][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in m,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var u=0,r=this.attrs.length;r>u;++u)this.processProperty("Attribute",this.attrs[u]);for(var u=0,r=this.pseudos.length;r>u;++u){var f=this.pseudos[u];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,e=this.htmlAttributes,u=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(e.length?" "+e.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),u.length&&(n&&t.push("\n"),t.push(u.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function e(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var m=r(p);if(!m||!m.length){if(s[h]=["IncGroup",[p,u(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=e(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(u(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];e(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=u(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,e=l.length,u=[];for(n=0;e>n;++n)"ExcGroup"===l[n][0]&&c.apply(u,this._makeExclusiveBranches(l[n],l,n));if(u.length){this.collectOutput=function(){};for(var r=[],o=0,i=u.length;i>o;++o){var a=u[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;e>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=e,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",A),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(e){throw void 0!==e.line&&void 0!==e.column?new SyntaxError("SIML: Line "+e.line+", column "+e.column+": "+e.message):new SyntaxError("SIML: "+e.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),function(){var n=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","data","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","plaintext","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],t={button:1,checkbox:1,color:1,date:1,datetime:1,"datetime-local":1,email:1,file:1,hidden:1,image:1,month:1,number:1,password:1,radio:1,range:1,reset:1,search:1,submit:1,tel:1,text:1,time:1,url:1,week:1},e={};n.forEach(function(l){if(e[l]=l,l.length>2){var n=l.replace(/[aeiou]+/g,"");n.length>1&&!e[n]&&(e[n]=l)}});var u={type:"CONTENT",make:function(){return""}};l.html5=new l.Generator({pretty:!0,indent:" ",toTag:function(l){return e[l]||l},directives:{doctype:u,dt:u},pseudos:{_default:{type:"ATTR",make:function(l){if("input"===this.parentElement.tag&&t.hasOwnProperty(l))return'type="'+l+'"';throw Error("Unknown Pseduo: "+l)}}}}),l.html5.HTML_SHORT_MAP=e,l.html5.INPUT_TYPES=t}(),l.angular=new l.Generator({pretty:!0,toTag:l.html5.config.toTag,directives:{doctype:l.html5.config.directives.doctype,dt:l.html5.config.directives.dt,_default:{type:"ATTR",make:function(l,n,t){return l=l.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()}),l="$"===l.substring(0,1)?l.substring(1):"ng-"+l,l+'="'+t+'"'}}},pseudos:{_default:{type:"ATTR",make:function(n){return"input"===this.parentElement.tag&&l.html5.INPUT_TYPES.hasOwnProperty(n)?'type="'+n+'"':"ng-"+n.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()})}}}}),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function e(l){var n={};for(var t in l)n[t]=l[t];return n}function u(l,t){for(var e=l.offset+t,u=l.offset;e>u;u++){var r=n.charAt(u);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){Q.offsetX.offset&&(X=e(Q),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=e(Q),a=e(Q),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h));null!==f;){for(o.push(f),h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,Q=e(a))):(l=null,Q=e(a))}else l=null,Q=e(a);else l=null,Q=e(a);return null!==l&&(l=function(l,n,t,e,u){if(!e)return["IncGroup",[]];("Element"!==e[0]||u.length)&&(e=["IncGroup",[e]]);for(var r=0,o=u.length;o>r;++r)e[1].push(u[r][1]);return e}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(Q=e(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=e(Q),h=e(Q),l=f(),null!==l?(p=e(Q),t=U(),null!==t?(44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return u[3]?["IncGroup",[e,u[3]],"CommaGroup"]:e}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(Q=e(a)),l}function f(){var l,t,s,h,p,m,A,g,v,_,y,b;if(_=e(Q),y=e(Q),l=a(),null!==l){for(b=e(Q),t=[],/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,Q=e(b))):(t=null,Q=e(b)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);if(null!==l&&(l=function(l,n,t,e,u,r){var o=u[0]&&u[0].join(""),s=u[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===e[0]&&e[1][1].push(f)}if(!u.length)return e;switch(e[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[e,s]]:("Element"===e[0]?e[1][1].push(s):("IncGroup"===e[0]||"ExcGroup"===e[0])&&e[1].push(s),e);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[e,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(Q=e(_)),null===l){if(_=e(Q),y=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],b=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b));null!==p;)h.push(p),b=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(Q.offset)?(m=")",u(Q,1)):(m=null,0===W&&r('")"')),null!==m){for(A=[],g=d();null!==g;)A.push(g),g=d();null!==A?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,m,A,g,v]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y)}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y);null!==l&&(l=function(l,n,t,e,u,r,o){var s=[],f="";u.unshift([,,,e]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=u.length;c>i;++i)"CommaGroup"===u[i][3][2]&&(u[i][3][0]="ExcGroup",u[i][3][2]=[]),s.push(u[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(Q=e(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=e(Q),s=e(Q),l=[],/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return[u,e]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o))}return l}function c(){var l,t,s,f,i;return f=e(Q),i=e(Q),123===n.charCodeAt(Q.offset)?(l="{",u(Q,1)):(l=null,0===W&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(Q.offset)?(s="}",u(Q,1)):(s=null,0===W&&r('"}"')),null!==s?l=[l,t,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i)),null!==l&&(l=function(l,n,t,e){return["Declaration",[e]]}(f.offset,f.line,f.column,l[1])),null===l&&(Q=e(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=E(),null===l&&(l=C(),null===l&&(l=x()))))),l}function h(){var l,n;return n=e(Q),l=A(),null!==l&&(l=function(l,n,t,e){return["Element",[e,[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=e(Q),h=e(Q),l=m(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));if(null!==s)if(f=A(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);return null!==l&&(l=function(l,n,t,e,u){return["Prototype",[e,u]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),l}function m(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function A(){var l,n,t,u,r;if(u=e(Q),r=e(Q),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,Q=e(r))}else l=null,Q=e(r);if(null!==l&&(l=function(l,n,t,e){return e[1].unshift(e[0]),e[1]}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u)),null===l){if(u=e(Q),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,e){return e}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u))}return l}function d(){var l;return l=v(),null===l&&(l=y(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=e(Q),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,e){return["Tag",e.join("")]}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),l}function v(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[#.]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return["#"===e?"Id":"Class",u.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function _(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),91===n.charCodeAt(Q.offset)?(l="[",u(Q,1)):(l=null,0===W&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]"));else t=null;null!==t?(c=e(Q),61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o?(s=b(),null!==s?o=[o,s]:(o=null,Q=e(c))):(o=null,Q=e(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(Q.offset)?(s="]",u(Q,1)):(s=null,0===W&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Attr",[e.join(""),u.length?u[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function y(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),58===n.charCodeAt(Q.offset)?(l=":",u(Q,1)):(l=null,0===W&&r('":"')),null!==l)if(c=e(Q),W++,t=R(),W--,null===t?t="":(t=null,Q=e(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=w(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Pseudo",[e.join(""),[u&&u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(Q=e(f)),l}function b(){var l,t,o;if(o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return e}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l){if(o=e(Q),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o))}return l}function E(){var l,n;return n=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[V(e)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function C(){var l,n;return n=e(Q),l=P(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[e],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=$(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[V(u)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=P(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[ \\t]")),null!==s?(f=$(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a))))),l}function S(){var l,t,o;if(W++,o=e(Q),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=R(),null===l&&(l=P())),W--,0===W&&null===l&&r("AttributeName"),l}function x(){var l,n,t,u,o;return W++,u=e(Q),o=e(Q),l=k(),null!==l?(n=G(),n=null!==n?n:"",null!==n?(t=I(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,Q=e(o))):(l=null,Q=e(o))):(l=null,Q=e(o)),null!==l&&(l=function(l,n,t,e,u,r){return["Directive",[e,u||[],r||[]]]}(u.offset,u.line,u.column,l[0],l[1],l[2])),null===l&&(Q=e(u)),W--,0===W&&null===l&&r("Directive"),l}function k(){var l,t,o,s,f,i;if(f=e(Q),i=e(Q),64===n.charCodeAt(Q.offset)?(l="@",u(Q,1)):(l=null,0===W&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function G(){var l,t,o,s,f;return s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l?(t=O(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),null===l&&(s=e(Q),l=w(),null!==l&&(l=function(l,n,t,e){return[e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(Q=e(s))),l}function I(){var l,t,s,i,c,a;if(c=e(Q),59===n.charCodeAt(Q.offset)?(l=";",u(Q,1)):(l=null,0===W&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(Q=e(c)),null===l&&(c=e(Q),a=e(Q),l=U(),null!==l?(123===n.charCodeAt(Q.offset)?(t="{",u(Q,1)):(t=null,0===W&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(Q.offset)?(i="}",u(Q,1)):(i=null,0===W&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[2])),null===l&&(Q=e(c)),null===l)){for(c=e(Q),a=e(Q),l=[],/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[1])),null===l&&(Q=e(c))}return l}function w(){var l,t,o,s,f;if(s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l){for(t=[],o=w(),null===o&&(o=N());null!==o;)t.push(o),o=w(),null===o&&(o=N());null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return"("+e.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),l}function z(){var l,n,t;if(t=e(Q),n=N(),null!==n)for(l=[];null!==n;)l.push(n),n=N();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function N(){var l;return/^[^()]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[^()]")),l}function O(){var l,t,o,s,f,i,c,a;if(i=e(Q),c=e(Q),l=$(),null!==l){for(t=[],a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=$(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==o;)t.push(o),a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=$(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==t?l=[l,t]:(l=null,Q=e(c))}else l=null,Q=e(c);return null!==l&&(l=function(l,n,t,e,u){for(var r=[e],o=0;u.length>o;o++)r.push(u[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(Q=e(i)),l}function $(){var l,t,o,s;return o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return V(e)}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=j(),null===l&&(l=P(),null===l&&(l=Z(),null===l&&(o=e(Q),s=e(Q),"true"===n.substr(Q.offset,4)?(l="true",u(Q,4)):(l=null,0===W&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),"false"===n.substr(Q.offset,5)?(l="false",u(Q,5)):(l=null,0===W&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(Q=e(o))))))),l}function R(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__STRING_TOKEN___%%"===n.substr(Q.offset,21)?(l="%%__STRING_TOKEN___%%",u(Q,21)):(l=null,0===W&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("String"),l}function P(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__HTML_TOKEN___%%"===n.substr(Q.offset,19)?(l="%%__HTML_TOKEN___%%",u(Q,19)):(l=null,0===W&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("HTML"),l}function j(){var l,t,o;if(W++,o=e(Q),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),W--,0===W&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,u,o,s;return W++,o=e(Q),s=e(Q),l=M(),null!==l?(n=L(),null!==n?(t=D(),null!==t?(u=U(),null!==u?l=[l,n,t,u]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u,r){return parseFloat(e+u+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=L(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return parseFloat(e)}(o.offset,o.line,o.column,l[0])),null===l&&(Q=e(o))))),W--,0===W&&null===l&&r("number"),l}function M(){var l,t,o,s,f;return s=e(Q),f=e(Q),l=B(),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return e+u}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),null===l&&(l=K(),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=B(),null!==t?(o=H(),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return"-"+e+u}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(Q=e(s)),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return"-"+e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s))))),l}function L(){var l,t,o,s;return o=e(Q),s=e(Q),46===n.charCodeAt(Q.offset)?(l=".",u(Q,1)):(l=null,0===W&&r('"."')),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return"."+e}(o.offset,o.line,o.column,l[1])),null===l&&(Q=e(o)),l}function D(){var l,n,t,u;return t=e(Q),u=e(Q),l=F(),null!==l?(n=H(),null!==n?l=[l,n]:(l=null,Q=e(u))):(l=null,Q=e(u)),null!==l&&(l=function(l,n,t,e,u){return e+u}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(Q=e(t)),l}function H(){var l,n,t;if(t=e(Q),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function F(){var l,t,o,s;return o=e(Q),s=e(Q),/^[eE]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return e+u}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),l -}function K(){var l;return/^[0-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(W++,l=[],/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));return W--,0===W&&null===l&&r("whitespace"),l}function Y(l){l.sort();for(var n=null,t=[],e=0;l.length>e;e++)l[e]!==n&&(t.push(l[e]),n=l[e]);return t}function V(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var J={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:m,SingleSelector:A,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:y,selectorAttrValue:b,Text:E,HTML:C,Attribute:T,attributeName:S,Directive:x,DirectiveName:k,DirectiveArguments:G,DirectiveChildren:I,braced:w,nonBraceCharacters:z,nonBraceCharacter:N,arrayElements:O,value:$,string:R,html:P,simpleString:j,number:Z,"int":M,frac:L,exp:D,digits:H,e:F,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===J[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var Q={offset:0,line:1,column:1,seenCR:!1},W=0,X={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,e=[],u={},r=null,o=0,s=0;n=n.split(/[\r\n]+/);for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))e.push(c);else{if(l>h)for(var m=l-h;;){if(m-=r,0===t||0>m)break;u[f-1]||(t--,e[f-1]+="}")}s||o?(u[f]=1,e.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?e.push(c):(p>h?(t++,e.push(a+c+"{")):e.push(a+c),l=h))}}n=e.join("\n"),n+=Array(t+1).join("}")}}();var en=J[t]();if(null===en||Q.offset!==n.length){var un=Math.max(Q.offset,X.offset),rn=n.length>un?n.charAt(un):null,on=Q.offset>X.offset?Q:X;throw new this.SyntaxError(Y(ln),rn,un,on.line,on.column)}return en},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,e,u,r){function o(n,t){var e,u;switch(n.length){case 0:e="end of input";break;case 1:e=n[0];break;default:e=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return u=t?l(t):"end of input","Expected "+e+" but "+u+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=e,this.line=u,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file +/** SIML v0.3.7 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ +(function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function e(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function u(l){for(var t=[],e=0,r=l.length;r>e;++e)t[e]=n(l[e])?u(l[e]):l[e];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,e,u,r){this.parentElement=u,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=e[l][o]||n[o];if(i||(i=e[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,e){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=e||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",m={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},A={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},e=this.selector.slice();this.augmentPrototypeSelector(e);for(var u=0,r=e.length;r>u;++u)switch(l=e[u][0],n=e[u][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in m,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var u=0,r=this.attrs.length;r>u;++u)this.processProperty("Attribute",this.attrs[u]);for(var u=0,r=this.pseudos.length;r>u;++u){var f=this.pseudos[u];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,e=this.htmlAttributes,u=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(e.length?" "+e.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),u.length&&(n&&t.push("\n"),t.push(u.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function e(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var m=r(p);if(!m||!m.length){if(s[h]=["IncGroup",[p,u(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=e(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(u(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];e(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=u(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,e=l.length,u=[];for(n=0;e>n;++n)"ExcGroup"===l[n][0]&&c.apply(u,this._makeExclusiveBranches(l[n],l,n));if(u.length){this.collectOutput=function(){};for(var r=[],o=0,i=u.length;i>o;++o){var a=u[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;e>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=e,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",A),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(e){throw void 0!==e.line&&void 0!==e.column?new SyntaxError("SIML: Line "+e.line+", column "+e.column+": "+e.message):new SyntaxError("SIML: "+e.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),function(){var n=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","data","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","plaintext","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],t={button:{button:1,reset:1,submit:1},input:{button:1,checkbox:1,color:1,date:1,datetime:1,"datetime-local":1,email:1,file:1,hidden:1,image:1,month:1,number:1,password:1,radio:1,range:1,reset:1,search:1,submit:1,tel:1,text:1,time:1,url:1,week:1}},e={};n.forEach(function(l){if(e[l]=l,l.length>2){var n=l.replace(/[aeiou]+/g,"");n.length>1&&!e[n]&&(e[n]=l)}});var u={type:"CONTENT",make:function(){return""}};l.html5=new l.Generator({pretty:!0,indent:" ",toTag:function(l){return e[l]||l},directives:{doctype:u,dt:u},getPsuedoType:function(l,n){var e=t[l];return e&&e[n]?'type="'+n+'"':void 0},pseudos:{_default:{type:"ATTR",make:function(n){var t=l.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(),n);if(t)return t;throw Error("Unknown Pseudo: "+n)}}}}),l.html5.HTML_SHORT_MAP=e,l.html5.INPUT_TYPES=t}(),l.angular=new l.Generator({pretty:!0,toTag:l.html5.config.toTag,directives:{doctype:l.html5.config.directives.doctype,dt:l.html5.config.directives.dt,_default:{type:"ATTR",make:function(l,n,t){return l=l.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()}),l="$"===l.substring(0,1)?l.substring(1):"ng-"+l,l+'="'+t+'"'}}},pseudos:{_default:{type:"ATTR",make:function(n){var t=l.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(),n);return t?t:"ng-"+n.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()})}}}}),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function e(l){var n={};for(var t in l)n[t]=l[t];return n}function u(l,t){for(var e=l.offset+t,u=l.offset;e>u;u++){var r=n.charAt(u);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){Q.offsetX.offset&&(X=e(Q),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=e(Q),a=e(Q),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h));null!==f;){for(o.push(f),h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,Q=e(a))):(l=null,Q=e(a))}else l=null,Q=e(a);else l=null,Q=e(a);return null!==l&&(l=function(l,n,t,e,u){if(!e)return["IncGroup",[]];("Element"!==e[0]||u.length)&&(e=["IncGroup",[e]]);for(var r=0,o=u.length;o>r;++r)e[1].push(u[r][1]);return e}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(Q=e(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=e(Q),h=e(Q),l=f(),null!==l?(p=e(Q),t=U(),null!==t?(44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return u[3]?["IncGroup",[e,u[3]],"CommaGroup"]:e}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(Q=e(a)),l}function f(){var l,t,s,h,p,m,A,g,v,_,y,b;if(_=e(Q),y=e(Q),l=a(),null!==l){for(b=e(Q),t=[],/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,Q=e(b))):(t=null,Q=e(b)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);if(null!==l&&(l=function(l,n,t,e,u,r){var o=u[0]&&u[0].join(""),s=u[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===e[0]&&e[1][1].push(f)}if(!u.length)return e;switch(e[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[e,s]]:("Element"===e[0]?e[1][1].push(s):("IncGroup"===e[0]||"ExcGroup"===e[0])&&e[1].push(s),e);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[e,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(Q=e(_)),null===l){if(_=e(Q),y=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],b=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b));null!==p;)h.push(p),b=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(Q.offset)?(m=")",u(Q,1)):(m=null,0===W&&r('")"')),null!==m){for(A=[],g=d();null!==g;)A.push(g),g=d();null!==A?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,m,A,g,v]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y)}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y);null!==l&&(l=function(l,n,t,e,u,r,o){var s=[],f="";u.unshift([,,,e]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=u.length;c>i;++i)"CommaGroup"===u[i][3][2]&&(u[i][3][0]="ExcGroup",u[i][3][2]=[]),s.push(u[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(Q=e(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=e(Q),s=e(Q),l=[],/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return[u,e]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o))}return l}function c(){var l,t,s,f,i;return f=e(Q),i=e(Q),123===n.charCodeAt(Q.offset)?(l="{",u(Q,1)):(l=null,0===W&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(Q.offset)?(s="}",u(Q,1)):(s=null,0===W&&r('"}"')),null!==s?l=[l,t,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i)),null!==l&&(l=function(l,n,t,e){return["Declaration",[e]]}(f.offset,f.line,f.column,l[1])),null===l&&(Q=e(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=E(),null===l&&(l=C(),null===l&&(l=x()))))),l}function h(){var l,n;return n=e(Q),l=A(),null!==l&&(l=function(l,n,t,e){return["Element",[e,[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=e(Q),h=e(Q),l=m(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));if(null!==s)if(f=A(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);return null!==l&&(l=function(l,n,t,e,u){return["Prototype",[e,u]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),l}function m(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function A(){var l,n,t,u,r;if(u=e(Q),r=e(Q),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,Q=e(r))}else l=null,Q=e(r);if(null!==l&&(l=function(l,n,t,e){return e[1].unshift(e[0]),e[1]}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u)),null===l){if(u=e(Q),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,e){return e}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u))}return l}function d(){var l;return l=v(),null===l&&(l=y(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=e(Q),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,e){return["Tag",e.join("")]}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),l}function v(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[#.]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return["#"===e?"Id":"Class",u.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function _(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),91===n.charCodeAt(Q.offset)?(l="[",u(Q,1)):(l=null,0===W&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]"));else t=null;null!==t?(c=e(Q),61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o?(s=b(),null!==s?o=[o,s]:(o=null,Q=e(c))):(o=null,Q=e(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(Q.offset)?(s="]",u(Q,1)):(s=null,0===W&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Attr",[e.join(""),u.length?u[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function y(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),58===n.charCodeAt(Q.offset)?(l=":",u(Q,1)):(l=null,0===W&&r('":"')),null!==l)if(c=e(Q),W++,t=R(),W--,null===t?t="":(t=null,Q=e(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=I(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Pseudo",[e.join(""),[u&&u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(Q=e(f)),l}function b(){var l,t,o;if(o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return e}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l){if(o=e(Q),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o))}return l}function E(){var l,n;return n=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[Y(e)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function C(){var l,n;return n=e(Q),l=P(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[e],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=O(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[Y(u)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=P(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[ \\t]")),null!==s?(f=O(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a))))),l}function S(){var l,t,o;if(W++,o=e(Q),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=R(),null===l&&(l=P())),W--,0===W&&null===l&&r("AttributeName"),l}function x(){var l,n,t,u,o;return W++,u=e(Q),o=e(Q),l=k(),null!==l?(n=G(),n=null!==n?n:"",null!==n?(t=w(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,Q=e(o))):(l=null,Q=e(o))):(l=null,Q=e(o)),null!==l&&(l=function(l,n,t,e,u,r){return["Directive",[e,u||[],r||[]]]}(u.offset,u.line,u.column,l[0],l[1],l[2])),null===l&&(Q=e(u)),W--,0===W&&null===l&&r("Directive"),l}function k(){var l,t,o,s,f,i;if(f=e(Q),i=e(Q),64===n.charCodeAt(Q.offset)?(l="@",u(Q,1)):(l=null,0===W&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function G(){var l,t,o,s,f;return s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l?(t=$(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),null===l&&(s=e(Q),l=I(),null!==l&&(l=function(l,n,t,e){return[e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(Q=e(s))),l}function w(){var l,t,s,i,c,a;if(c=e(Q),59===n.charCodeAt(Q.offset)?(l=";",u(Q,1)):(l=null,0===W&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(Q=e(c)),null===l&&(c=e(Q),a=e(Q),l=U(),null!==l?(123===n.charCodeAt(Q.offset)?(t="{",u(Q,1)):(t=null,0===W&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(Q.offset)?(i="}",u(Q,1)):(i=null,0===W&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[2])),null===l&&(Q=e(c)),null===l)){for(c=e(Q),a=e(Q),l=[],/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[1])),null===l&&(Q=e(c))}return l}function I(){var l,t,o,s,f;if(s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l){for(t=[],o=I(),null===o&&(o=N());null!==o;)t.push(o),o=I(),null===o&&(o=N());null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return"("+e.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),l}function z(){var l,n,t;if(t=e(Q),n=N(),null!==n)for(l=[];null!==n;)l.push(n),n=N();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function N(){var l;return/^[^()]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[^()]")),l}function $(){var l,t,o,s,f,i,c,a;if(i=e(Q),c=e(Q),l=O(),null!==l){for(t=[],a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==o;)t.push(o),a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==t?l=[l,t]:(l=null,Q=e(c))}else l=null,Q=e(c);return null!==l&&(l=function(l,n,t,e,u){for(var r=[e],o=0;u.length>o;o++)r.push(u[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(Q=e(i)),l}function O(){var l,t,o,s;return o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return Y(e)}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=j(),null===l&&(l=P(),null===l&&(l=Z(),null===l&&(o=e(Q),s=e(Q),"true"===n.substr(Q.offset,4)?(l="true",u(Q,4)):(l=null,0===W&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),"false"===n.substr(Q.offset,5)?(l="false",u(Q,5)):(l=null,0===W&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(Q=e(o))))))),l}function R(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__STRING_TOKEN___%%"===n.substr(Q.offset,21)?(l="%%__STRING_TOKEN___%%",u(Q,21)):(l=null,0===W&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("String"),l}function P(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__HTML_TOKEN___%%"===n.substr(Q.offset,19)?(l="%%__HTML_TOKEN___%%",u(Q,19)):(l=null,0===W&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("HTML"),l}function j(){var l,t,o;if(W++,o=e(Q),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),W--,0===W&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,u,o,s;return W++,o=e(Q),s=e(Q),l=L(),null!==l?(n=M(),null!==n?(t=D(),null!==t?(u=U(),null!==u?l=[l,n,t,u]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u,r){return parseFloat(e+u+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=M(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return parseFloat(e)}(o.offset,o.line,o.column,l[0])),null===l&&(Q=e(o))))),W--,0===W&&null===l&&r("number"),l}function L(){var l,t,o,s,f;return s=e(Q),f=e(Q),l=B(),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return e+u}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),null===l&&(l=K(),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=B(),null!==t?(o=H(),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return"-"+e+u}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(Q=e(s)),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return"-"+e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s))))),l}function M(){var l,t,o,s;return o=e(Q),s=e(Q),46===n.charCodeAt(Q.offset)?(l=".",u(Q,1)):(l=null,0===W&&r('"."')),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return"."+e}(o.offset,o.line,o.column,l[1])),null===l&&(Q=e(o)),l}function D(){var l,n,t,u;return t=e(Q),u=e(Q),l=F(),null!==l?(n=H(),null!==n?l=[l,n]:(l=null,Q=e(u))):(l=null,Q=e(u)),null!==l&&(l=function(l,n,t,e,u){return e+u}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(Q=e(t)),l}function H(){var l,n,t;if(t=e(Q),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function F(){var l,t,o,s;return o=e(Q),s=e(Q),/^[eE]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return e+u +}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),l}function K(){var l;return/^[0-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(W++,l=[],/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));return W--,0===W&&null===l&&r("whitespace"),l}function V(l){l.sort();for(var n=null,t=[],e=0;l.length>e;e++)l[e]!==n&&(t.push(l[e]),n=l[e]);return t}function Y(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var J={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:m,SingleSelector:A,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:y,selectorAttrValue:b,Text:E,HTML:C,Attribute:T,attributeName:S,Directive:x,DirectiveName:k,DirectiveArguments:G,DirectiveChildren:w,braced:I,nonBraceCharacters:z,nonBraceCharacter:N,arrayElements:$,value:O,string:R,html:P,simpleString:j,number:Z,"int":L,frac:M,exp:D,digits:H,e:F,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===J[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var Q={offset:0,line:1,column:1,seenCR:!1},W=0,X={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,e=[],u={},r=null,o=0,s=0;n=n.split(/[\r\n]+/);for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))e.push(c);else{if(l>h)for(var m=l-h;;){if(m-=r,0===t||0>m)break;u[f-1]||(t--,e[f-1]+="}")}s||o?(u[f]=1,e.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?e.push(c):(p>h?(t++,e.push(a+c+"{")):e.push(a+c),l=h))}}n=e.join("\n"),n+=Array(t+1).join("}")}}();var en=J[t]();if(null===en||Q.offset!==n.length){var un=Math.max(Q.offset,X.offset),rn=n.length>un?n.charAt(un):null,on=Q.offset>X.offset?Q:X;throw new this.SyntaxError(V(ln),rn,un,on.line,on.column)}return en},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,e,u,r){function o(n,t){var e,u;switch(n.length){case 0:e="end of input";break;case 1:e=n[0];break;default:e=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return u=t?l(t):"end of input","Expected "+e+" but "+u+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=e,this.line=u,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file diff --git a/dist/siml.angular.js b/dist/siml.angular.js index 021a72e..26363bc 100644 --- a/dist/siml.angular.js +++ b/dist/siml.angular.js @@ -1,594 +1,594 @@ /** * SIML (c) James Padolsey 2013 - * @version 0.3.6 + * @version 0.3.7 * @license https://github.com/padolsey/SIML/blob/master/LICENSE-MIT * @info http://github.com/padolsey/SIML */ -(function() { +(function() { -var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; -(function() { - - 'use strict'; - - var push = [].push; - var unshift = [].unshift; - - var DEFAULT_TAG = 'div'; - var DEFAULT_INDENTATION = ' '; - - var SINGULAR_TAGS = { - input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, - source: 1, area: 1, base: 1, col: 1 - }; - - var DEFAULT_DIRECTIVES = { - _fillHTML: { - type: 'CONTENT', - make: function(_, children, t) { - return t; - } - }, - _default: { - type: 'CONTENT', - make: function(dir) { - throw new Error('SIML: Directive not resolvable: ' + dir); - } - } - }; - - var DEFAULT_ATTRIBUTES = { - _default: { - type: 'ATTR', - make: function(attrName, value) { - if (value == null) { - return attrName; - } - return attrName + '="' + value + '"'; - } - }, - text: { - type: 'CONTENT', - make: function(_, t) { - return t; - } - } - }; - - var DEFAULT_PSEUDOS = { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input') { - return 'type="' + name + '"'; - } - console.warn('Unknown pseudo class used:', name) - } - } - } - - var objCreate = Object.create || function (o) { - function F() {} - F.prototype = o; - return new F(); - }; - - function isArray(a) { - return {}.toString.call(a) === '[object Array]'; - } - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - function trim(s) { - return String(s).replace(/^\s\s*|\s\s*$/g, ''); - } - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - if (isArray(arr[i])) { - out[i] = deepCopyArray(arr[i]); - } else { - out[i] = arr[i]; - } - } - return out; - } - function defaults(defaults, obj) { - for (var i in defaults) { - if (!obj.hasOwnProperty(i)) { - obj[i] = defaults[i]; - } - } - return obj; - } - - function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { - return function ConfigurableProperty(args, config, parentElement, indentation) { - - this.parentElement = parentElement; - this.indentation = indentation; - - args = [].slice.call(args); - - var propName = args[0]; - var propArguments = args[1]; - var propChildren = args[2]; - - if (propChildren) { - propArguments.unshift(propChildren); - } - - propArguments.unshift(propName); - - var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; - if (!propMaker) { - propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; - } - - if (!propMaker) { - throw new Error('SIML: No fallback for' + args.join()); - } - - this.type = propMaker.type; - this.html = propMaker.make.apply(this, propArguments) || ''; - - }; - } - - function Element(spec, config, parentElement, indentation) { - - this.spec = spec; - this.config = config || {}; - this.parentElement = parentElement || this; - this.indentation = indentation || ''; - this.defaultIndentation = config.indent; - - this.tag = null; - this.id = null; - this.attrs = []; - this.classes = []; - this.pseudos = []; - this.prototypes = objCreate(parentElement && parentElement.prototypes || null); - - this.isSingular = false; - this.multiplier = 1; - - this.isPretty = config.pretty; - - this.htmlOutput = []; - this.htmlContent = []; - this.htmlAttributes = []; - - this.selector = spec[0]; - - this.make(); - this.processChildren(spec[1]); - this.collectOutput(); - - this.html = this.htmlOutput.join(''); - - } - - Element.prototype = { - - make: function() { - - var attributeMap = {}; - var selector = this.selector.slice(); - var selectorPortionType; - var selectorPortion; - - this.augmentPrototypeSelector(selector); - - for (var i = 0, l = selector.length; i < l; ++i) { - selectorPortionType = selector[i][0]; - selectorPortion = selector[i][1]; - switch (selectorPortionType) { - case 'Tag': - if (!this.tag) { - this.tag = selectorPortion; - } - break; - case 'Id': - this.id = selectorPortion; break; - case 'Attr': - var attrName = selectorPortion[0]; - var attr = [attrName, [selectorPortion[1]]]; - // Attributes can only be defined once -- latest wins - if (attributeMap[attrName] != null) { - this.attrs[attributeMap[attrName]] = attr; - } else { - attributeMap[attrName] = this.attrs.push(attr) - 1; - } - break; - case 'Class': - this.classes.push(selectorPortion); break; - case 'Pseudo': - this.pseudos.push(selectorPortion); break; - } - } - - this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); - this.isSingular = this.tag in SINGULAR_TAGS; - - if (this.id) { - this.htmlAttributes.push( - 'id="' + this.id + '"' - ); - } - - if (this.classes.length) { - this.htmlAttributes.push( - 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' - ); - } - - for (var i = 0, l = this.attrs.length; i < l; ++ i) { - this.processProperty('Attribute', this.attrs[i]); - } - - for (var i = 0, l = this.pseudos.length; i < l; ++ i) { - var p = this.pseudos[i]; - if (!isNaN(p[0])) { - this.multiplier = p[0]; - continue; - } - this.processProperty('Pseudo', p); - } - - }, - - collectOutput: function() { - - var indent = this.indentation; - var isPretty = this.isPretty; - var output = this.htmlOutput; - var attrs = this.htmlAttributes; - var content = this.htmlContent; - - output.push(indent + '<' + this.tag); - output.push(attrs.length ? ' ' + attrs.join(' ') : ''); - - if (this.isSingular) { - output.push('/>'); - } else { - - output.push('>'); - - if (content.length) { - isPretty && output.push('\n'); - output.push(content.join(isPretty ? '\n': '')); - isPretty && output.push('\n' + indent); - } - - output.push(''); - - } - - if (this.multiplier > 1) { - var all = output.join(''); - for (var m = this.multiplier - 1; m--;) { - output.push(isPretty ? '\n' : ''); - output.push(all); - } - } - - }, - - _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { - - var tail = excGroup[2]; - var exclusives = excGroup[1]; - - var branches = []; - - attachTail(excGroup, tail); - - for (var n = 0, nl = exclusives.length; n < nl; ++n) { - specChildren[specChildIndex] = exclusives[n]; // Mutate - var newBranch = deepCopyArray(this.spec); // Complete copy - specChildren[specChildIndex] = excGroup; // Return to regular - branches.push(newBranch); - } - - return branches; - - // attachTail - // Goes through children (equal candidacy) looking for places to append - // both the tailChild and tailSelector. Note: they may be placed in diff places - // as in the case of `(a 'c', b)>d` - function attachTail(start, tail, hasAttached) { - - var type = start[0]; - - var children = getChildren(start); - var tailChild = tail[0]; - var tailSelector = tail[1]; - var tailChildType = tail[2]; - - var hasAttached = hasAttached || { - child: false, - selector: false - }; - - if (hasAttached.child && hasAttached.selector) { - return hasAttached; - } - - if (children) { - for (var i = children.length; i-->0;) { - var child = children[i]; - - if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild - child = child[2][0]; - } - - if (tailChildType === 'sibling') { - var cChildren = getChildren(child); - if (!cChildren || !cChildren.length) { - // Add tailChild as sibling of child - children[i] = ['IncGroup', [ - child, - deepCopyArray(tailChild) - ]]; - hasAttached.child = true; //? - if (type === 'IncGroup') { - break; - } else { - continue; - } - } - } - hasAttached = attachTail(child, tail, { - child: false, - selector: false - }); - // Prevent descendants from being attached to more than one sibling - // e.g. a,b or a+b -- should only attach last one (i.e. b) - if (type === 'IncGroup' && hasAttached.child) { - break; - } - } - } - - if (!hasAttached.selector) { - if (start[0] === 'Element') { - if (tailSelector) { - push.apply(start[1][0], tailSelector); - } - hasAttached.selector = true; - } - } - - if (!hasAttached.child) { - if (children) { - if (tailChild) { - children.push(deepCopyArray(tailChild)); - } - hasAttached.child = true; - } - } - - return hasAttached; - } - - function getChildren(child) { - return child[0] === 'Element' ? child[1][1] : - child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? - child[1] : null; - } - }, - - processChildren: function(children) { - - var cl = children.length; - var i; - var childType; - - var exclusiveBranches = []; - - for (i = 0; i < cl; ++i) { - if (children[i][0] === 'ExcGroup') { - push.apply( - exclusiveBranches, - this._makeExclusiveBranches(children[i], children, i) - ); - } - } - - if (exclusiveBranches.length) { - - this.collectOutput = function(){}; - var html = []; - - for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { - var branch = exclusiveBranches[ei]; - html.push( - new (branch[0] === 'RootElement' ? RootElement : Element)( - branch, - this.config, - this.parentElement, - this.indentation - ).html - ); - } - - this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); - - } else { - for (i = 0; i < cl; ++i) { - var child = children[i][1]; - var childType = children[i][0]; - switch (childType) { - case 'Element': - this.processElement(child); - break; - case 'Prototype': - this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); - break; - case 'IncGroup': - this.processIncGroup(child); - break; - case 'ExcGroup': - throw new Error('SIML: Found ExcGroup in unexpected location'); - default: - this.processProperty(childType, child); - } - } - } - - }, - - processElement: function(spec) { - this.htmlContent.push( - new Generator.Element( - spec, - this.config, - this, - this.indentation + this.defaultIndentation - ).html - ); - }, - - processIncGroup: function(spec) { - this.processChildren(spec); - }, - - processProperty: function(type, args) { - // type = Attribute | Directive | Pseudo - var property = new Generator.properties[type]( - args, - this.config, - this, - this.indentation + this.defaultIndentation - ); - if (property.html) { - switch (property.type) { - case 'ATTR': - if (property.html) { - this.htmlAttributes.push(property.html); - } - break; - case 'CONTENT': - if (property.html) { - this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); - } - break; - } - } - }, - - augmentPrototypeSelector: function(selector) { - // Assume tag, if specified, to be first selector portion. - if (selector[0][0] !== 'Tag') { - return selector; - } - // Retrieve and unshift prototype selector portions: - unshift.apply(selector, this.prototypes[selector[0][1]] || []); - return selector; - } - }; - - function RootElement() { - Element.apply(this, arguments); - } - - RootElement.prototype = objCreate(Element.prototype); - RootElement.prototype.make = function(){ - // RootElement is just an empty space - }; - RootElement.prototype.collectOutput = function() { - this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; - }; - RootElement.prototype.processChildren = function() { - this.defaultIndentation = ''; - return Element.prototype.processChildren.apply(this, arguments); - }; - - function Generator(defaultGeneratorConfig) { - this.config = defaults(this.defaultConfig, defaultGeneratorConfig); - } - - Generator.escapeHTML = escapeHTML; - Generator.trim = trim; - Generator.isArray = isArray; - - Generator.Element = Element; - Generator.RootElement = RootElement; - - Generator.properties = { - Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), - Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), - Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) - }; - - Generator.prototype = { - - defaultConfig: { - pretty: true, - curly: false, - indent: DEFAULT_INDENTATION, - directives: {}, - attributes: {}, - pseudos: {}, - toTag: function(t) { - return t; - } - }, - - parse: function(spec, singleRunConfig) { - - singleRunConfig = defaults(this.config, singleRunConfig || {}); - - if (!singleRunConfig.pretty) { - singleRunConfig.indent = ''; - } - - if (!/^[\s\n\r]+$/.test(spec)) { - if (singleRunConfig.curly) { - // TODO: Find a nicer way of passing config to the PEGjs parser: - spec += '\n/*siml:curly=true*/'; - } - try { - spec = siml.PARSER.parse(spec); - } catch(e) { - if (e.line !== undefined && e.column !== undefined) { - throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); - } else { - throw new SyntaxError('SIML: ' + e.message); - } - } - } else { - spec = []; - } - - if (spec[0] === 'Element') { - return new Generator.Element( - spec[1], - singleRunConfig - ).html; - } - - return new Generator.RootElement( - ['RootElement', [['IncGroup', [spec]]]], - singleRunConfig - ).html; - } - - }; - - siml.Generator = Generator; - - siml.defaultGenerator = new Generator({ - pretty: true, - indent: DEFAULT_INDENTATION - }); - - siml.parse = function(s, c) { - return siml.defaultGenerator.parse(s, c); - }; - -}()); +var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; +(function() { + + 'use strict'; + + var push = [].push; + var unshift = [].unshift; + + var DEFAULT_TAG = 'div'; + var DEFAULT_INDENTATION = ' '; + + var SINGULAR_TAGS = { + input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, + source: 1, area: 1, base: 1, col: 1 + }; + + var DEFAULT_DIRECTIVES = { + _fillHTML: { + type: 'CONTENT', + make: function(_, children, t) { + return t; + } + }, + _default: { + type: 'CONTENT', + make: function(dir) { + throw new Error('SIML: Directive not resolvable: ' + dir); + } + } + }; + + var DEFAULT_ATTRIBUTES = { + _default: { + type: 'ATTR', + make: function(attrName, value) { + if (value == null) { + return attrName; + } + return attrName + '="' + value + '"'; + } + }, + text: { + type: 'CONTENT', + make: function(_, t) { + return t; + } + } + }; + + var DEFAULT_PSEUDOS = { + _default: { + type: 'ATTR', + make: function(name) { + if (this.parentElement.tag === 'input') { + return 'type="' + name + '"'; + } + console.warn('Unknown pseudo class used:', name) + } + } + } + + var objCreate = Object.create || function (o) { + function F() {} + F.prototype = o; + return new F(); + }; + + function isArray(a) { + return {}.toString.call(a) === '[object Array]'; + } + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + function trim(s) { + return String(s).replace(/^\s\s*|\s\s*$/g, ''); + } + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + if (isArray(arr[i])) { + out[i] = deepCopyArray(arr[i]); + } else { + out[i] = arr[i]; + } + } + return out; + } + function defaults(defaults, obj) { + for (var i in defaults) { + if (!obj.hasOwnProperty(i)) { + obj[i] = defaults[i]; + } + } + return obj; + } + + function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { + return function ConfigurableProperty(args, config, parentElement, indentation) { + + this.parentElement = parentElement; + this.indentation = indentation; + + args = [].slice.call(args); + + var propName = args[0]; + var propArguments = args[1]; + var propChildren = args[2]; + + if (propChildren) { + propArguments.unshift(propChildren); + } + + propArguments.unshift(propName); + + var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; + if (!propMaker) { + propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; + } + + if (!propMaker) { + throw new Error('SIML: No fallback for' + args.join()); + } + + this.type = propMaker.type; + this.html = propMaker.make.apply(this, propArguments) || ''; + + }; + } + + function Element(spec, config, parentElement, indentation) { + + this.spec = spec; + this.config = config || {}; + this.parentElement = parentElement || this; + this.indentation = indentation || ''; + this.defaultIndentation = config.indent; + + this.tag = null; + this.id = null; + this.attrs = []; + this.classes = []; + this.pseudos = []; + this.prototypes = objCreate(parentElement && parentElement.prototypes || null); + + this.isSingular = false; + this.multiplier = 1; + + this.isPretty = config.pretty; + + this.htmlOutput = []; + this.htmlContent = []; + this.htmlAttributes = []; + + this.selector = spec[0]; + + this.make(); + this.processChildren(spec[1]); + this.collectOutput(); + + this.html = this.htmlOutput.join(''); + + } + + Element.prototype = { + + make: function() { + + var attributeMap = {}; + var selector = this.selector.slice(); + var selectorPortionType; + var selectorPortion; + + this.augmentPrototypeSelector(selector); + + for (var i = 0, l = selector.length; i < l; ++i) { + selectorPortionType = selector[i][0]; + selectorPortion = selector[i][1]; + switch (selectorPortionType) { + case 'Tag': + if (!this.tag) { + this.tag = selectorPortion; + } + break; + case 'Id': + this.id = selectorPortion; break; + case 'Attr': + var attrName = selectorPortion[0]; + var attr = [attrName, [selectorPortion[1]]]; + // Attributes can only be defined once -- latest wins + if (attributeMap[attrName] != null) { + this.attrs[attributeMap[attrName]] = attr; + } else { + attributeMap[attrName] = this.attrs.push(attr) - 1; + } + break; + case 'Class': + this.classes.push(selectorPortion); break; + case 'Pseudo': + this.pseudos.push(selectorPortion); break; + } + } + + this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); + this.isSingular = this.tag in SINGULAR_TAGS; + + if (this.id) { + this.htmlAttributes.push( + 'id="' + this.id + '"' + ); + } + + if (this.classes.length) { + this.htmlAttributes.push( + 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' + ); + } + + for (var i = 0, l = this.attrs.length; i < l; ++ i) { + this.processProperty('Attribute', this.attrs[i]); + } + + for (var i = 0, l = this.pseudos.length; i < l; ++ i) { + var p = this.pseudos[i]; + if (!isNaN(p[0])) { + this.multiplier = p[0]; + continue; + } + this.processProperty('Pseudo', p); + } + + }, + + collectOutput: function() { + + var indent = this.indentation; + var isPretty = this.isPretty; + var output = this.htmlOutput; + var attrs = this.htmlAttributes; + var content = this.htmlContent; + + output.push(indent + '<' + this.tag); + output.push(attrs.length ? ' ' + attrs.join(' ') : ''); + + if (this.isSingular) { + output.push('/>'); + } else { + + output.push('>'); + + if (content.length) { + isPretty && output.push('\n'); + output.push(content.join(isPretty ? '\n': '')); + isPretty && output.push('\n' + indent); + } + + output.push(''); + + } + + if (this.multiplier > 1) { + var all = output.join(''); + for (var m = this.multiplier - 1; m--;) { + output.push(isPretty ? '\n' : ''); + output.push(all); + } + } + + }, + + _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { + + var tail = excGroup[2]; + var exclusives = excGroup[1]; + + var branches = []; + + attachTail(excGroup, tail); + + for (var n = 0, nl = exclusives.length; n < nl; ++n) { + specChildren[specChildIndex] = exclusives[n]; // Mutate + var newBranch = deepCopyArray(this.spec); // Complete copy + specChildren[specChildIndex] = excGroup; // Return to regular + branches.push(newBranch); + } + + return branches; + + // attachTail + // Goes through children (equal candidacy) looking for places to append + // both the tailChild and tailSelector. Note: they may be placed in diff places + // as in the case of `(a 'c', b)>d` + function attachTail(start, tail, hasAttached) { + + var type = start[0]; + + var children = getChildren(start); + var tailChild = tail[0]; + var tailSelector = tail[1]; + var tailChildType = tail[2]; + + var hasAttached = hasAttached || { + child: false, + selector: false + }; + + if (hasAttached.child && hasAttached.selector) { + return hasAttached; + } + + if (children) { + for (var i = children.length; i-->0;) { + var child = children[i]; + + if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild + child = child[2][0]; + } + + if (tailChildType === 'sibling') { + var cChildren = getChildren(child); + if (!cChildren || !cChildren.length) { + // Add tailChild as sibling of child + children[i] = ['IncGroup', [ + child, + deepCopyArray(tailChild) + ]]; + hasAttached.child = true; //? + if (type === 'IncGroup') { + break; + } else { + continue; + } + } + } + hasAttached = attachTail(child, tail, { + child: false, + selector: false + }); + // Prevent descendants from being attached to more than one sibling + // e.g. a,b or a+b -- should only attach last one (i.e. b) + if (type === 'IncGroup' && hasAttached.child) { + break; + } + } + } + + if (!hasAttached.selector) { + if (start[0] === 'Element') { + if (tailSelector) { + push.apply(start[1][0], tailSelector); + } + hasAttached.selector = true; + } + } + + if (!hasAttached.child) { + if (children) { + if (tailChild) { + children.push(deepCopyArray(tailChild)); + } + hasAttached.child = true; + } + } + + return hasAttached; + } + + function getChildren(child) { + return child[0] === 'Element' ? child[1][1] : + child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? + child[1] : null; + } + }, + + processChildren: function(children) { + + var cl = children.length; + var i; + var childType; + + var exclusiveBranches = []; + + for (i = 0; i < cl; ++i) { + if (children[i][0] === 'ExcGroup') { + push.apply( + exclusiveBranches, + this._makeExclusiveBranches(children[i], children, i) + ); + } + } + + if (exclusiveBranches.length) { + + this.collectOutput = function(){}; + var html = []; + + for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { + var branch = exclusiveBranches[ei]; + html.push( + new (branch[0] === 'RootElement' ? RootElement : Element)( + branch, + this.config, + this.parentElement, + this.indentation + ).html + ); + } + + this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); + + } else { + for (i = 0; i < cl; ++i) { + var child = children[i][1]; + var childType = children[i][0]; + switch (childType) { + case 'Element': + this.processElement(child); + break; + case 'Prototype': + this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); + break; + case 'IncGroup': + this.processIncGroup(child); + break; + case 'ExcGroup': + throw new Error('SIML: Found ExcGroup in unexpected location'); + default: + this.processProperty(childType, child); + } + } + } + + }, + + processElement: function(spec) { + this.htmlContent.push( + new Generator.Element( + spec, + this.config, + this, + this.indentation + this.defaultIndentation + ).html + ); + }, + + processIncGroup: function(spec) { + this.processChildren(spec); + }, + + processProperty: function(type, args) { + // type = Attribute | Directive | Pseudo + var property = new Generator.properties[type]( + args, + this.config, + this, + this.indentation + this.defaultIndentation + ); + if (property.html) { + switch (property.type) { + case 'ATTR': + if (property.html) { + this.htmlAttributes.push(property.html); + } + break; + case 'CONTENT': + if (property.html) { + this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); + } + break; + } + } + }, + + augmentPrototypeSelector: function(selector) { + // Assume tag, if specified, to be first selector portion. + if (selector[0][0] !== 'Tag') { + return selector; + } + // Retrieve and unshift prototype selector portions: + unshift.apply(selector, this.prototypes[selector[0][1]] || []); + return selector; + } + }; + + function RootElement() { + Element.apply(this, arguments); + } + + RootElement.prototype = objCreate(Element.prototype); + RootElement.prototype.make = function(){ + // RootElement is just an empty space + }; + RootElement.prototype.collectOutput = function() { + this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; + }; + RootElement.prototype.processChildren = function() { + this.defaultIndentation = ''; + return Element.prototype.processChildren.apply(this, arguments); + }; + + function Generator(defaultGeneratorConfig) { + this.config = defaults(this.defaultConfig, defaultGeneratorConfig); + } + + Generator.escapeHTML = escapeHTML; + Generator.trim = trim; + Generator.isArray = isArray; + + Generator.Element = Element; + Generator.RootElement = RootElement; + + Generator.properties = { + Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), + Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), + Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) + }; + + Generator.prototype = { + + defaultConfig: { + pretty: true, + curly: false, + indent: DEFAULT_INDENTATION, + directives: {}, + attributes: {}, + pseudos: {}, + toTag: function(t) { + return t; + } + }, + + parse: function(spec, singleRunConfig) { + + singleRunConfig = defaults(this.config, singleRunConfig || {}); + + if (!singleRunConfig.pretty) { + singleRunConfig.indent = ''; + } + + if (!/^[\s\n\r]+$/.test(spec)) { + if (singleRunConfig.curly) { + // TODO: Find a nicer way of passing config to the PEGjs parser: + spec += '\n/*siml:curly=true*/'; + } + try { + spec = siml.PARSER.parse(spec); + } catch(e) { + if (e.line !== undefined && e.column !== undefined) { + throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); + } else { + throw new SyntaxError('SIML: ' + e.message); + } + } + } else { + spec = []; + } + + if (spec[0] === 'Element') { + return new Generator.Element( + spec[1], + singleRunConfig + ).html; + } + + return new Generator.RootElement( + ['RootElement', [['IncGroup', [spec]]]], + singleRunConfig + ).html; + } + + }; + + siml.Generator = Generator; + + siml.defaultGenerator = new Generator({ + pretty: true, + indent: DEFAULT_INDENTATION + }); + + siml.parse = function(s, c) { + return siml.defaultGenerator.parse(s, c); + }; + +}()); (function() { @@ -608,9 +608,15 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win ]; var INPUT_TYPES = { - button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, 'datetime-local': 1, - email: 1, file: 1, hidden: 1, image: 1, month: 1, number: 1, password: 1, radio: 1, - range: 1, reset: 1, search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + button: { + button: 1, reset: 1, submit: 1 + }, + input: { + button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, + 'datetime-local': 1, email: 1, file: 1, hidden: 1, image: 1, + month: 1, number: 1, password: 1, radio: 1, range: 1, reset: 1, + search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + } }; var HTML_SHORT_MAP = {}; @@ -643,14 +649,20 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win doctype: doctypeDirective, dt: doctypeDirective }, + getPsuedoType: function(tag, name) { + var types = INPUT_TYPES[tag]; + + if (types && types[name]) { + return 'type="' + name + '"'; + } + }, pseudos: { _default: { type: 'ATTR', make: function(name) { - if (this.parentElement.tag === 'input' && INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - throw new Error('Unknown Pseduo: ' + name); + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + throw new Error('Unknown Pseudo: ' + name); } } } @@ -662,43 +674,42 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win }()); -siml.angular = new siml.Generator({ - pretty: true, - toTag: siml.html5.config.toTag, - directives: { - doctype: siml.html5.config.directives.doctype, - dt: siml.html5.config.directives.dt, - _default: { - type: 'ATTR', - make: function(name, children, value) { - // camelCase -> snake-case - name = name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { - return $1 + '-' + $2.toLowerCase(); - }); - if (name.substring(0, 1) === '$') { - name = name.substring(1); - } else { - name = 'ng-' + name; - } - return name + '="' + value + '"'; - } - } - }, - pseudos: { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input' && siml.html5.INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - // camelCase -> snake-case - return 'ng-' + name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { - return $1 + '-' + $2.toLowerCase(); - }); - } - } - } -}); +siml.angular = new siml.Generator({ + pretty: true, + toTag: siml.html5.config.toTag, + directives: { + doctype: siml.html5.config.directives.doctype, + dt: siml.html5.config.directives.dt, + _default: { + type: 'ATTR', + make: function(name, children, value) { + // camelCase -> snake-case + name = name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { + return $1 + '-' + $2.toLowerCase(); + }); + if (name.substring(0, 1) === '$') { + name = name.substring(1); + } else { + name = 'ng-' + name; + } + return name + '="' + value + '"'; + } + } + }, + pseudos: { + _default: { + type: 'ATTR', + make: function(name) { + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + // camelCase -> snake-case + return 'ng-' + name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { + return $1 + '-' + $2.toLowerCase(); + }); + } + } + } +}); siml.PARSER = (function(){ /* @@ -972,22 +983,22 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body) { - if (!head) { - return ['IncGroup', []]; - } - - var all = []; - - if (head[0] !== 'Element' || body.length) { - head = ['IncGroup', [head]]; - } - - for (var i = 0, l = body.length; i < l; ++i) { - head[1].push(body[i][1]); - } - - return head; + result0 = (function(offset, line, column, head, body) { + if (!head) { + return ['IncGroup', []]; + } + + var all = []; + + if (head[0] !== 'Element' || body.length) { + head = ['IncGroup', [head]]; + } + + for (var i = 0, l = body.length; i < l; ++i) { + head[1].push(body[i][1]); + } + + return head; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -1050,11 +1061,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, a, b) { - if (b[3]) { - return ['IncGroup', [a, b[3]], 'CommaGroup']; - } - return a; + result0 = (function(offset, line, column, a, b) { + if (b[3]) { + return ['IncGroup', [a, b[3]], 'CommaGroup']; + } + return a; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1131,47 +1142,47 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, singleA, tail, decl) { - - var seperator = tail[0] && tail[0].join(''); - var singleB = tail[1]; - - if (decl) { - var declarationChildren = decl[1][0]; - if (singleB) { - if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); - } else { - if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); - } - } - - if (!tail.length) { - return singleA; - } - - switch (singleA[0]) { - case 'Element': { - - if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { - return ['IncGroup', [singleA,singleB]]; - } - - // a>b - if (singleA[0] === 'Element') { - singleA[1][1].push(singleB); - } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { - singleA[1].push(singleB); - } - - return singleA; - } - case 'Prototype': - case 'Directive': - case 'Attribute': { - return ['IncGroup', [singleA, singleB]]; - } - } - return 'ERROR'; + result0 = (function(offset, line, column, singleA, tail, decl) { + + var seperator = tail[0] && tail[0].join(''); + var singleB = tail[1]; + + if (decl) { + var declarationChildren = decl[1][0]; + if (singleB) { + if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); + } else { + if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); + } + } + + if (!tail.length) { + return singleA; + } + + switch (singleA[0]) { + case 'Element': { + + if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { + return ['IncGroup', [singleA,singleB]]; + } + + // a>b + if (singleA[0] === 'Element') { + singleA[1][1].push(singleB); + } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { + singleA[1].push(singleB); + } + + return singleA; + } + case 'Prototype': + case 'Directive': + case 'Attribute': { + return ['IncGroup', [singleA, singleB]]; + } + } + return 'ERROR'; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[3]); } if (result0 === null) { @@ -1329,35 +1340,35 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body, selector, tail) { - - var all = []; - var separator = ''; - - body.unshift([,,,head]); - - if (tail) { - if (tail[0] === 'Declaration') { - tail = tail[1][0]; - } else { - separator = tail[1]; - tail = tail[0]; - } - } - - for (var i = 0, l = body.length; i < l; ++i) { - if (body[i][3][2] === 'CommaGroup') { - // Make (a,b,c/g) be considered as ((a/b/c/)/g) - body[i][3][0] = 'ExcGroup'; - body[i][3][2] = []; - } - all.push(body[i][3]); - } - return ['ExcGroup', all, [ - tail, - selector, - separator.indexOf('+') > -1 ? 'sibling' : 'descendent' - ]]; + result0 = (function(offset, line, column, head, body, selector, tail) { + + var all = []; + var separator = ''; + + body.unshift([,,,head]); + + if (tail) { + if (tail[0] === 'Declaration') { + tail = tail[1][0]; + } else { + separator = tail[1]; + tail = tail[0]; + } + } + + for (var i = 0, l = body.length; i < l; ++i) { + if (body[i][3][2] === 'CommaGroup') { + // Make (a,b,c/g) be considered as ((a/b/c/)/g) + body[i][3][0] = 'ExcGroup'; + body[i][3][2] = []; + } + all.push(body[i][3]); + } + return ['ExcGroup', all, [ + tail, + selector, + separator.indexOf('+') > -1 ? 'sibling' : 'descendent' + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3], result0[6], result0[8]); } if (result0 === null) { @@ -1410,8 +1421,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, separator, tail) { - return [tail, separator]; + result0 = (function(offset, line, column, separator, tail) { + return [tail, separator]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1464,8 +1475,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return ['Declaration', [c]]; + result0 = (function(offset, line, column, c) { + return ['Declaration', [c]]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -1503,8 +1514,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_SingleSelector(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Element', [s,[]]]; + result0 = (function(offset, line, column, s) { + return ['Element', [s,[]]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1643,8 +1654,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, s) { - return ['Prototype', [name, s]]; + result0 = (function(offset, line, column, name, s) { + return ['Prototype', [name, s]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -1735,9 +1746,9 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - s[1].unshift(s[0]); - return s[1]; + result0 = (function(offset, line, column, s) { + s[1].unshift(s[0]); + return s[1]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1756,8 +1767,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return s; + result0 = (function(offset, line, column, s) { + return s; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1873,11 +1884,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, f, t) { - return [ - f === '#' ? 'Id' : 'Class', - t.join('') - ]; + result0 = (function(offset, line, column, f, t) { + return [ + f === '#' ? 'Id' : 'Class', + t.join('') + ]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1981,8 +1992,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attr', [name.join(''), value.length ? value[1] : null]]; + result0 = (function(offset, line, column, name, value) { + return ['Attr', [name.join(''), value.length ? value[1] : null]]; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -2066,13 +2077,13 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, t, arg) { - return ['Pseudo', [ - t.join(''), - [ - arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ] - ]]; + result0 = (function(offset, line, column, t, arg) { + return ['Pseudo', [ + t.join(''), + [ + arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3]); } if (result0 === null) { @@ -2138,8 +2149,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2155,8 +2166,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_html(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [s], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [s], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2231,8 +2242,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2281,8 +2292,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [escapeHTML(value)]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [escapeHTML(value)]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2331,8 +2342,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2389,8 +2400,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { // explicit space - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { // explicit space + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2482,12 +2493,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, args, children) { - return ['Directive', [ - name, - args || [], - children || [] - ]]; + result0 = (function(offset, line, column, name, args, children) { + return ['Directive', [ + name, + args || [], + children || [] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[2]); } if (result0 === null) { @@ -2614,8 +2625,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, args) { - return args; + result0 = (function(offset, line, column, args) { + return args; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2625,10 +2636,10 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_braced(); if (result0 !== null) { - result0 = (function(offset, line, column, arg) { - return [ - arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ]; + result0 = (function(offset, line, column, arg) { + return [ + arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2653,8 +2664,8 @@ siml.PARSER = (function(){ } } if (result0 !== null) { - result0 = (function(offset, line, column) { - return []; + result0 = (function(offset, line, column) { + return []; })(pos0.offset, pos0.line, pos0.column); } if (result0 === null) { @@ -2706,8 +2717,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return [c]; + result0 = (function(offset, line, column, c) { + return [c]; })(pos0.offset, pos0.line, pos0.column, result0[2]); } if (result0 === null) { @@ -2751,8 +2762,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, tail) { - return [tail]; + result0 = (function(offset, line, column, tail) { + return [tail]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2816,8 +2827,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, parts) { - return '(' + parts.join('') + ')'; + result0 = (function(offset, line, column, parts) { + return '(' + parts.join('') + ')'; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2944,12 +2955,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, tail) { - var result = [head]; - for (var i = 0; i < tail.length; i++) { - result.push(tail[i][2]); - } - return result; + result0 = (function(offset, line, column, head, tail) { + var result = [head]; + for (var i = 0; i < tail.length; i++) { + result.push(tail[i][2]); + } + return result; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -2965,8 +2976,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return escapeHTML(s); + result0 = (function(offset, line, column, s) { + return escapeHTML(s); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3100,12 +3111,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - // Replace any `...` quotes within the String: - return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { - var str = stringTokens[ $1 ]; - return str[0] + str[1] + str[0]; - }); + result0 = (function(offset, line, column, d) { + // Replace any `...` quotes within the String: + return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { + var str = stringTokens[ $1 ]; + return str[0] + str[1] + str[0]; + }); })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3172,8 +3183,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - return stringTokens[ d.join('') ][1]; + result0 = (function(offset, line, column, d) { + return stringTokens[ d.join('') ][1]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3219,8 +3230,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, simpleString) { - return simpleString.join(''); + result0 = (function(offset, line, column, simpleString) { + return simpleString.join(''); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3685,145 +3696,145 @@ siml.PARSER = (function(){ } - - - var toString = {}.toString; - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; - } - return out; - } - - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - - // Replace all strings with recoverable string tokens: - // This is done to make comment-removal possible and safe. - var stringTokens = [ - // [ 'QUOTE', 'ACTUAL_STRING' ] ... - ]; - function resolveStringToken(tok) { - return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] - } - - // Replace HTML with string tokens first - input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__HTML_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\`/g, '\`')] - ) - 1); - }); - - input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__STRING_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] - ) - 1); - }); - - input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { - return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); - }); - - var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); - - // Remove comments: - input = input.replace(/\/\*[\s\S]*?\*\//g, ''); - input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); - - (function() { - - // Avoid magical whitespace if we're definitely using curlies: - if (isCurly) { - return; - } - - // Here we impose hierarchical curlies on the basis of indentation - // This is used to make, e.g. - // a\n\tb - // into - // a{b} - - input = input.replace(/^(?:\s*\n)+/g, ''); - - var cur; - var lvl = 0; - var lines = []; - var blockedFromClosing = {}; - var step = null; - - var braceDepth = 0; - var curlyDepth = 0; - - input = input.split(/[\r\n]+/); - - for (var i = 0, l = input.length; i < l; ++i) { - - var line = input[i]; - - var indent = line.match(/^\s*/)[0]; - var indentLevel = (indent.match(/\s/g)||[]).length; - - var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; - - if (step == null && nextIndentLevel !== indentLevel) { - step = nextIndentLevel - indentLevel; - } - - braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; - curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; - - if (/^\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (indentLevel < cur) { // dedent - var diff = cur - indentLevel; - while (1) { - diff -= step; - if (lvl === 0 || diff < 0) { - break; - } - if (blockedFromClosing[i-1]) { - continue; - } - lvl--; - lines[i-1] += '}'; - } - } - - if (curlyDepth || braceDepth) { - // Lines within a curly/brace nesting are blocked from future '}' closes - blockedFromClosing[i] = 1; - lines.push(line); - continue; - } - - line = line.substring(indent.length); - - // Don't seek to add curlies to places where curlies already exist: - if (/[{}]\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (nextIndentLevel > indentLevel) { // indent - lvl++; - lines.push(indent + line + '{'); - } else { - lines.push(indent+line); - } - - cur = indentLevel; - - } - - input = lines.join('\n'); //{{ // make curlies BALANCE for peg! - input += Array(lvl+1).join('}'); - }()); - + + + var toString = {}.toString; + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; + } + return out; + } + + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + + // Replace all strings with recoverable string tokens: + // This is done to make comment-removal possible and safe. + var stringTokens = [ + // [ 'QUOTE', 'ACTUAL_STRING' ] ... + ]; + function resolveStringToken(tok) { + return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] + } + + // Replace HTML with string tokens first + input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__HTML_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\`/g, '\`')] + ) - 1); + }); + + input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__STRING_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] + ) - 1); + }); + + input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { + return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); + }); + + var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); + + // Remove comments: + input = input.replace(/\/\*[\s\S]*?\*\//g, ''); + input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); + + (function() { + + // Avoid magical whitespace if we're definitely using curlies: + if (isCurly) { + return; + } + + // Here we impose hierarchical curlies on the basis of indentation + // This is used to make, e.g. + // a\n\tb + // into + // a{b} + + input = input.replace(/^(?:\s*\n)+/g, ''); + + var cur; + var lvl = 0; + var lines = []; + var blockedFromClosing = {}; + var step = null; + + var braceDepth = 0; + var curlyDepth = 0; + + input = input.split(/[\r\n]+/); + + for (var i = 0, l = input.length; i < l; ++i) { + + var line = input[i]; + + var indent = line.match(/^\s*/)[0]; + var indentLevel = (indent.match(/\s/g)||[]).length; + + var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; + + if (step == null && nextIndentLevel !== indentLevel) { + step = nextIndentLevel - indentLevel; + } + + braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; + curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; + + if (/^\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (indentLevel < cur) { // dedent + var diff = cur - indentLevel; + while (1) { + diff -= step; + if (lvl === 0 || diff < 0) { + break; + } + if (blockedFromClosing[i-1]) { + continue; + } + lvl--; + lines[i-1] += '}'; + } + } + + if (curlyDepth || braceDepth) { + // Lines within a curly/brace nesting are blocked from future '}' closes + blockedFromClosing[i] = 1; + lines.push(line); + continue; + } + + line = line.substring(indent.length); + + // Don't seek to add curlies to places where curlies already exist: + if (/[{}]\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (nextIndentLevel > indentLevel) { // indent + lvl++; + lines.push(indent + line + '{'); + } else { + lines.push(indent+line); + } + + cur = indentLevel; + + } + + input = lines.join('\n'); //{{ // make curlies BALANCE for peg! + input += Array(lvl+1).join('}'); + }()); + var result = parseFunctions[startRule](); diff --git a/dist/siml.angular.min.js b/dist/siml.angular.min.js index 271dede..d5950d9 100644 --- a/dist/siml.angular.min.js +++ b/dist/siml.angular.min.js @@ -1,3 +1,3 @@ -/** SIML v0.3.6 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ -(function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function e(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function u(l){for(var t=[],e=0,r=l.length;r>e;++e)t[e]=n(l[e])?u(l[e]):l[e];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,e,u,r){this.parentElement=u,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=e[l][o]||n[o];if(i||(i=e[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,e){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=e||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",m={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},A={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},e=this.selector.slice();this.augmentPrototypeSelector(e);for(var u=0,r=e.length;r>u;++u)switch(l=e[u][0],n=e[u][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in m,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var u=0,r=this.attrs.length;r>u;++u)this.processProperty("Attribute",this.attrs[u]);for(var u=0,r=this.pseudos.length;r>u;++u){var f=this.pseudos[u];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,e=this.htmlAttributes,u=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(e.length?" "+e.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),u.length&&(n&&t.push("\n"),t.push(u.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function e(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var m=r(p);if(!m||!m.length){if(s[h]=["IncGroup",[p,u(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=e(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(u(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];e(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=u(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,e=l.length,u=[];for(n=0;e>n;++n)"ExcGroup"===l[n][0]&&c.apply(u,this._makeExclusiveBranches(l[n],l,n));if(u.length){this.collectOutput=function(){};for(var r=[],o=0,i=u.length;i>o;++o){var a=u[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;e>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=e,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",A),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(e){throw void 0!==e.line&&void 0!==e.column?new SyntaxError("SIML: Line "+e.line+", column "+e.column+": "+e.message):new SyntaxError("SIML: "+e.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),function(){var n=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","data","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","plaintext","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],t={button:1,checkbox:1,color:1,date:1,datetime:1,"datetime-local":1,email:1,file:1,hidden:1,image:1,month:1,number:1,password:1,radio:1,range:1,reset:1,search:1,submit:1,tel:1,text:1,time:1,url:1,week:1},e={};n.forEach(function(l){if(e[l]=l,l.length>2){var n=l.replace(/[aeiou]+/g,"");n.length>1&&!e[n]&&(e[n]=l)}});var u={type:"CONTENT",make:function(){return""}};l.html5=new l.Generator({pretty:!0,indent:" ",toTag:function(l){return e[l]||l},directives:{doctype:u,dt:u},pseudos:{_default:{type:"ATTR",make:function(l){if("input"===this.parentElement.tag&&t.hasOwnProperty(l))return'type="'+l+'"';throw Error("Unknown Pseduo: "+l)}}}}),l.html5.HTML_SHORT_MAP=e,l.html5.INPUT_TYPES=t}(),l.angular=new l.Generator({pretty:!0,toTag:l.html5.config.toTag,directives:{doctype:l.html5.config.directives.doctype,dt:l.html5.config.directives.dt,_default:{type:"ATTR",make:function(l,n,t){return l=l.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()}),l="$"===l.substring(0,1)?l.substring(1):"ng-"+l,l+'="'+t+'"'}}},pseudos:{_default:{type:"ATTR",make:function(n){return"input"===this.parentElement.tag&&l.html5.INPUT_TYPES.hasOwnProperty(n)?'type="'+n+'"':"ng-"+n.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()})}}}}),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function e(l){var n={};for(var t in l)n[t]=l[t];return n}function u(l,t){for(var e=l.offset+t,u=l.offset;e>u;u++){var r=n.charAt(u);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){Q.offsetX.offset&&(X=e(Q),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=e(Q),a=e(Q),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h));null!==f;){for(o.push(f),h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,Q=e(a))):(l=null,Q=e(a))}else l=null,Q=e(a);else l=null,Q=e(a);return null!==l&&(l=function(l,n,t,e,u){if(!e)return["IncGroup",[]];("Element"!==e[0]||u.length)&&(e=["IncGroup",[e]]);for(var r=0,o=u.length;o>r;++r)e[1].push(u[r][1]);return e}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(Q=e(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=e(Q),h=e(Q),l=f(),null!==l?(p=e(Q),t=U(),null!==t?(44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return u[3]?["IncGroup",[e,u[3]],"CommaGroup"]:e}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(Q=e(a)),l}function f(){var l,t,s,h,p,m,A,g,v,_,y,E;if(_=e(Q),y=e(Q),l=a(),null!==l){for(E=e(Q),t=[],/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,Q=e(E))):(t=null,Q=e(E)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);if(null!==l&&(l=function(l,n,t,e,u,r){var o=u[0]&&u[0].join(""),s=u[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===e[0]&&e[1][1].push(f)}if(!u.length)return e;switch(e[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[e,s]]:("Element"===e[0]?e[1][1].push(s):("IncGroup"===e[0]||"ExcGroup"===e[0])&&e[1].push(s),e);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[e,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(Q=e(_)),null===l){if(_=e(Q),y=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],E=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E));null!==p;)h.push(p),E=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(Q.offset)?(m=")",u(Q,1)):(m=null,0===W&&r('")"')),null!==m){for(A=[],g=d();null!==g;)A.push(g),g=d();null!==A?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,m,A,g,v]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y)}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y);null!==l&&(l=function(l,n,t,e,u,r,o){var s=[],f="";u.unshift([,,,e]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=u.length;c>i;++i)"CommaGroup"===u[i][3][2]&&(u[i][3][0]="ExcGroup",u[i][3][2]=[]),s.push(u[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(Q=e(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=e(Q),s=e(Q),l=[],/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return[u,e]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o))}return l}function c(){var l,t,s,f,i;return f=e(Q),i=e(Q),123===n.charCodeAt(Q.offset)?(l="{",u(Q,1)):(l=null,0===W&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(Q.offset)?(s="}",u(Q,1)):(s=null,0===W&&r('"}"')),null!==s?l=[l,t,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i)),null!==l&&(l=function(l,n,t,e){return["Declaration",[e]]}(f.offset,f.line,f.column,l[1])),null===l&&(Q=e(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=b(),null===l&&(l=C(),null===l&&(l=x()))))),l}function h(){var l,n;return n=e(Q),l=A(),null!==l&&(l=function(l,n,t,e){return["Element",[e,[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=e(Q),h=e(Q),l=m(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));if(null!==s)if(f=A(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);return null!==l&&(l=function(l,n,t,e,u){return["Prototype",[e,u]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),l}function m(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function A(){var l,n,t,u,r;if(u=e(Q),r=e(Q),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,Q=e(r))}else l=null,Q=e(r);if(null!==l&&(l=function(l,n,t,e){return e[1].unshift(e[0]),e[1]}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u)),null===l){if(u=e(Q),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,e){return e}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u))}return l}function d(){var l;return l=v(),null===l&&(l=y(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=e(Q),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,e){return["Tag",e.join("")]}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),l}function v(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[#.]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return["#"===e?"Id":"Class",u.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function _(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),91===n.charCodeAt(Q.offset)?(l="[",u(Q,1)):(l=null,0===W&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]"));else t=null;null!==t?(c=e(Q),61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o?(s=E(),null!==s?o=[o,s]:(o=null,Q=e(c))):(o=null,Q=e(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(Q.offset)?(s="]",u(Q,1)):(s=null,0===W&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Attr",[e.join(""),u.length?u[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function y(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),58===n.charCodeAt(Q.offset)?(l=":",u(Q,1)):(l=null,0===W&&r('":"')),null!==l)if(c=e(Q),W++,t=R(),W--,null===t?t="":(t=null,Q=e(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=z(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Pseudo",[e.join(""),[u&&u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(Q=e(f)),l}function E(){var l,t,o;if(o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return e}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l){if(o=e(Q),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o))}return l}function b(){var l,n;return n=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[Y(e)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function C(){var l,n;return n=e(Q),l=j(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[e],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=O(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[Y(u)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=j(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[ \\t]")),null!==s?(f=O(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a))))),l}function S(){var l,t,o;if(W++,o=e(Q),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=R(),null===l&&(l=j())),W--,0===W&&null===l&&r("AttributeName"),l}function x(){var l,n,t,u,o;return W++,u=e(Q),o=e(Q),l=k(),null!==l?(n=G(),n=null!==n?n:"",null!==n?(t=I(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,Q=e(o))):(l=null,Q=e(o))):(l=null,Q=e(o)),null!==l&&(l=function(l,n,t,e,u,r){return["Directive",[e,u||[],r||[]]]}(u.offset,u.line,u.column,l[0],l[1],l[2])),null===l&&(Q=e(u)),W--,0===W&&null===l&&r("Directive"),l}function k(){var l,t,o,s,f,i;if(f=e(Q),i=e(Q),64===n.charCodeAt(Q.offset)?(l="@",u(Q,1)):(l=null,0===W&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function G(){var l,t,o,s,f;return s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l?(t=$(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),null===l&&(s=e(Q),l=z(),null!==l&&(l=function(l,n,t,e){return[e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(Q=e(s))),l}function I(){var l,t,s,i,c,a;if(c=e(Q),59===n.charCodeAt(Q.offset)?(l=";",u(Q,1)):(l=null,0===W&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(Q=e(c)),null===l&&(c=e(Q),a=e(Q),l=U(),null!==l?(123===n.charCodeAt(Q.offset)?(t="{",u(Q,1)):(t=null,0===W&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(Q.offset)?(i="}",u(Q,1)):(i=null,0===W&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[2])),null===l&&(Q=e(c)),null===l)){for(c=e(Q),a=e(Q),l=[],/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[1])),null===l&&(Q=e(c))}return l}function z(){var l,t,o,s,f;if(s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l){for(t=[],o=z(),null===o&&(o=N());null!==o;)t.push(o),o=z(),null===o&&(o=N());null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return"("+e.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),l}function w(){var l,n,t;if(t=e(Q),n=N(),null!==n)for(l=[];null!==n;)l.push(n),n=N();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function N(){var l;return/^[^()]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[^()]")),l}function $(){var l,t,o,s,f,i,c,a;if(i=e(Q),c=e(Q),l=O(),null!==l){for(t=[],a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==o;)t.push(o),a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==t?l=[l,t]:(l=null,Q=e(c))}else l=null,Q=e(c);return null!==l&&(l=function(l,n,t,e,u){for(var r=[e],o=0;u.length>o;o++)r.push(u[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(Q=e(i)),l}function O(){var l,t,o,s;return o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return Y(e)}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=P(),null===l&&(l=j(),null===l&&(l=Z(),null===l&&(o=e(Q),s=e(Q),"true"===n.substr(Q.offset,4)?(l="true",u(Q,4)):(l=null,0===W&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),"false"===n.substr(Q.offset,5)?(l="false",u(Q,5)):(l=null,0===W&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(Q=e(o))))))),l}function R(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__STRING_TOKEN___%%"===n.substr(Q.offset,21)?(l="%%__STRING_TOKEN___%%",u(Q,21)):(l=null,0===W&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("String"),l}function j(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__HTML_TOKEN___%%"===n.substr(Q.offset,19)?(l="%%__HTML_TOKEN___%%",u(Q,19)):(l=null,0===W&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("HTML"),l}function P(){var l,t,o;if(W++,o=e(Q),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),W--,0===W&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,u,o,s;return W++,o=e(Q),s=e(Q),l=M(),null!==l?(n=L(),null!==n?(t=D(),null!==t?(u=U(),null!==u?l=[l,n,t,u]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u,r){return parseFloat(e+u+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=L(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return parseFloat(e)}(o.offset,o.line,o.column,l[0])),null===l&&(Q=e(o))))),W--,0===W&&null===l&&r("number"),l}function M(){var l,t,o,s,f;return s=e(Q),f=e(Q),l=B(),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return e+u}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),null===l&&(l=K(),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=B(),null!==t?(o=H(),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return"-"+e+u}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(Q=e(s)),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return"-"+e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s))))),l}function L(){var l,t,o,s;return o=e(Q),s=e(Q),46===n.charCodeAt(Q.offset)?(l=".",u(Q,1)):(l=null,0===W&&r('"."')),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return"."+e}(o.offset,o.line,o.column,l[1])),null===l&&(Q=e(o)),l}function D(){var l,n,t,u;return t=e(Q),u=e(Q),l=F(),null!==l?(n=H(),null!==n?l=[l,n]:(l=null,Q=e(u))):(l=null,Q=e(u)),null!==l&&(l=function(l,n,t,e,u){return e+u}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(Q=e(t)),l}function H(){var l,n,t;if(t=e(Q),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function F(){var l,t,o,s;return o=e(Q),s=e(Q),/^[eE]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return e+u}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),l -}function K(){var l;return/^[0-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(W++,l=[],/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));return W--,0===W&&null===l&&r("whitespace"),l}function V(l){l.sort();for(var n=null,t=[],e=0;l.length>e;e++)l[e]!==n&&(t.push(l[e]),n=l[e]);return t}function Y(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var J={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:m,SingleSelector:A,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:y,selectorAttrValue:E,Text:b,HTML:C,Attribute:T,attributeName:S,Directive:x,DirectiveName:k,DirectiveArguments:G,DirectiveChildren:I,braced:z,nonBraceCharacters:w,nonBraceCharacter:N,arrayElements:$,value:O,string:R,html:j,simpleString:P,number:Z,"int":M,frac:L,exp:D,digits:H,e:F,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===J[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var Q={offset:0,line:1,column:1,seenCR:!1},W=0,X={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,e=[],u={},r=null,o=0,s=0;n=n.split(/[\r\n]+/);for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))e.push(c);else{if(l>h)for(var m=l-h;;){if(m-=r,0===t||0>m)break;u[f-1]||(t--,e[f-1]+="}")}s||o?(u[f]=1,e.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?e.push(c):(p>h?(t++,e.push(a+c+"{")):e.push(a+c),l=h))}}n=e.join("\n"),n+=Array(t+1).join("}")}}();var en=J[t]();if(null===en||Q.offset!==n.length){var un=Math.max(Q.offset,X.offset),rn=n.length>un?n.charAt(un):null,on=Q.offset>X.offset?Q:X;throw new this.SyntaxError(V(ln),rn,un,on.line,on.column)}return en},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,e,u,r){function o(n,t){var e,u;switch(n.length){case 0:e="end of input";break;case 1:e=n[0];break;default:e=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return u=t?l(t):"end of input","Expected "+e+" but "+u+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=e,this.line=u,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file +/** SIML v0.3.7 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ +(function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function e(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function u(l){for(var t=[],e=0,r=l.length;r>e;++e)t[e]=n(l[e])?u(l[e]):l[e];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,e,u,r){this.parentElement=u,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=e[l][o]||n[o];if(i||(i=e[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,e){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=e||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",m={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},A={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},e=this.selector.slice();this.augmentPrototypeSelector(e);for(var u=0,r=e.length;r>u;++u)switch(l=e[u][0],n=e[u][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in m,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var u=0,r=this.attrs.length;r>u;++u)this.processProperty("Attribute",this.attrs[u]);for(var u=0,r=this.pseudos.length;r>u;++u){var f=this.pseudos[u];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,e=this.htmlAttributes,u=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(e.length?" "+e.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),u.length&&(n&&t.push("\n"),t.push(u.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function e(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var m=r(p);if(!m||!m.length){if(s[h]=["IncGroup",[p,u(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=e(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(u(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];e(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=u(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,e=l.length,u=[];for(n=0;e>n;++n)"ExcGroup"===l[n][0]&&c.apply(u,this._makeExclusiveBranches(l[n],l,n));if(u.length){this.collectOutput=function(){};for(var r=[],o=0,i=u.length;i>o;++o){var a=u[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;e>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=e,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",A),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(e){throw void 0!==e.line&&void 0!==e.column?new SyntaxError("SIML: Line "+e.line+", column "+e.column+": "+e.message):new SyntaxError("SIML: "+e.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),function(){var n=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","data","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","plaintext","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],t={button:{button:1,reset:1,submit:1},input:{button:1,checkbox:1,color:1,date:1,datetime:1,"datetime-local":1,email:1,file:1,hidden:1,image:1,month:1,number:1,password:1,radio:1,range:1,reset:1,search:1,submit:1,tel:1,text:1,time:1,url:1,week:1}},e={};n.forEach(function(l){if(e[l]=l,l.length>2){var n=l.replace(/[aeiou]+/g,"");n.length>1&&!e[n]&&(e[n]=l)}});var u={type:"CONTENT",make:function(){return""}};l.html5=new l.Generator({pretty:!0,indent:" ",toTag:function(l){return e[l]||l},directives:{doctype:u,dt:u},getPsuedoType:function(l,n){var e=t[l];return e&&e[n]?'type="'+n+'"':void 0},pseudos:{_default:{type:"ATTR",make:function(n){var t=l.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(),n);if(t)return t;throw Error("Unknown Pseudo: "+n)}}}}),l.html5.HTML_SHORT_MAP=e,l.html5.INPUT_TYPES=t}(),l.angular=new l.Generator({pretty:!0,toTag:l.html5.config.toTag,directives:{doctype:l.html5.config.directives.doctype,dt:l.html5.config.directives.dt,_default:{type:"ATTR",make:function(l,n,t){return l=l.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()}),l="$"===l.substring(0,1)?l.substring(1):"ng-"+l,l+'="'+t+'"'}}},pseudos:{_default:{type:"ATTR",make:function(n){var t=l.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(),n);return t?t:"ng-"+n.replace(/([a-z])([A-Z])/g,function(l,n,t){return n+"-"+t.toLowerCase()})}}}}),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function e(l){var n={};for(var t in l)n[t]=l[t];return n}function u(l,t){for(var e=l.offset+t,u=l.offset;e>u;u++){var r=n.charAt(u);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){Q.offsetX.offset&&(X=e(Q),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=e(Q),a=e(Q),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h));null!==f;){for(o.push(f),h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,Q=e(a))):(l=null,Q=e(a))}else l=null,Q=e(a);else l=null,Q=e(a);return null!==l&&(l=function(l,n,t,e,u){if(!e)return["IncGroup",[]];("Element"!==e[0]||u.length)&&(e=["IncGroup",[e]]);for(var r=0,o=u.length;o>r;++r)e[1].push(u[r][1]);return e}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(Q=e(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=e(Q),h=e(Q),l=f(),null!==l?(p=e(Q),t=U(),null!==t?(44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return u[3]?["IncGroup",[e,u[3]],"CommaGroup"]:e}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(Q=e(a)),l}function f(){var l,t,s,h,p,m,A,g,v,_,y,E;if(_=e(Q),y=e(Q),l=a(),null!==l){for(E=e(Q),t=[],/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,Q=e(E))):(t=null,Q=e(E)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);if(null!==l&&(l=function(l,n,t,e,u,r){var o=u[0]&&u[0].join(""),s=u[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===e[0]&&e[1][1].push(f)}if(!u.length)return e;switch(e[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[e,s]]:("Element"===e[0]?e[1][1].push(s):("IncGroup"===e[0]||"ExcGroup"===e[0])&&e[1].push(s),e);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[e,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(Q=e(_)),null===l){if(_=e(Q),y=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],E=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E));null!==p;)h.push(p),E=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(Q.offset)?(m=")",u(Q,1)):(m=null,0===W&&r('")"')),null!==m){for(A=[],g=d();null!==g;)A.push(g),g=d();null!==A?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,m,A,g,v]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y)}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y);null!==l&&(l=function(l,n,t,e,u,r,o){var s=[],f="";u.unshift([,,,e]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=u.length;c>i;++i)"CommaGroup"===u[i][3][2]&&(u[i][3][0]="ExcGroup",u[i][3][2]=[]),s.push(u[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(Q=e(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=e(Q),s=e(Q),l=[],/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return[u,e]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o))}return l}function c(){var l,t,s,f,i;return f=e(Q),i=e(Q),123===n.charCodeAt(Q.offset)?(l="{",u(Q,1)):(l=null,0===W&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(Q.offset)?(s="}",u(Q,1)):(s=null,0===W&&r('"}"')),null!==s?l=[l,t,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i)),null!==l&&(l=function(l,n,t,e){return["Declaration",[e]]}(f.offset,f.line,f.column,l[1])),null===l&&(Q=e(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=b(),null===l&&(l=C(),null===l&&(l=x()))))),l}function h(){var l,n;return n=e(Q),l=A(),null!==l&&(l=function(l,n,t,e){return["Element",[e,[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=e(Q),h=e(Q),l=m(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));if(null!==s)if(f=A(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);return null!==l&&(l=function(l,n,t,e,u){return["Prototype",[e,u]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),l}function m(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function A(){var l,n,t,u,r;if(u=e(Q),r=e(Q),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,Q=e(r))}else l=null,Q=e(r);if(null!==l&&(l=function(l,n,t,e){return e[1].unshift(e[0]),e[1]}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u)),null===l){if(u=e(Q),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,e){return e}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u))}return l}function d(){var l;return l=v(),null===l&&(l=y(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=e(Q),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,e){return["Tag",e.join("")]}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),l}function v(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[#.]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return["#"===e?"Id":"Class",u.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function _(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),91===n.charCodeAt(Q.offset)?(l="[",u(Q,1)):(l=null,0===W&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]"));else t=null;null!==t?(c=e(Q),61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o?(s=E(),null!==s?o=[o,s]:(o=null,Q=e(c))):(o=null,Q=e(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(Q.offset)?(s="]",u(Q,1)):(s=null,0===W&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Attr",[e.join(""),u.length?u[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function y(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),58===n.charCodeAt(Q.offset)?(l=":",u(Q,1)):(l=null,0===W&&r('":"')),null!==l)if(c=e(Q),W++,t=R(),W--,null===t?t="":(t=null,Q=e(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=z(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Pseudo",[e.join(""),[u&&u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(Q=e(f)),l}function E(){var l,t,o;if(o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return e}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l){if(o=e(Q),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o))}return l}function b(){var l,n;return n=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[Y(e)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function C(){var l,n;return n=e(Q),l=j(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[e],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=O(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[Y(u)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=j(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[ \\t]")),null!==s?(f=O(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a))))),l}function S(){var l,t,o;if(W++,o=e(Q),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=R(),null===l&&(l=j())),W--,0===W&&null===l&&r("AttributeName"),l}function x(){var l,n,t,u,o;return W++,u=e(Q),o=e(Q),l=k(),null!==l?(n=G(),n=null!==n?n:"",null!==n?(t=I(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,Q=e(o))):(l=null,Q=e(o))):(l=null,Q=e(o)),null!==l&&(l=function(l,n,t,e,u,r){return["Directive",[e,u||[],r||[]]]}(u.offset,u.line,u.column,l[0],l[1],l[2])),null===l&&(Q=e(u)),W--,0===W&&null===l&&r("Directive"),l}function k(){var l,t,o,s,f,i;if(f=e(Q),i=e(Q),64===n.charCodeAt(Q.offset)?(l="@",u(Q,1)):(l=null,0===W&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function G(){var l,t,o,s,f;return s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l?(t=N(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),null===l&&(s=e(Q),l=z(),null!==l&&(l=function(l,n,t,e){return[e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(Q=e(s))),l}function I(){var l,t,s,i,c,a;if(c=e(Q),59===n.charCodeAt(Q.offset)?(l=";",u(Q,1)):(l=null,0===W&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(Q=e(c)),null===l&&(c=e(Q),a=e(Q),l=U(),null!==l?(123===n.charCodeAt(Q.offset)?(t="{",u(Q,1)):(t=null,0===W&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(Q.offset)?(i="}",u(Q,1)):(i=null,0===W&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[2])),null===l&&(Q=e(c)),null===l)){for(c=e(Q),a=e(Q),l=[],/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[1])),null===l&&(Q=e(c))}return l}function z(){var l,t,o,s,f;if(s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l){for(t=[],o=z(),null===o&&(o=$());null!==o;)t.push(o),o=z(),null===o&&(o=$());null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return"("+e.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),l}function w(){var l,n,t;if(t=e(Q),n=$(),null!==n)for(l=[];null!==n;)l.push(n),n=$();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function $(){var l;return/^[^()]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[^()]")),l}function N(){var l,t,o,s,f,i,c,a;if(i=e(Q),c=e(Q),l=O(),null!==l){for(t=[],a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==o;)t.push(o),a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==t?l=[l,t]:(l=null,Q=e(c))}else l=null,Q=e(c);return null!==l&&(l=function(l,n,t,e,u){for(var r=[e],o=0;u.length>o;o++)r.push(u[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(Q=e(i)),l}function O(){var l,t,o,s;return o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return Y(e)}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=P(),null===l&&(l=j(),null===l&&(l=Z(),null===l&&(o=e(Q),s=e(Q),"true"===n.substr(Q.offset,4)?(l="true",u(Q,4)):(l=null,0===W&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),"false"===n.substr(Q.offset,5)?(l="false",u(Q,5)):(l=null,0===W&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(Q=e(o))))))),l}function R(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__STRING_TOKEN___%%"===n.substr(Q.offset,21)?(l="%%__STRING_TOKEN___%%",u(Q,21)):(l=null,0===W&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("String"),l}function j(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__HTML_TOKEN___%%"===n.substr(Q.offset,19)?(l="%%__HTML_TOKEN___%%",u(Q,19)):(l=null,0===W&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("HTML"),l}function P(){var l,t,o;if(W++,o=e(Q),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),W--,0===W&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,u,o,s;return W++,o=e(Q),s=e(Q),l=L(),null!==l?(n=M(),null!==n?(t=D(),null!==t?(u=U(),null!==u?l=[l,n,t,u]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u,r){return parseFloat(e+u+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=M(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return parseFloat(e)}(o.offset,o.line,o.column,l[0])),null===l&&(Q=e(o))))),W--,0===W&&null===l&&r("number"),l}function L(){var l,t,o,s,f;return s=e(Q),f=e(Q),l=B(),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return e+u}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),null===l&&(l=K(),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=B(),null!==t?(o=H(),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return"-"+e+u}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(Q=e(s)),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return"-"+e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s))))),l}function M(){var l,t,o,s;return o=e(Q),s=e(Q),46===n.charCodeAt(Q.offset)?(l=".",u(Q,1)):(l=null,0===W&&r('"."')),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return"."+e}(o.offset,o.line,o.column,l[1])),null===l&&(Q=e(o)),l}function D(){var l,n,t,u;return t=e(Q),u=e(Q),l=F(),null!==l?(n=H(),null!==n?l=[l,n]:(l=null,Q=e(u))):(l=null,Q=e(u)),null!==l&&(l=function(l,n,t,e,u){return e+u}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(Q=e(t)),l}function H(){var l,n,t;if(t=e(Q),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function F(){var l,t,o,s;return o=e(Q),s=e(Q),/^[eE]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return e+u +}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),l}function K(){var l;return/^[0-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(W++,l=[],/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));return W--,0===W&&null===l&&r("whitespace"),l}function V(l){l.sort();for(var n=null,t=[],e=0;l.length>e;e++)l[e]!==n&&(t.push(l[e]),n=l[e]);return t}function Y(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var J={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:m,SingleSelector:A,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:y,selectorAttrValue:E,Text:b,HTML:C,Attribute:T,attributeName:S,Directive:x,DirectiveName:k,DirectiveArguments:G,DirectiveChildren:I,braced:z,nonBraceCharacters:w,nonBraceCharacter:$,arrayElements:N,value:O,string:R,html:j,simpleString:P,number:Z,"int":L,frac:M,exp:D,digits:H,e:F,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===J[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var Q={offset:0,line:1,column:1,seenCR:!1},W=0,X={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,e=[],u={},r=null,o=0,s=0;n=n.split(/[\r\n]+/);for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))e.push(c);else{if(l>h)for(var m=l-h;;){if(m-=r,0===t||0>m)break;u[f-1]||(t--,e[f-1]+="}")}s||o?(u[f]=1,e.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?e.push(c):(p>h?(t++,e.push(a+c+"{")):e.push(a+c),l=h))}}n=e.join("\n"),n+=Array(t+1).join("}")}}();var en=J[t]();if(null===en||Q.offset!==n.length){var un=Math.max(Q.offset,X.offset),rn=n.length>un?n.charAt(un):null,on=Q.offset>X.offset?Q:X;throw new this.SyntaxError(V(ln),rn,un,on.line,on.column)}return en},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,e,u,r){function o(n,t){var e,u;switch(n.length){case 0:e="end of input";break;case 1:e=n[0];break;default:e=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return u=t?l(t):"end of input","Expected "+e+" but "+u+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=e,this.line=u,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file diff --git a/dist/siml.html5.js b/dist/siml.html5.js index 89a9d65..ad7376f 100644 --- a/dist/siml.html5.js +++ b/dist/siml.html5.js @@ -1,594 +1,594 @@ /** * SIML (c) James Padolsey 2013 - * @version 0.3.6 + * @version 0.3.7 * @license https://github.com/padolsey/SIML/blob/master/LICENSE-MIT * @info http://github.com/padolsey/SIML */ -(function() { +(function() { -var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; -(function() { - - 'use strict'; - - var push = [].push; - var unshift = [].unshift; - - var DEFAULT_TAG = 'div'; - var DEFAULT_INDENTATION = ' '; - - var SINGULAR_TAGS = { - input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, - source: 1, area: 1, base: 1, col: 1 - }; - - var DEFAULT_DIRECTIVES = { - _fillHTML: { - type: 'CONTENT', - make: function(_, children, t) { - return t; - } - }, - _default: { - type: 'CONTENT', - make: function(dir) { - throw new Error('SIML: Directive not resolvable: ' + dir); - } - } - }; - - var DEFAULT_ATTRIBUTES = { - _default: { - type: 'ATTR', - make: function(attrName, value) { - if (value == null) { - return attrName; - } - return attrName + '="' + value + '"'; - } - }, - text: { - type: 'CONTENT', - make: function(_, t) { - return t; - } - } - }; - - var DEFAULT_PSEUDOS = { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input') { - return 'type="' + name + '"'; - } - console.warn('Unknown pseudo class used:', name) - } - } - } - - var objCreate = Object.create || function (o) { - function F() {} - F.prototype = o; - return new F(); - }; - - function isArray(a) { - return {}.toString.call(a) === '[object Array]'; - } - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - function trim(s) { - return String(s).replace(/^\s\s*|\s\s*$/g, ''); - } - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - if (isArray(arr[i])) { - out[i] = deepCopyArray(arr[i]); - } else { - out[i] = arr[i]; - } - } - return out; - } - function defaults(defaults, obj) { - for (var i in defaults) { - if (!obj.hasOwnProperty(i)) { - obj[i] = defaults[i]; - } - } - return obj; - } - - function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { - return function ConfigurableProperty(args, config, parentElement, indentation) { - - this.parentElement = parentElement; - this.indentation = indentation; - - args = [].slice.call(args); - - var propName = args[0]; - var propArguments = args[1]; - var propChildren = args[2]; - - if (propChildren) { - propArguments.unshift(propChildren); - } - - propArguments.unshift(propName); - - var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; - if (!propMaker) { - propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; - } - - if (!propMaker) { - throw new Error('SIML: No fallback for' + args.join()); - } - - this.type = propMaker.type; - this.html = propMaker.make.apply(this, propArguments) || ''; - - }; - } - - function Element(spec, config, parentElement, indentation) { - - this.spec = spec; - this.config = config || {}; - this.parentElement = parentElement || this; - this.indentation = indentation || ''; - this.defaultIndentation = config.indent; - - this.tag = null; - this.id = null; - this.attrs = []; - this.classes = []; - this.pseudos = []; - this.prototypes = objCreate(parentElement && parentElement.prototypes || null); - - this.isSingular = false; - this.multiplier = 1; - - this.isPretty = config.pretty; - - this.htmlOutput = []; - this.htmlContent = []; - this.htmlAttributes = []; - - this.selector = spec[0]; - - this.make(); - this.processChildren(spec[1]); - this.collectOutput(); - - this.html = this.htmlOutput.join(''); - - } - - Element.prototype = { - - make: function() { - - var attributeMap = {}; - var selector = this.selector.slice(); - var selectorPortionType; - var selectorPortion; - - this.augmentPrototypeSelector(selector); - - for (var i = 0, l = selector.length; i < l; ++i) { - selectorPortionType = selector[i][0]; - selectorPortion = selector[i][1]; - switch (selectorPortionType) { - case 'Tag': - if (!this.tag) { - this.tag = selectorPortion; - } - break; - case 'Id': - this.id = selectorPortion; break; - case 'Attr': - var attrName = selectorPortion[0]; - var attr = [attrName, [selectorPortion[1]]]; - // Attributes can only be defined once -- latest wins - if (attributeMap[attrName] != null) { - this.attrs[attributeMap[attrName]] = attr; - } else { - attributeMap[attrName] = this.attrs.push(attr) - 1; - } - break; - case 'Class': - this.classes.push(selectorPortion); break; - case 'Pseudo': - this.pseudos.push(selectorPortion); break; - } - } - - this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); - this.isSingular = this.tag in SINGULAR_TAGS; - - if (this.id) { - this.htmlAttributes.push( - 'id="' + this.id + '"' - ); - } - - if (this.classes.length) { - this.htmlAttributes.push( - 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' - ); - } - - for (var i = 0, l = this.attrs.length; i < l; ++ i) { - this.processProperty('Attribute', this.attrs[i]); - } - - for (var i = 0, l = this.pseudos.length; i < l; ++ i) { - var p = this.pseudos[i]; - if (!isNaN(p[0])) { - this.multiplier = p[0]; - continue; - } - this.processProperty('Pseudo', p); - } - - }, - - collectOutput: function() { - - var indent = this.indentation; - var isPretty = this.isPretty; - var output = this.htmlOutput; - var attrs = this.htmlAttributes; - var content = this.htmlContent; - - output.push(indent + '<' + this.tag); - output.push(attrs.length ? ' ' + attrs.join(' ') : ''); - - if (this.isSingular) { - output.push('/>'); - } else { - - output.push('>'); - - if (content.length) { - isPretty && output.push('\n'); - output.push(content.join(isPretty ? '\n': '')); - isPretty && output.push('\n' + indent); - } - - output.push(''); - - } - - if (this.multiplier > 1) { - var all = output.join(''); - for (var m = this.multiplier - 1; m--;) { - output.push(isPretty ? '\n' : ''); - output.push(all); - } - } - - }, - - _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { - - var tail = excGroup[2]; - var exclusives = excGroup[1]; - - var branches = []; - - attachTail(excGroup, tail); - - for (var n = 0, nl = exclusives.length; n < nl; ++n) { - specChildren[specChildIndex] = exclusives[n]; // Mutate - var newBranch = deepCopyArray(this.spec); // Complete copy - specChildren[specChildIndex] = excGroup; // Return to regular - branches.push(newBranch); - } - - return branches; - - // attachTail - // Goes through children (equal candidacy) looking for places to append - // both the tailChild and tailSelector. Note: they may be placed in diff places - // as in the case of `(a 'c', b)>d` - function attachTail(start, tail, hasAttached) { - - var type = start[0]; - - var children = getChildren(start); - var tailChild = tail[0]; - var tailSelector = tail[1]; - var tailChildType = tail[2]; - - var hasAttached = hasAttached || { - child: false, - selector: false - }; - - if (hasAttached.child && hasAttached.selector) { - return hasAttached; - } - - if (children) { - for (var i = children.length; i-->0;) { - var child = children[i]; - - if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild - child = child[2][0]; - } - - if (tailChildType === 'sibling') { - var cChildren = getChildren(child); - if (!cChildren || !cChildren.length) { - // Add tailChild as sibling of child - children[i] = ['IncGroup', [ - child, - deepCopyArray(tailChild) - ]]; - hasAttached.child = true; //? - if (type === 'IncGroup') { - break; - } else { - continue; - } - } - } - hasAttached = attachTail(child, tail, { - child: false, - selector: false - }); - // Prevent descendants from being attached to more than one sibling - // e.g. a,b or a+b -- should only attach last one (i.e. b) - if (type === 'IncGroup' && hasAttached.child) { - break; - } - } - } - - if (!hasAttached.selector) { - if (start[0] === 'Element') { - if (tailSelector) { - push.apply(start[1][0], tailSelector); - } - hasAttached.selector = true; - } - } - - if (!hasAttached.child) { - if (children) { - if (tailChild) { - children.push(deepCopyArray(tailChild)); - } - hasAttached.child = true; - } - } - - return hasAttached; - } - - function getChildren(child) { - return child[0] === 'Element' ? child[1][1] : - child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? - child[1] : null; - } - }, - - processChildren: function(children) { - - var cl = children.length; - var i; - var childType; - - var exclusiveBranches = []; - - for (i = 0; i < cl; ++i) { - if (children[i][0] === 'ExcGroup') { - push.apply( - exclusiveBranches, - this._makeExclusiveBranches(children[i], children, i) - ); - } - } - - if (exclusiveBranches.length) { - - this.collectOutput = function(){}; - var html = []; - - for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { - var branch = exclusiveBranches[ei]; - html.push( - new (branch[0] === 'RootElement' ? RootElement : Element)( - branch, - this.config, - this.parentElement, - this.indentation - ).html - ); - } - - this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); - - } else { - for (i = 0; i < cl; ++i) { - var child = children[i][1]; - var childType = children[i][0]; - switch (childType) { - case 'Element': - this.processElement(child); - break; - case 'Prototype': - this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); - break; - case 'IncGroup': - this.processIncGroup(child); - break; - case 'ExcGroup': - throw new Error('SIML: Found ExcGroup in unexpected location'); - default: - this.processProperty(childType, child); - } - } - } - - }, - - processElement: function(spec) { - this.htmlContent.push( - new Generator.Element( - spec, - this.config, - this, - this.indentation + this.defaultIndentation - ).html - ); - }, - - processIncGroup: function(spec) { - this.processChildren(spec); - }, - - processProperty: function(type, args) { - // type = Attribute | Directive | Pseudo - var property = new Generator.properties[type]( - args, - this.config, - this, - this.indentation + this.defaultIndentation - ); - if (property.html) { - switch (property.type) { - case 'ATTR': - if (property.html) { - this.htmlAttributes.push(property.html); - } - break; - case 'CONTENT': - if (property.html) { - this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); - } - break; - } - } - }, - - augmentPrototypeSelector: function(selector) { - // Assume tag, if specified, to be first selector portion. - if (selector[0][0] !== 'Tag') { - return selector; - } - // Retrieve and unshift prototype selector portions: - unshift.apply(selector, this.prototypes[selector[0][1]] || []); - return selector; - } - }; - - function RootElement() { - Element.apply(this, arguments); - } - - RootElement.prototype = objCreate(Element.prototype); - RootElement.prototype.make = function(){ - // RootElement is just an empty space - }; - RootElement.prototype.collectOutput = function() { - this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; - }; - RootElement.prototype.processChildren = function() { - this.defaultIndentation = ''; - return Element.prototype.processChildren.apply(this, arguments); - }; - - function Generator(defaultGeneratorConfig) { - this.config = defaults(this.defaultConfig, defaultGeneratorConfig); - } - - Generator.escapeHTML = escapeHTML; - Generator.trim = trim; - Generator.isArray = isArray; - - Generator.Element = Element; - Generator.RootElement = RootElement; - - Generator.properties = { - Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), - Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), - Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) - }; - - Generator.prototype = { - - defaultConfig: { - pretty: true, - curly: false, - indent: DEFAULT_INDENTATION, - directives: {}, - attributes: {}, - pseudos: {}, - toTag: function(t) { - return t; - } - }, - - parse: function(spec, singleRunConfig) { - - singleRunConfig = defaults(this.config, singleRunConfig || {}); - - if (!singleRunConfig.pretty) { - singleRunConfig.indent = ''; - } - - if (!/^[\s\n\r]+$/.test(spec)) { - if (singleRunConfig.curly) { - // TODO: Find a nicer way of passing config to the PEGjs parser: - spec += '\n/*siml:curly=true*/'; - } - try { - spec = siml.PARSER.parse(spec); - } catch(e) { - if (e.line !== undefined && e.column !== undefined) { - throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); - } else { - throw new SyntaxError('SIML: ' + e.message); - } - } - } else { - spec = []; - } - - if (spec[0] === 'Element') { - return new Generator.Element( - spec[1], - singleRunConfig - ).html; - } - - return new Generator.RootElement( - ['RootElement', [['IncGroup', [spec]]]], - singleRunConfig - ).html; - } - - }; - - siml.Generator = Generator; - - siml.defaultGenerator = new Generator({ - pretty: true, - indent: DEFAULT_INDENTATION - }); - - siml.parse = function(s, c) { - return siml.defaultGenerator.parse(s, c); - }; - -}()); +var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; +(function() { + + 'use strict'; + + var push = [].push; + var unshift = [].unshift; + + var DEFAULT_TAG = 'div'; + var DEFAULT_INDENTATION = ' '; + + var SINGULAR_TAGS = { + input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, + source: 1, area: 1, base: 1, col: 1 + }; + + var DEFAULT_DIRECTIVES = { + _fillHTML: { + type: 'CONTENT', + make: function(_, children, t) { + return t; + } + }, + _default: { + type: 'CONTENT', + make: function(dir) { + throw new Error('SIML: Directive not resolvable: ' + dir); + } + } + }; + + var DEFAULT_ATTRIBUTES = { + _default: { + type: 'ATTR', + make: function(attrName, value) { + if (value == null) { + return attrName; + } + return attrName + '="' + value + '"'; + } + }, + text: { + type: 'CONTENT', + make: function(_, t) { + return t; + } + } + }; + + var DEFAULT_PSEUDOS = { + _default: { + type: 'ATTR', + make: function(name) { + if (this.parentElement.tag === 'input') { + return 'type="' + name + '"'; + } + console.warn('Unknown pseudo class used:', name) + } + } + } + + var objCreate = Object.create || function (o) { + function F() {} + F.prototype = o; + return new F(); + }; + + function isArray(a) { + return {}.toString.call(a) === '[object Array]'; + } + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + function trim(s) { + return String(s).replace(/^\s\s*|\s\s*$/g, ''); + } + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + if (isArray(arr[i])) { + out[i] = deepCopyArray(arr[i]); + } else { + out[i] = arr[i]; + } + } + return out; + } + function defaults(defaults, obj) { + for (var i in defaults) { + if (!obj.hasOwnProperty(i)) { + obj[i] = defaults[i]; + } + } + return obj; + } + + function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { + return function ConfigurableProperty(args, config, parentElement, indentation) { + + this.parentElement = parentElement; + this.indentation = indentation; + + args = [].slice.call(args); + + var propName = args[0]; + var propArguments = args[1]; + var propChildren = args[2]; + + if (propChildren) { + propArguments.unshift(propChildren); + } + + propArguments.unshift(propName); + + var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; + if (!propMaker) { + propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; + } + + if (!propMaker) { + throw new Error('SIML: No fallback for' + args.join()); + } + + this.type = propMaker.type; + this.html = propMaker.make.apply(this, propArguments) || ''; + + }; + } + + function Element(spec, config, parentElement, indentation) { + + this.spec = spec; + this.config = config || {}; + this.parentElement = parentElement || this; + this.indentation = indentation || ''; + this.defaultIndentation = config.indent; + + this.tag = null; + this.id = null; + this.attrs = []; + this.classes = []; + this.pseudos = []; + this.prototypes = objCreate(parentElement && parentElement.prototypes || null); + + this.isSingular = false; + this.multiplier = 1; + + this.isPretty = config.pretty; + + this.htmlOutput = []; + this.htmlContent = []; + this.htmlAttributes = []; + + this.selector = spec[0]; + + this.make(); + this.processChildren(spec[1]); + this.collectOutput(); + + this.html = this.htmlOutput.join(''); + + } + + Element.prototype = { + + make: function() { + + var attributeMap = {}; + var selector = this.selector.slice(); + var selectorPortionType; + var selectorPortion; + + this.augmentPrototypeSelector(selector); + + for (var i = 0, l = selector.length; i < l; ++i) { + selectorPortionType = selector[i][0]; + selectorPortion = selector[i][1]; + switch (selectorPortionType) { + case 'Tag': + if (!this.tag) { + this.tag = selectorPortion; + } + break; + case 'Id': + this.id = selectorPortion; break; + case 'Attr': + var attrName = selectorPortion[0]; + var attr = [attrName, [selectorPortion[1]]]; + // Attributes can only be defined once -- latest wins + if (attributeMap[attrName] != null) { + this.attrs[attributeMap[attrName]] = attr; + } else { + attributeMap[attrName] = this.attrs.push(attr) - 1; + } + break; + case 'Class': + this.classes.push(selectorPortion); break; + case 'Pseudo': + this.pseudos.push(selectorPortion); break; + } + } + + this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); + this.isSingular = this.tag in SINGULAR_TAGS; + + if (this.id) { + this.htmlAttributes.push( + 'id="' + this.id + '"' + ); + } + + if (this.classes.length) { + this.htmlAttributes.push( + 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' + ); + } + + for (var i = 0, l = this.attrs.length; i < l; ++ i) { + this.processProperty('Attribute', this.attrs[i]); + } + + for (var i = 0, l = this.pseudos.length; i < l; ++ i) { + var p = this.pseudos[i]; + if (!isNaN(p[0])) { + this.multiplier = p[0]; + continue; + } + this.processProperty('Pseudo', p); + } + + }, + + collectOutput: function() { + + var indent = this.indentation; + var isPretty = this.isPretty; + var output = this.htmlOutput; + var attrs = this.htmlAttributes; + var content = this.htmlContent; + + output.push(indent + '<' + this.tag); + output.push(attrs.length ? ' ' + attrs.join(' ') : ''); + + if (this.isSingular) { + output.push('/>'); + } else { + + output.push('>'); + + if (content.length) { + isPretty && output.push('\n'); + output.push(content.join(isPretty ? '\n': '')); + isPretty && output.push('\n' + indent); + } + + output.push(''); + + } + + if (this.multiplier > 1) { + var all = output.join(''); + for (var m = this.multiplier - 1; m--;) { + output.push(isPretty ? '\n' : ''); + output.push(all); + } + } + + }, + + _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { + + var tail = excGroup[2]; + var exclusives = excGroup[1]; + + var branches = []; + + attachTail(excGroup, tail); + + for (var n = 0, nl = exclusives.length; n < nl; ++n) { + specChildren[specChildIndex] = exclusives[n]; // Mutate + var newBranch = deepCopyArray(this.spec); // Complete copy + specChildren[specChildIndex] = excGroup; // Return to regular + branches.push(newBranch); + } + + return branches; + + // attachTail + // Goes through children (equal candidacy) looking for places to append + // both the tailChild and tailSelector. Note: they may be placed in diff places + // as in the case of `(a 'c', b)>d` + function attachTail(start, tail, hasAttached) { + + var type = start[0]; + + var children = getChildren(start); + var tailChild = tail[0]; + var tailSelector = tail[1]; + var tailChildType = tail[2]; + + var hasAttached = hasAttached || { + child: false, + selector: false + }; + + if (hasAttached.child && hasAttached.selector) { + return hasAttached; + } + + if (children) { + for (var i = children.length; i-->0;) { + var child = children[i]; + + if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild + child = child[2][0]; + } + + if (tailChildType === 'sibling') { + var cChildren = getChildren(child); + if (!cChildren || !cChildren.length) { + // Add tailChild as sibling of child + children[i] = ['IncGroup', [ + child, + deepCopyArray(tailChild) + ]]; + hasAttached.child = true; //? + if (type === 'IncGroup') { + break; + } else { + continue; + } + } + } + hasAttached = attachTail(child, tail, { + child: false, + selector: false + }); + // Prevent descendants from being attached to more than one sibling + // e.g. a,b or a+b -- should only attach last one (i.e. b) + if (type === 'IncGroup' && hasAttached.child) { + break; + } + } + } + + if (!hasAttached.selector) { + if (start[0] === 'Element') { + if (tailSelector) { + push.apply(start[1][0], tailSelector); + } + hasAttached.selector = true; + } + } + + if (!hasAttached.child) { + if (children) { + if (tailChild) { + children.push(deepCopyArray(tailChild)); + } + hasAttached.child = true; + } + } + + return hasAttached; + } + + function getChildren(child) { + return child[0] === 'Element' ? child[1][1] : + child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? + child[1] : null; + } + }, + + processChildren: function(children) { + + var cl = children.length; + var i; + var childType; + + var exclusiveBranches = []; + + for (i = 0; i < cl; ++i) { + if (children[i][0] === 'ExcGroup') { + push.apply( + exclusiveBranches, + this._makeExclusiveBranches(children[i], children, i) + ); + } + } + + if (exclusiveBranches.length) { + + this.collectOutput = function(){}; + var html = []; + + for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { + var branch = exclusiveBranches[ei]; + html.push( + new (branch[0] === 'RootElement' ? RootElement : Element)( + branch, + this.config, + this.parentElement, + this.indentation + ).html + ); + } + + this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); + + } else { + for (i = 0; i < cl; ++i) { + var child = children[i][1]; + var childType = children[i][0]; + switch (childType) { + case 'Element': + this.processElement(child); + break; + case 'Prototype': + this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); + break; + case 'IncGroup': + this.processIncGroup(child); + break; + case 'ExcGroup': + throw new Error('SIML: Found ExcGroup in unexpected location'); + default: + this.processProperty(childType, child); + } + } + } + + }, + + processElement: function(spec) { + this.htmlContent.push( + new Generator.Element( + spec, + this.config, + this, + this.indentation + this.defaultIndentation + ).html + ); + }, + + processIncGroup: function(spec) { + this.processChildren(spec); + }, + + processProperty: function(type, args) { + // type = Attribute | Directive | Pseudo + var property = new Generator.properties[type]( + args, + this.config, + this, + this.indentation + this.defaultIndentation + ); + if (property.html) { + switch (property.type) { + case 'ATTR': + if (property.html) { + this.htmlAttributes.push(property.html); + } + break; + case 'CONTENT': + if (property.html) { + this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); + } + break; + } + } + }, + + augmentPrototypeSelector: function(selector) { + // Assume tag, if specified, to be first selector portion. + if (selector[0][0] !== 'Tag') { + return selector; + } + // Retrieve and unshift prototype selector portions: + unshift.apply(selector, this.prototypes[selector[0][1]] || []); + return selector; + } + }; + + function RootElement() { + Element.apply(this, arguments); + } + + RootElement.prototype = objCreate(Element.prototype); + RootElement.prototype.make = function(){ + // RootElement is just an empty space + }; + RootElement.prototype.collectOutput = function() { + this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; + }; + RootElement.prototype.processChildren = function() { + this.defaultIndentation = ''; + return Element.prototype.processChildren.apply(this, arguments); + }; + + function Generator(defaultGeneratorConfig) { + this.config = defaults(this.defaultConfig, defaultGeneratorConfig); + } + + Generator.escapeHTML = escapeHTML; + Generator.trim = trim; + Generator.isArray = isArray; + + Generator.Element = Element; + Generator.RootElement = RootElement; + + Generator.properties = { + Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), + Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), + Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) + }; + + Generator.prototype = { + + defaultConfig: { + pretty: true, + curly: false, + indent: DEFAULT_INDENTATION, + directives: {}, + attributes: {}, + pseudos: {}, + toTag: function(t) { + return t; + } + }, + + parse: function(spec, singleRunConfig) { + + singleRunConfig = defaults(this.config, singleRunConfig || {}); + + if (!singleRunConfig.pretty) { + singleRunConfig.indent = ''; + } + + if (!/^[\s\n\r]+$/.test(spec)) { + if (singleRunConfig.curly) { + // TODO: Find a nicer way of passing config to the PEGjs parser: + spec += '\n/*siml:curly=true*/'; + } + try { + spec = siml.PARSER.parse(spec); + } catch(e) { + if (e.line !== undefined && e.column !== undefined) { + throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); + } else { + throw new SyntaxError('SIML: ' + e.message); + } + } + } else { + spec = []; + } + + if (spec[0] === 'Element') { + return new Generator.Element( + spec[1], + singleRunConfig + ).html; + } + + return new Generator.RootElement( + ['RootElement', [['IncGroup', [spec]]]], + singleRunConfig + ).html; + } + + }; + + siml.Generator = Generator; + + siml.defaultGenerator = new Generator({ + pretty: true, + indent: DEFAULT_INDENTATION + }); + + siml.parse = function(s, c) { + return siml.defaultGenerator.parse(s, c); + }; + +}()); (function() { @@ -608,9 +608,15 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win ]; var INPUT_TYPES = { - button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, 'datetime-local': 1, - email: 1, file: 1, hidden: 1, image: 1, month: 1, number: 1, password: 1, radio: 1, - range: 1, reset: 1, search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + button: { + button: 1, reset: 1, submit: 1 + }, + input: { + button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, + 'datetime-local': 1, email: 1, file: 1, hidden: 1, image: 1, + month: 1, number: 1, password: 1, radio: 1, range: 1, reset: 1, + search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + } }; var HTML_SHORT_MAP = {}; @@ -643,14 +649,20 @@ var siml = typeof module != 'undefined' && module.exports ? module.exports : win doctype: doctypeDirective, dt: doctypeDirective }, + getPsuedoType: function(tag, name) { + var types = INPUT_TYPES[tag]; + + if (types && types[name]) { + return 'type="' + name + '"'; + } + }, pseudos: { _default: { type: 'ATTR', make: function(name) { - if (this.parentElement.tag === 'input' && INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - throw new Error('Unknown Pseduo: ' + name); + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + throw new Error('Unknown Pseudo: ' + name); } } } @@ -934,22 +946,22 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body) { - if (!head) { - return ['IncGroup', []]; - } - - var all = []; - - if (head[0] !== 'Element' || body.length) { - head = ['IncGroup', [head]]; - } - - for (var i = 0, l = body.length; i < l; ++i) { - head[1].push(body[i][1]); - } - - return head; + result0 = (function(offset, line, column, head, body) { + if (!head) { + return ['IncGroup', []]; + } + + var all = []; + + if (head[0] !== 'Element' || body.length) { + head = ['IncGroup', [head]]; + } + + for (var i = 0, l = body.length; i < l; ++i) { + head[1].push(body[i][1]); + } + + return head; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -1012,11 +1024,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, a, b) { - if (b[3]) { - return ['IncGroup', [a, b[3]], 'CommaGroup']; - } - return a; + result0 = (function(offset, line, column, a, b) { + if (b[3]) { + return ['IncGroup', [a, b[3]], 'CommaGroup']; + } + return a; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1093,47 +1105,47 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, singleA, tail, decl) { - - var seperator = tail[0] && tail[0].join(''); - var singleB = tail[1]; - - if (decl) { - var declarationChildren = decl[1][0]; - if (singleB) { - if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); - } else { - if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); - } - } - - if (!tail.length) { - return singleA; - } - - switch (singleA[0]) { - case 'Element': { - - if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { - return ['IncGroup', [singleA,singleB]]; - } - - // a>b - if (singleA[0] === 'Element') { - singleA[1][1].push(singleB); - } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { - singleA[1].push(singleB); - } - - return singleA; - } - case 'Prototype': - case 'Directive': - case 'Attribute': { - return ['IncGroup', [singleA, singleB]]; - } - } - return 'ERROR'; + result0 = (function(offset, line, column, singleA, tail, decl) { + + var seperator = tail[0] && tail[0].join(''); + var singleB = tail[1]; + + if (decl) { + var declarationChildren = decl[1][0]; + if (singleB) { + if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); + } else { + if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); + } + } + + if (!tail.length) { + return singleA; + } + + switch (singleA[0]) { + case 'Element': { + + if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { + return ['IncGroup', [singleA,singleB]]; + } + + // a>b + if (singleA[0] === 'Element') { + singleA[1][1].push(singleB); + } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { + singleA[1].push(singleB); + } + + return singleA; + } + case 'Prototype': + case 'Directive': + case 'Attribute': { + return ['IncGroup', [singleA, singleB]]; + } + } + return 'ERROR'; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[3]); } if (result0 === null) { @@ -1291,35 +1303,35 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body, selector, tail) { - - var all = []; - var separator = ''; - - body.unshift([,,,head]); - - if (tail) { - if (tail[0] === 'Declaration') { - tail = tail[1][0]; - } else { - separator = tail[1]; - tail = tail[0]; - } - } - - for (var i = 0, l = body.length; i < l; ++i) { - if (body[i][3][2] === 'CommaGroup') { - // Make (a,b,c/g) be considered as ((a/b/c/)/g) - body[i][3][0] = 'ExcGroup'; - body[i][3][2] = []; - } - all.push(body[i][3]); - } - return ['ExcGroup', all, [ - tail, - selector, - separator.indexOf('+') > -1 ? 'sibling' : 'descendent' - ]]; + result0 = (function(offset, line, column, head, body, selector, tail) { + + var all = []; + var separator = ''; + + body.unshift([,,,head]); + + if (tail) { + if (tail[0] === 'Declaration') { + tail = tail[1][0]; + } else { + separator = tail[1]; + tail = tail[0]; + } + } + + for (var i = 0, l = body.length; i < l; ++i) { + if (body[i][3][2] === 'CommaGroup') { + // Make (a,b,c/g) be considered as ((a/b/c/)/g) + body[i][3][0] = 'ExcGroup'; + body[i][3][2] = []; + } + all.push(body[i][3]); + } + return ['ExcGroup', all, [ + tail, + selector, + separator.indexOf('+') > -1 ? 'sibling' : 'descendent' + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3], result0[6], result0[8]); } if (result0 === null) { @@ -1372,8 +1384,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, separator, tail) { - return [tail, separator]; + result0 = (function(offset, line, column, separator, tail) { + return [tail, separator]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1426,8 +1438,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return ['Declaration', [c]]; + result0 = (function(offset, line, column, c) { + return ['Declaration', [c]]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -1465,8 +1477,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_SingleSelector(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Element', [s,[]]]; + result0 = (function(offset, line, column, s) { + return ['Element', [s,[]]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1605,8 +1617,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, s) { - return ['Prototype', [name, s]]; + result0 = (function(offset, line, column, name, s) { + return ['Prototype', [name, s]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -1697,9 +1709,9 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - s[1].unshift(s[0]); - return s[1]; + result0 = (function(offset, line, column, s) { + s[1].unshift(s[0]); + return s[1]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1718,8 +1730,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return s; + result0 = (function(offset, line, column, s) { + return s; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1835,11 +1847,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, f, t) { - return [ - f === '#' ? 'Id' : 'Class', - t.join('') - ]; + result0 = (function(offset, line, column, f, t) { + return [ + f === '#' ? 'Id' : 'Class', + t.join('') + ]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1943,8 +1955,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attr', [name.join(''), value.length ? value[1] : null]]; + result0 = (function(offset, line, column, name, value) { + return ['Attr', [name.join(''), value.length ? value[1] : null]]; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -2028,13 +2040,13 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, t, arg) { - return ['Pseudo', [ - t.join(''), - [ - arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ] - ]]; + result0 = (function(offset, line, column, t, arg) { + return ['Pseudo', [ + t.join(''), + [ + arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3]); } if (result0 === null) { @@ -2100,8 +2112,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2117,8 +2129,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_html(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [s], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [s], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2193,8 +2205,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2243,8 +2255,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [escapeHTML(value)]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [escapeHTML(value)]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2293,8 +2305,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2351,8 +2363,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { // explicit space - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { // explicit space + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2444,12 +2456,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, args, children) { - return ['Directive', [ - name, - args || [], - children || [] - ]]; + result0 = (function(offset, line, column, name, args, children) { + return ['Directive', [ + name, + args || [], + children || [] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[2]); } if (result0 === null) { @@ -2576,8 +2588,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, args) { - return args; + result0 = (function(offset, line, column, args) { + return args; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2587,10 +2599,10 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_braced(); if (result0 !== null) { - result0 = (function(offset, line, column, arg) { - return [ - arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ]; + result0 = (function(offset, line, column, arg) { + return [ + arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2615,8 +2627,8 @@ siml.PARSER = (function(){ } } if (result0 !== null) { - result0 = (function(offset, line, column) { - return []; + result0 = (function(offset, line, column) { + return []; })(pos0.offset, pos0.line, pos0.column); } if (result0 === null) { @@ -2668,8 +2680,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return [c]; + result0 = (function(offset, line, column, c) { + return [c]; })(pos0.offset, pos0.line, pos0.column, result0[2]); } if (result0 === null) { @@ -2713,8 +2725,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, tail) { - return [tail]; + result0 = (function(offset, line, column, tail) { + return [tail]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2778,8 +2790,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, parts) { - return '(' + parts.join('') + ')'; + result0 = (function(offset, line, column, parts) { + return '(' + parts.join('') + ')'; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2906,12 +2918,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, tail) { - var result = [head]; - for (var i = 0; i < tail.length; i++) { - result.push(tail[i][2]); - } - return result; + result0 = (function(offset, line, column, head, tail) { + var result = [head]; + for (var i = 0; i < tail.length; i++) { + result.push(tail[i][2]); + } + return result; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -2927,8 +2939,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return escapeHTML(s); + result0 = (function(offset, line, column, s) { + return escapeHTML(s); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3062,12 +3074,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - // Replace any `...` quotes within the String: - return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { - var str = stringTokens[ $1 ]; - return str[0] + str[1] + str[0]; - }); + result0 = (function(offset, line, column, d) { + // Replace any `...` quotes within the String: + return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { + var str = stringTokens[ $1 ]; + return str[0] + str[1] + str[0]; + }); })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3134,8 +3146,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - return stringTokens[ d.join('') ][1]; + result0 = (function(offset, line, column, d) { + return stringTokens[ d.join('') ][1]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3181,8 +3193,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, simpleString) { - return simpleString.join(''); + result0 = (function(offset, line, column, simpleString) { + return simpleString.join(''); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3647,145 +3659,145 @@ siml.PARSER = (function(){ } - - - var toString = {}.toString; - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; - } - return out; - } - - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - - // Replace all strings with recoverable string tokens: - // This is done to make comment-removal possible and safe. - var stringTokens = [ - // [ 'QUOTE', 'ACTUAL_STRING' ] ... - ]; - function resolveStringToken(tok) { - return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] - } - - // Replace HTML with string tokens first - input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__HTML_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\`/g, '\`')] - ) - 1); - }); - - input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__STRING_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] - ) - 1); - }); - - input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { - return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); - }); - - var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); - - // Remove comments: - input = input.replace(/\/\*[\s\S]*?\*\//g, ''); - input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); - - (function() { - - // Avoid magical whitespace if we're definitely using curlies: - if (isCurly) { - return; - } - - // Here we impose hierarchical curlies on the basis of indentation - // This is used to make, e.g. - // a\n\tb - // into - // a{b} - - input = input.replace(/^(?:\s*\n)+/g, ''); - - var cur; - var lvl = 0; - var lines = []; - var blockedFromClosing = {}; - var step = null; - - var braceDepth = 0; - var curlyDepth = 0; - - input = input.split(/[\r\n]+/); - - for (var i = 0, l = input.length; i < l; ++i) { - - var line = input[i]; - - var indent = line.match(/^\s*/)[0]; - var indentLevel = (indent.match(/\s/g)||[]).length; - - var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; - - if (step == null && nextIndentLevel !== indentLevel) { - step = nextIndentLevel - indentLevel; - } - - braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; - curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; - - if (/^\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (indentLevel < cur) { // dedent - var diff = cur - indentLevel; - while (1) { - diff -= step; - if (lvl === 0 || diff < 0) { - break; - } - if (blockedFromClosing[i-1]) { - continue; - } - lvl--; - lines[i-1] += '}'; - } - } - - if (curlyDepth || braceDepth) { - // Lines within a curly/brace nesting are blocked from future '}' closes - blockedFromClosing[i] = 1; - lines.push(line); - continue; - } - - line = line.substring(indent.length); - - // Don't seek to add curlies to places where curlies already exist: - if (/[{}]\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (nextIndentLevel > indentLevel) { // indent - lvl++; - lines.push(indent + line + '{'); - } else { - lines.push(indent+line); - } - - cur = indentLevel; - - } - - input = lines.join('\n'); //{{ // make curlies BALANCE for peg! - input += Array(lvl+1).join('}'); - }()); - + + + var toString = {}.toString; + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; + } + return out; + } + + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + + // Replace all strings with recoverable string tokens: + // This is done to make comment-removal possible and safe. + var stringTokens = [ + // [ 'QUOTE', 'ACTUAL_STRING' ] ... + ]; + function resolveStringToken(tok) { + return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] + } + + // Replace HTML with string tokens first + input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__HTML_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\`/g, '\`')] + ) - 1); + }); + + input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__STRING_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] + ) - 1); + }); + + input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { + return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); + }); + + var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); + + // Remove comments: + input = input.replace(/\/\*[\s\S]*?\*\//g, ''); + input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); + + (function() { + + // Avoid magical whitespace if we're definitely using curlies: + if (isCurly) { + return; + } + + // Here we impose hierarchical curlies on the basis of indentation + // This is used to make, e.g. + // a\n\tb + // into + // a{b} + + input = input.replace(/^(?:\s*\n)+/g, ''); + + var cur; + var lvl = 0; + var lines = []; + var blockedFromClosing = {}; + var step = null; + + var braceDepth = 0; + var curlyDepth = 0; + + input = input.split(/[\r\n]+/); + + for (var i = 0, l = input.length; i < l; ++i) { + + var line = input[i]; + + var indent = line.match(/^\s*/)[0]; + var indentLevel = (indent.match(/\s/g)||[]).length; + + var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; + + if (step == null && nextIndentLevel !== indentLevel) { + step = nextIndentLevel - indentLevel; + } + + braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; + curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; + + if (/^\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (indentLevel < cur) { // dedent + var diff = cur - indentLevel; + while (1) { + diff -= step; + if (lvl === 0 || diff < 0) { + break; + } + if (blockedFromClosing[i-1]) { + continue; + } + lvl--; + lines[i-1] += '}'; + } + } + + if (curlyDepth || braceDepth) { + // Lines within a curly/brace nesting are blocked from future '}' closes + blockedFromClosing[i] = 1; + lines.push(line); + continue; + } + + line = line.substring(indent.length); + + // Don't seek to add curlies to places where curlies already exist: + if (/[{}]\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (nextIndentLevel > indentLevel) { // indent + lvl++; + lines.push(indent + line + '{'); + } else { + lines.push(indent+line); + } + + cur = indentLevel; + + } + + input = lines.join('\n'); //{{ // make curlies BALANCE for peg! + input += Array(lvl+1).join('}'); + }()); + var result = parseFunctions[startRule](); diff --git a/dist/siml.html5.min.js b/dist/siml.html5.min.js index 5045bb8..b50b892 100644 --- a/dist/siml.html5.min.js +++ b/dist/siml.html5.min.js @@ -1,3 +1,3 @@ -/** SIML v0.3.6 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ -(function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function e(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function u(l){for(var t=[],e=0,r=l.length;r>e;++e)t[e]=n(l[e])?u(l[e]):l[e];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,e,u,r){this.parentElement=u,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=e[l][o]||n[o];if(i||(i=e[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,e){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=e||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",m={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},A={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},e=this.selector.slice();this.augmentPrototypeSelector(e);for(var u=0,r=e.length;r>u;++u)switch(l=e[u][0],n=e[u][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in m,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var u=0,r=this.attrs.length;r>u;++u)this.processProperty("Attribute",this.attrs[u]);for(var u=0,r=this.pseudos.length;r>u;++u){var f=this.pseudos[u];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,e=this.htmlAttributes,u=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(e.length?" "+e.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),u.length&&(n&&t.push("\n"),t.push(u.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function e(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var m=r(p);if(!m||!m.length){if(s[h]=["IncGroup",[p,u(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=e(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(u(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];e(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=u(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,e=l.length,u=[];for(n=0;e>n;++n)"ExcGroup"===l[n][0]&&c.apply(u,this._makeExclusiveBranches(l[n],l,n));if(u.length){this.collectOutput=function(){};for(var r=[],o=0,i=u.length;i>o;++o){var a=u[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;e>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=e,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",A),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(e){throw void 0!==e.line&&void 0!==e.column?new SyntaxError("SIML: Line "+e.line+", column "+e.column+": "+e.message):new SyntaxError("SIML: "+e.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),function(){var n=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","data","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","plaintext","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],t={button:1,checkbox:1,color:1,date:1,datetime:1,"datetime-local":1,email:1,file:1,hidden:1,image:1,month:1,number:1,password:1,radio:1,range:1,reset:1,search:1,submit:1,tel:1,text:1,time:1,url:1,week:1},e={};n.forEach(function(l){if(e[l]=l,l.length>2){var n=l.replace(/[aeiou]+/g,"");n.length>1&&!e[n]&&(e[n]=l)}});var u={type:"CONTENT",make:function(){return""}};l.html5=new l.Generator({pretty:!0,indent:" ",toTag:function(l){return e[l]||l},directives:{doctype:u,dt:u},pseudos:{_default:{type:"ATTR",make:function(l){if("input"===this.parentElement.tag&&t.hasOwnProperty(l))return'type="'+l+'"';throw Error("Unknown Pseduo: "+l)}}}}),l.html5.HTML_SHORT_MAP=e,l.html5.INPUT_TYPES=t}(),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function e(l){var n={};for(var t in l)n[t]=l[t];return n}function u(l,t){for(var e=l.offset+t,u=l.offset;e>u;u++){var r=n.charAt(u);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){Q.offsetX.offset&&(X=e(Q),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=e(Q),a=e(Q),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h));null!==f;){for(o.push(f),h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,Q=e(a))):(l=null,Q=e(a))}else l=null,Q=e(a);else l=null,Q=e(a);return null!==l&&(l=function(l,n,t,e,u){if(!e)return["IncGroup",[]];("Element"!==e[0]||u.length)&&(e=["IncGroup",[e]]);for(var r=0,o=u.length;o>r;++r)e[1].push(u[r][1]);return e}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(Q=e(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=e(Q),h=e(Q),l=f(),null!==l?(p=e(Q),t=U(),null!==t?(44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return u[3]?["IncGroup",[e,u[3]],"CommaGroup"]:e}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(Q=e(a)),l}function f(){var l,t,s,h,p,m,A,g,v,_,y,E;if(_=e(Q),y=e(Q),l=a(),null!==l){for(E=e(Q),t=[],/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,Q=e(E))):(t=null,Q=e(E)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);if(null!==l&&(l=function(l,n,t,e,u,r){var o=u[0]&&u[0].join(""),s=u[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===e[0]&&e[1][1].push(f)}if(!u.length)return e;switch(e[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[e,s]]:("Element"===e[0]?e[1][1].push(s):("IncGroup"===e[0]||"ExcGroup"===e[0])&&e[1].push(s),e);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[e,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(Q=e(_)),null===l){if(_=e(Q),y=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],E=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E));null!==p;)h.push(p),E=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E))):(p=null,Q=e(E));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(Q.offset)?(m=")",u(Q,1)):(m=null,0===W&&r('")"')),null!==m){for(A=[],g=d();null!==g;)A.push(g),g=d();null!==A?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,m,A,g,v]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y)}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y);null!==l&&(l=function(l,n,t,e,u,r,o){var s=[],f="";u.unshift([,,,e]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=u.length;c>i;++i)"CommaGroup"===u[i][3][2]&&(u[i][3][0]="ExcGroup",u[i][3][2]=[]),s.push(u[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(Q=e(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=e(Q),s=e(Q),l=[],/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return[u,e]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o))}return l}function c(){var l,t,s,f,i;return f=e(Q),i=e(Q),123===n.charCodeAt(Q.offset)?(l="{",u(Q,1)):(l=null,0===W&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(Q.offset)?(s="}",u(Q,1)):(s=null,0===W&&r('"}"')),null!==s?l=[l,t,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i)),null!==l&&(l=function(l,n,t,e){return["Declaration",[e]]}(f.offset,f.line,f.column,l[1])),null===l&&(Q=e(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=b(),null===l&&(l=C(),null===l&&(l=x()))))),l}function h(){var l,n;return n=e(Q),l=A(),null!==l&&(l=function(l,n,t,e){return["Element",[e,[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=e(Q),h=e(Q),l=m(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));if(null!==s)if(f=A(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);return null!==l&&(l=function(l,n,t,e,u){return["Prototype",[e,u]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),l}function m(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function A(){var l,n,t,u,r;if(u=e(Q),r=e(Q),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,Q=e(r))}else l=null,Q=e(r);if(null!==l&&(l=function(l,n,t,e){return e[1].unshift(e[0]),e[1]}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u)),null===l){if(u=e(Q),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,e){return e}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u))}return l}function d(){var l;return l=v(),null===l&&(l=y(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=e(Q),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,e){return["Tag",e.join("")]}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),l}function v(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[#.]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return["#"===e?"Id":"Class",u.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function _(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),91===n.charCodeAt(Q.offset)?(l="[",u(Q,1)):(l=null,0===W&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]"));else t=null;null!==t?(c=e(Q),61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o?(s=E(),null!==s?o=[o,s]:(o=null,Q=e(c))):(o=null,Q=e(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(Q.offset)?(s="]",u(Q,1)):(s=null,0===W&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Attr",[e.join(""),u.length?u[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function y(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),58===n.charCodeAt(Q.offset)?(l=":",u(Q,1)):(l=null,0===W&&r('":"')),null!==l)if(c=e(Q),W++,t=R(),W--,null===t?t="":(t=null,Q=e(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=w(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Pseudo",[e.join(""),[u&&u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(Q=e(f)),l}function E(){var l,t,o;if(o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return e}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l){if(o=e(Q),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o))}return l}function b(){var l,n;return n=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[Y(e)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function C(){var l,n;return n=e(Q),l=j(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[e],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=O(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[Y(u)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=j(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[ \\t]")),null!==s?(f=O(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a))))),l}function S(){var l,t,o;if(W++,o=e(Q),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=R(),null===l&&(l=j())),W--,0===W&&null===l&&r("AttributeName"),l}function x(){var l,n,t,u,o;return W++,u=e(Q),o=e(Q),l=k(),null!==l?(n=G(),n=null!==n?n:"",null!==n?(t=I(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,Q=e(o))):(l=null,Q=e(o))):(l=null,Q=e(o)),null!==l&&(l=function(l,n,t,e,u,r){return["Directive",[e,u||[],r||[]]]}(u.offset,u.line,u.column,l[0],l[1],l[2])),null===l&&(Q=e(u)),W--,0===W&&null===l&&r("Directive"),l}function k(){var l,t,o,s,f,i;if(f=e(Q),i=e(Q),64===n.charCodeAt(Q.offset)?(l="@",u(Q,1)):(l=null,0===W&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function G(){var l,t,o,s,f;return s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l?(t=$(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),null===l&&(s=e(Q),l=w(),null!==l&&(l=function(l,n,t,e){return[e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(Q=e(s))),l}function I(){var l,t,s,i,c,a;if(c=e(Q),59===n.charCodeAt(Q.offset)?(l=";",u(Q,1)):(l=null,0===W&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(Q=e(c)),null===l&&(c=e(Q),a=e(Q),l=U(),null!==l?(123===n.charCodeAt(Q.offset)?(t="{",u(Q,1)):(t=null,0===W&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(Q.offset)?(i="}",u(Q,1)):(i=null,0===W&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[2])),null===l&&(Q=e(c)),null===l)){for(c=e(Q),a=e(Q),l=[],/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[1])),null===l&&(Q=e(c))}return l}function w(){var l,t,o,s,f;if(s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l){for(t=[],o=w(),null===o&&(o=N());null!==o;)t.push(o),o=w(),null===o&&(o=N());null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return"("+e.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),l}function z(){var l,n,t;if(t=e(Q),n=N(),null!==n)for(l=[];null!==n;)l.push(n),n=N();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function N(){var l;return/^[^()]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[^()]")),l}function $(){var l,t,o,s,f,i,c,a;if(i=e(Q),c=e(Q),l=O(),null!==l){for(t=[],a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==o;)t.push(o),a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==t?l=[l,t]:(l=null,Q=e(c))}else l=null,Q=e(c);return null!==l&&(l=function(l,n,t,e,u){for(var r=[e],o=0;u.length>o;o++)r.push(u[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(Q=e(i)),l}function O(){var l,t,o,s;return o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return Y(e)}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=P(),null===l&&(l=j(),null===l&&(l=Z(),null===l&&(o=e(Q),s=e(Q),"true"===n.substr(Q.offset,4)?(l="true",u(Q,4)):(l=null,0===W&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),"false"===n.substr(Q.offset,5)?(l="false",u(Q,5)):(l=null,0===W&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(Q=e(o))))))),l}function R(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__STRING_TOKEN___%%"===n.substr(Q.offset,21)?(l="%%__STRING_TOKEN___%%",u(Q,21)):(l=null,0===W&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("String"),l}function j(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__HTML_TOKEN___%%"===n.substr(Q.offset,19)?(l="%%__HTML_TOKEN___%%",u(Q,19)):(l=null,0===W&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("HTML"),l}function P(){var l,t,o;if(W++,o=e(Q),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),W--,0===W&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,u,o,s;return W++,o=e(Q),s=e(Q),l=M(),null!==l?(n=L(),null!==n?(t=D(),null!==t?(u=U(),null!==u?l=[l,n,t,u]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u,r){return parseFloat(e+u+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=L(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=M(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return parseFloat(e)}(o.offset,o.line,o.column,l[0])),null===l&&(Q=e(o))))),W--,0===W&&null===l&&r("number"),l}function M(){var l,t,o,s,f;return s=e(Q),f=e(Q),l=B(),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return e+u}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),null===l&&(l=K(),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=B(),null!==t?(o=H(),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return"-"+e+u}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(Q=e(s)),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return"-"+e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s))))),l}function L(){var l,t,o,s;return o=e(Q),s=e(Q),46===n.charCodeAt(Q.offset)?(l=".",u(Q,1)):(l=null,0===W&&r('"."')),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return"."+e}(o.offset,o.line,o.column,l[1])),null===l&&(Q=e(o)),l}function D(){var l,n,t,u;return t=e(Q),u=e(Q),l=F(),null!==l?(n=H(),null!==n?l=[l,n]:(l=null,Q=e(u))):(l=null,Q=e(u)),null!==l&&(l=function(l,n,t,e,u){return e+u}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(Q=e(t)),l}function H(){var l,n,t;if(t=e(Q),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function F(){var l,t,o,s;return o=e(Q),s=e(Q),/^[eE]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return e+u}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),l}function K(){var l;return/^[0-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(W++,l=[],/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]")); -return W--,0===W&&null===l&&r("whitespace"),l}function V(l){l.sort();for(var n=null,t=[],e=0;l.length>e;e++)l[e]!==n&&(t.push(l[e]),n=l[e]);return t}function Y(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var J={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:m,SingleSelector:A,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:y,selectorAttrValue:E,Text:b,HTML:C,Attribute:T,attributeName:S,Directive:x,DirectiveName:k,DirectiveArguments:G,DirectiveChildren:I,braced:w,nonBraceCharacters:z,nonBraceCharacter:N,arrayElements:$,value:O,string:R,html:j,simpleString:P,number:Z,"int":M,frac:L,exp:D,digits:H,e:F,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===J[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var Q={offset:0,line:1,column:1,seenCR:!1},W=0,X={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,e=[],u={},r=null,o=0,s=0;n=n.split(/[\r\n]+/);for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))e.push(c);else{if(l>h)for(var m=l-h;;){if(m-=r,0===t||0>m)break;u[f-1]||(t--,e[f-1]+="}")}s||o?(u[f]=1,e.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?e.push(c):(p>h?(t++,e.push(a+c+"{")):e.push(a+c),l=h))}}n=e.join("\n"),n+=Array(t+1).join("}")}}();var en=J[t]();if(null===en||Q.offset!==n.length){var un=Math.max(Q.offset,X.offset),rn=n.length>un?n.charAt(un):null,on=Q.offset>X.offset?Q:X;throw new this.SyntaxError(V(ln),rn,un,on.line,on.column)}return en},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,e,u,r){function o(n,t){var e,u;switch(n.length){case 0:e="end of input";break;case 1:e=n[0];break;default:e=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return u=t?l(t):"end of input","Expected "+e+" but "+u+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=e,this.line=u,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file +/** SIML v0.3.7 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ +(function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function e(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function u(l){for(var t=[],e=0,r=l.length;r>e;++e)t[e]=n(l[e])?u(l[e]):l[e];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,e,u,r){this.parentElement=u,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=e[l][o]||n[o];if(i||(i=e[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,e){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=e||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",m={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},A={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},e=this.selector.slice();this.augmentPrototypeSelector(e);for(var u=0,r=e.length;r>u;++u)switch(l=e[u][0],n=e[u][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in m,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var u=0,r=this.attrs.length;r>u;++u)this.processProperty("Attribute",this.attrs[u]);for(var u=0,r=this.pseudos.length;r>u;++u){var f=this.pseudos[u];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,e=this.htmlAttributes,u=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(e.length?" "+e.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),u.length&&(n&&t.push("\n"),t.push(u.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function e(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var m=r(p);if(!m||!m.length){if(s[h]=["IncGroup",[p,u(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=e(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(u(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];e(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=u(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,e=l.length,u=[];for(n=0;e>n;++n)"ExcGroup"===l[n][0]&&c.apply(u,this._makeExclusiveBranches(l[n],l,n));if(u.length){this.collectOutput=function(){};for(var r=[],o=0,i=u.length;i>o;++o){var a=u[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;e>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=e,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",A),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(e){throw void 0!==e.line&&void 0!==e.column?new SyntaxError("SIML: Line "+e.line+", column "+e.column+": "+e.message):new SyntaxError("SIML: "+e.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),function(){var n=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","command","data","datalist","dd","del","details","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","main","map","mark","marquee","menu","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","plaintext","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"],t={button:{button:1,reset:1,submit:1},input:{button:1,checkbox:1,color:1,date:1,datetime:1,"datetime-local":1,email:1,file:1,hidden:1,image:1,month:1,number:1,password:1,radio:1,range:1,reset:1,search:1,submit:1,tel:1,text:1,time:1,url:1,week:1}},e={};n.forEach(function(l){if(e[l]=l,l.length>2){var n=l.replace(/[aeiou]+/g,"");n.length>1&&!e[n]&&(e[n]=l)}});var u={type:"CONTENT",make:function(){return""}};l.html5=new l.Generator({pretty:!0,indent:" ",toTag:function(l){return e[l]||l},directives:{doctype:u,dt:u},getPsuedoType:function(l,n){var e=t[l];return e&&e[n]?'type="'+n+'"':void 0},pseudos:{_default:{type:"ATTR",make:function(n){var t=l.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(),n);if(t)return t;throw Error("Unknown Pseudo: "+n)}}}}),l.html5.HTML_SHORT_MAP=e,l.html5.INPUT_TYPES=t}(),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function e(l){var n={};for(var t in l)n[t]=l[t];return n}function u(l,t){for(var e=l.offset+t,u=l.offset;e>u;u++){var r=n.charAt(u);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){Q.offsetX.offset&&(X=e(Q),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=e(Q),a=e(Q),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h));null!==f;){for(o.push(f),h=e(Q),f=[],/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(Q.offset))?(i=n.charAt(Q.offset),u(Q,1)):(i=null,0===W&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,Q=e(h))):(f=null,Q=e(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,Q=e(a))):(l=null,Q=e(a))}else l=null,Q=e(a);else l=null,Q=e(a);return null!==l&&(l=function(l,n,t,e,u){if(!e)return["IncGroup",[]];("Element"!==e[0]||u.length)&&(e=["IncGroup",[e]]);for(var r=0,o=u.length;o>r;++r)e[1].push(u[r][1]);return e}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(Q=e(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=e(Q),h=e(Q),l=f(),null!==l?(p=e(Q),t=U(),null!==t?(44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p))):(t=null,Q=e(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return u[3]?["IncGroup",[e,u[3]],"CommaGroup"]:e}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(Q=e(a)),l}function f(){var l,t,s,h,p,m,A,g,v,_,y,b;if(_=e(Q),y=e(Q),l=a(),null!==l){for(b=e(Q),t=[],/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,Q=e(b))):(t=null,Q=e(b)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);if(null!==l&&(l=function(l,n,t,e,u,r){var o=u[0]&&u[0].join(""),s=u[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===e[0]&&e[1][1].push(f)}if(!u.length)return e;switch(e[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[e,s]]:("Element"===e[0]?e[1][1].push(s):("IncGroup"===e[0]||"ExcGroup"===e[0])&&e[1].push(s),e);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[e,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(Q=e(_)),null===l){if(_=e(Q),y=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],b=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b));null!==p;)h.push(p),b=e(Q),p=U(),null!==p?(47===n.charCodeAt(Q.offset)?(m="/",u(Q,1)):(m=null,0===W&&r('"/"')),null!==m?(A=U(),null!==A?(g=o(),null!==g?p=[p,m,A,g]:(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b))):(p=null,Q=e(b));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(Q.offset)?(m=")",u(Q,1)):(m=null,0===W&&r('")"')),null!==m){for(A=[],g=d();null!==g;)A.push(g),g=d();null!==A?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,m,A,g,v]:(l=null,Q=e(y))):(l=null,Q=e(y))):(l=null,Q=e(y))}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y)}else l=null,Q=e(y);else l=null,Q=e(y);else l=null,Q=e(y);null!==l&&(l=function(l,n,t,e,u,r,o){var s=[],f="";u.unshift([,,,e]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=u.length;c>i;++i)"CommaGroup"===u[i][3][2]&&(u[i][3][0]="ExcGroup",u[i][3][2]=[]),s.push(u[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(Q=e(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=e(Q),s=e(Q),l=[],/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return[u,e]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o))}return l}function c(){var l,t,s,f,i;return f=e(Q),i=e(Q),123===n.charCodeAt(Q.offset)?(l="{",u(Q,1)):(l=null,0===W&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(Q.offset)?(s="}",u(Q,1)):(s=null,0===W&&r('"}"')),null!==s?l=[l,t,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i)),null!==l&&(l=function(l,n,t,e){return["Declaration",[e]]}(f.offset,f.line,f.column,l[1])),null===l&&(Q=e(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=E(),null===l&&(l=C(),null===l&&(l=x()))))),l}function h(){var l,n;return n=e(Q),l=A(),null!==l&&(l=function(l,n,t,e){return["Element",[e,[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=e(Q),h=e(Q),l=m(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(Q.offset))?(f=n.charAt(Q.offset),u(Q,1)):(f=null,0===W&&r("[ \\t]"));if(null!==s)if(f=A(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(Q.offset))?(c=n.charAt(Q.offset),u(Q,1)):(c=null,0===W&&r("[ \\t]"));null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);else l=null,Q=e(h)}else l=null,Q=e(h);return null!==l&&(l=function(l,n,t,e,u){return["Prototype",[e,u]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),l}function m(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function A(){var l,n,t,u,r;if(u=e(Q),r=e(Q),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,Q=e(r))}else l=null,Q=e(r);if(null!==l&&(l=function(l,n,t,e){return e[1].unshift(e[0]),e[1]}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u)),null===l){if(u=e(Q),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,e){return e}(u.offset,u.line,u.column,l)),null===l&&(Q=e(u))}return l}function d(){var l;return l=v(),null===l&&(l=y(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=e(Q),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,e){return["Tag",e.join("")]}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),l}function v(){var l,t,o,s,f;if(s=e(Q),f=e(Q),/^[#.]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e,u){return["#"===e?"Id":"Class",u.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),l}function _(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),91===n.charCodeAt(Q.offset)?(l="[",u(Q,1)):(l=null,0===W&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[^[\\]=]"));else t=null;null!==t?(c=e(Q),61===n.charCodeAt(Q.offset)?(o="=",u(Q,1)):(o=null,0===W&&r('"="')),null!==o?(s=b(),null!==s?o=[o,s]:(o=null,Q=e(c))):(o=null,Q=e(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(Q.offset)?(s="]",u(Q,1)):(s=null,0===W&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Attr",[e.join(""),u.length?u[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function y(){var l,t,o,s,f,i,c;if(f=e(Q),i=e(Q),58===n.charCodeAt(Q.offset)?(l=":",u(Q,1)):(l=null,0===W&&r('":"')),null!==l)if(c=e(Q),W++,t=R(),W--,null===t?t="":(t=null,Q=e(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=w(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,Q=e(i))):(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return["Pseudo",[e.join(""),[u&&u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(Q=e(f)),l}function b(){var l,t,o;if(o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return e}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l){if(o=e(Q),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o))}return l}function E(){var l,n;return n=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[Y(e)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function C(){var l,n;return n=e(Q),l=j(),null!==l&&(l=function(l,n,t,e){return["Directive",["_fillHTML",[e],[]]]}(n.offset,n.line,n.column,l)),null===l&&(Q=e(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=O(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(Q.offset)?(c=";",u(Q,1)):(c=null,0===W&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[Y(u)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(s=U(),null!==s?(f=j(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a)),null===l&&(a=e(Q),h=e(Q),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(Q.offset)?(o=":",u(Q,1)):(o=null,0===W&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[ \\t]")),null!==s?(f=O(),null!==f?l=[l,t,o,s,f]:(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h))):(l=null,Q=e(h)),null!==l&&(l=function(l,n,t,e,u){return["Attribute",[e,[u]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(Q=e(a))))),l}function S(){var l,t,o;if(W++,o=e(Q),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=R(),null===l&&(l=j())),W--,0===W&&null===l&&r("AttributeName"),l}function x(){var l,n,t,u,o;return W++,u=e(Q),o=e(Q),l=k(),null!==l?(n=G(),n=null!==n?n:"",null!==n?(t=I(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,Q=e(o))):(l=null,Q=e(o))):(l=null,Q=e(o)),null!==l&&(l=function(l,n,t,e,u,r){return["Directive",[e,u||[],r||[]]]}(u.offset,u.line,u.column,l[0],l[1],l[2])),null===l&&(Q=e(u)),W--,0===W&&null===l&&r("Directive"),l}function k(){var l,t,o,s,f,i;if(f=e(Q),i=e(Q),64===n.charCodeAt(Q.offset)?(l="@",u(Q,1)):(l=null,0===W&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(Q.offset))?(s=n.charAt(Q.offset),u(Q,1)):(s=null,0===W&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,Q=e(i))}else l=null,Q=e(i);else l=null,Q=e(i);return null!==l&&(l=function(l,n,t,e,u){return e+u.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(Q=e(f)),l}function G(){var l,t,o,s,f;return s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l?(t=$(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),null===l&&(s=e(Q),l=w(),null!==l&&(l=function(l,n,t,e){return[e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(Q=e(s))),l}function I(){var l,t,s,i,c,a;if(c=e(Q),59===n.charCodeAt(Q.offset)?(l=";",u(Q,1)):(l=null,0===W&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(Q=e(c)),null===l&&(c=e(Q),a=e(Q),l=U(),null!==l?(123===n.charCodeAt(Q.offset)?(t="{",u(Q,1)):(t=null,0===W&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(Q.offset)?(i="}",u(Q,1)):(i=null,0===W&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[2])),null===l&&(Q=e(c)),null===l)){for(c=e(Q),a=e(Q),l=[],/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,Q=e(a))):(l=null,Q=e(a)),null!==l&&(l=function(l,n,t,e){return[e]}(c.offset,c.line,c.column,l[1])),null===l&&(Q=e(c))}return l}function w(){var l,t,o,s,f;if(s=e(Q),f=e(Q),40===n.charCodeAt(Q.offset)?(l="(",u(Q,1)):(l=null,0===W&&r('"("')),null!==l){for(t=[],o=w(),null===o&&(o=N());null!==o;)t.push(o),o=w(),null===o&&(o=N());null!==t?(41===n.charCodeAt(Q.offset)?(o=")",u(Q,1)):(o=null,0===W&&r('")"')),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return"("+e.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),l}function z(){var l,n,t;if(t=e(Q),n=N(),null!==n)for(l=[];null!==n;)l.push(n),n=N();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function N(){var l;return/^[^()]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[^()]")),l}function $(){var l,t,o,s,f,i,c,a;if(i=e(Q),c=e(Q),l=O(),null!==l){for(t=[],a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==o;)t.push(o),a=e(Q),44===n.charCodeAt(Q.offset)?(o=",",u(Q,1)):(o=null,0===W&&r('","')),null!==o?(s=U(),null!==s?(f=O(),null!==f?o=[o,s,f]:(o=null,Q=e(a))):(o=null,Q=e(a))):(o=null,Q=e(a));null!==t?l=[l,t]:(l=null,Q=e(c))}else l=null,Q=e(c);return null!==l&&(l=function(l,n,t,e,u){for(var r=[e],o=0;u.length>o;o++)r.push(u[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(Q=e(i)),l}function O(){var l,t,o,s;return o=e(Q),l=R(),null!==l&&(l=function(l,n,t,e){return Y(e)}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),null===l&&(l=P(),null===l&&(l=j(),null===l&&(l=Z(),null===l&&(o=e(Q),s=e(Q),"true"===n.substr(Q.offset,4)?(l="true",u(Q,4)):(l=null,0===W&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),"false"===n.substr(Q.offset,5)?(l="false",u(Q,5)):(l=null,0===W&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(Q=e(o))))))),l}function R(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__STRING_TOKEN___%%"===n.substr(Q.offset,21)?(l="%%__STRING_TOKEN___%%",u(Q,21)):(l=null,0===W&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("String"),l}function j(){var l,t,o,s,f;if(W++,s=e(Q),f=e(Q),"%%__HTML_TOKEN___%%"===n.substr(Q.offset,19)?(l="%%__HTML_TOKEN___%%",u(Q,19)):(l=null,0===W&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(Q.offset))?(o=n.charAt(Q.offset),u(Q,1)):(o=null,0===W&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,Q=e(f))}else l=null,Q=e(f);return null!==l&&(l=function(l,n,t,e){return nn[e.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s)),W--,0===W&&null===l&&r("HTML"),l}function P(){var l,t,o;if(W++,o=e(Q),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(o.offset,o.line,o.column,l)),null===l&&(Q=e(o)),W--,0===W&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,u,o,s;return W++,o=e(Q),s=e(Q),l=L(),null!==l?(n=M(),null!==n?(t=D(),null!==t?(u=U(),null!==u?l=[l,n,t,u]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u,r){return parseFloat(e+u+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=M(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,Q=e(s))):(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return parseFloat(e+u)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),null===l&&(o=e(Q),s=e(Q),l=L(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return parseFloat(e)}(o.offset,o.line,o.column,l[0])),null===l&&(Q=e(o))))),W--,0===W&&null===l&&r("number"),l}function L(){var l,t,o,s,f;return s=e(Q),f=e(Q),l=B(),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return e+u}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(Q=e(s)),null===l&&(l=K(),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=B(),null!==t?(o=H(),null!==o?l=[l,t,o]:(l=null,Q=e(f))):(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e,u){return"-"+e+u}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(Q=e(s)),null===l&&(s=e(Q),f=e(Q),45===n.charCodeAt(Q.offset)?(l="-",u(Q,1)):(l=null,0===W&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,Q=e(f))):(l=null,Q=e(f)),null!==l&&(l=function(l,n,t,e){return"-"+e}(s.offset,s.line,s.column,l[1])),null===l&&(Q=e(s))))),l}function M(){var l,t,o,s;return o=e(Q),s=e(Q),46===n.charCodeAt(Q.offset)?(l=".",u(Q,1)):(l=null,0===W&&r('"."')),null!==l?(t=H(),null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e){return"."+e}(o.offset,o.line,o.column,l[1])),null===l&&(Q=e(o)),l}function D(){var l,n,t,u;return t=e(Q),u=e(Q),l=F(),null!==l?(n=H(),null!==n?l=[l,n]:(l=null,Q=e(u))):(l=null,Q=e(u)),null!==l&&(l=function(l,n,t,e,u){return e+u}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(Q=e(t)),l}function H(){var l,n,t;if(t=e(Q),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,e){return e.join("")}(t.offset,t.line,t.column,l)),null===l&&(Q=e(t)),l}function F(){var l,t,o,s;return o=e(Q),s=e(Q),/^[eE]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,Q=e(s))):(l=null,Q=e(s)),null!==l&&(l=function(l,n,t,e,u){return e+u}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(Q=e(o)),l}function K(){var l;return/^[0-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(Q.offset))?(l=n.charAt(Q.offset),u(Q,1)):(l=null,0===W&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(W++,l=[],/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(Q.offset))?(t=n.charAt(Q.offset),u(Q,1)):(t=null,0===W&&r("[ \\t\\n\\r]")); +return W--,0===W&&null===l&&r("whitespace"),l}function V(l){l.sort();for(var n=null,t=[],e=0;l.length>e;e++)l[e]!==n&&(t.push(l[e]),n=l[e]);return t}function Y(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var J={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:m,SingleSelector:A,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:y,selectorAttrValue:b,Text:E,HTML:C,Attribute:T,attributeName:S,Directive:x,DirectiveName:k,DirectiveArguments:G,DirectiveChildren:I,braced:w,nonBraceCharacters:z,nonBraceCharacter:N,arrayElements:$,value:O,string:R,html:j,simpleString:P,number:Z,"int":L,frac:M,exp:D,digits:H,e:F,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===J[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var Q={offset:0,line:1,column:1,seenCR:!1},W=0,X={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,e=[],u={},r=null,o=0,s=0;n=n.split(/[\r\n]+/);for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))e.push(c);else{if(l>h)for(var m=l-h;;){if(m-=r,0===t||0>m)break;u[f-1]||(t--,e[f-1]+="}")}s||o?(u[f]=1,e.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?e.push(c):(p>h?(t++,e.push(a+c+"{")):e.push(a+c),l=h))}}n=e.join("\n"),n+=Array(t+1).join("}")}}();var en=J[t]();if(null===en||Q.offset!==n.length){var un=Math.max(Q.offset,X.offset),rn=n.length>un?n.charAt(un):null,on=Q.offset>X.offset?Q:X;throw new this.SyntaxError(V(ln),rn,un,on.line,on.column)}return en},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,e,u,r){function o(n,t){var e,u;switch(n.length){case 0:e="end of input";break;case 1:e=n[0];break;default:e=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return u=t?l(t):"end of input","Expected "+e+" but "+u+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=e,this.line=u,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file diff --git a/dist/siml.js b/dist/siml.js index 4641b50..4928ac2 100644 --- a/dist/siml.js +++ b/dist/siml.js @@ -1,594 +1,594 @@ /** * SIML (c) James Padolsey 2013 - * @version 0.3.6 + * @version 0.3.7 * @license https://github.com/padolsey/SIML/blob/master/LICENSE-MIT * @info http://github.com/padolsey/SIML */ -(function() { - -var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; -(function() { - - 'use strict'; - - var push = [].push; - var unshift = [].unshift; - - var DEFAULT_TAG = 'div'; - var DEFAULT_INDENTATION = ' '; - - var SINGULAR_TAGS = { - input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, - source: 1, area: 1, base: 1, col: 1 - }; - - var DEFAULT_DIRECTIVES = { - _fillHTML: { - type: 'CONTENT', - make: function(_, children, t) { - return t; - } - }, - _default: { - type: 'CONTENT', - make: function(dir) { - throw new Error('SIML: Directive not resolvable: ' + dir); - } - } - }; - - var DEFAULT_ATTRIBUTES = { - _default: { - type: 'ATTR', - make: function(attrName, value) { - if (value == null) { - return attrName; - } - return attrName + '="' + value + '"'; - } - }, - text: { - type: 'CONTENT', - make: function(_, t) { - return t; - } - } - }; - - var DEFAULT_PSEUDOS = { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input') { - return 'type="' + name + '"'; - } - console.warn('Unknown pseudo class used:', name) - } - } - } - - var objCreate = Object.create || function (o) { - function F() {} - F.prototype = o; - return new F(); - }; - - function isArray(a) { - return {}.toString.call(a) === '[object Array]'; - } - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - function trim(s) { - return String(s).replace(/^\s\s*|\s\s*$/g, ''); - } - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - if (isArray(arr[i])) { - out[i] = deepCopyArray(arr[i]); - } else { - out[i] = arr[i]; - } - } - return out; - } - function defaults(defaults, obj) { - for (var i in defaults) { - if (!obj.hasOwnProperty(i)) { - obj[i] = defaults[i]; - } - } - return obj; - } - - function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { - return function ConfigurableProperty(args, config, parentElement, indentation) { - - this.parentElement = parentElement; - this.indentation = indentation; - - args = [].slice.call(args); - - var propName = args[0]; - var propArguments = args[1]; - var propChildren = args[2]; - - if (propChildren) { - propArguments.unshift(propChildren); - } - - propArguments.unshift(propName); - - var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; - if (!propMaker) { - propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; - } - - if (!propMaker) { - throw new Error('SIML: No fallback for' + args.join()); - } - - this.type = propMaker.type; - this.html = propMaker.make.apply(this, propArguments) || ''; - - }; - } - - function Element(spec, config, parentElement, indentation) { - - this.spec = spec; - this.config = config || {}; - this.parentElement = parentElement || this; - this.indentation = indentation || ''; - this.defaultIndentation = config.indent; - - this.tag = null; - this.id = null; - this.attrs = []; - this.classes = []; - this.pseudos = []; - this.prototypes = objCreate(parentElement && parentElement.prototypes || null); - - this.isSingular = false; - this.multiplier = 1; - - this.isPretty = config.pretty; - - this.htmlOutput = []; - this.htmlContent = []; - this.htmlAttributes = []; - - this.selector = spec[0]; - - this.make(); - this.processChildren(spec[1]); - this.collectOutput(); - - this.html = this.htmlOutput.join(''); - - } - - Element.prototype = { - - make: function() { - - var attributeMap = {}; - var selector = this.selector.slice(); - var selectorPortionType; - var selectorPortion; - - this.augmentPrototypeSelector(selector); - - for (var i = 0, l = selector.length; i < l; ++i) { - selectorPortionType = selector[i][0]; - selectorPortion = selector[i][1]; - switch (selectorPortionType) { - case 'Tag': - if (!this.tag) { - this.tag = selectorPortion; - } - break; - case 'Id': - this.id = selectorPortion; break; - case 'Attr': - var attrName = selectorPortion[0]; - var attr = [attrName, [selectorPortion[1]]]; - // Attributes can only be defined once -- latest wins - if (attributeMap[attrName] != null) { - this.attrs[attributeMap[attrName]] = attr; - } else { - attributeMap[attrName] = this.attrs.push(attr) - 1; - } - break; - case 'Class': - this.classes.push(selectorPortion); break; - case 'Pseudo': - this.pseudos.push(selectorPortion); break; - } - } - - this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); - this.isSingular = this.tag in SINGULAR_TAGS; - - if (this.id) { - this.htmlAttributes.push( - 'id="' + this.id + '"' - ); - } - - if (this.classes.length) { - this.htmlAttributes.push( - 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' - ); - } - - for (var i = 0, l = this.attrs.length; i < l; ++ i) { - this.processProperty('Attribute', this.attrs[i]); - } - - for (var i = 0, l = this.pseudos.length; i < l; ++ i) { - var p = this.pseudos[i]; - if (!isNaN(p[0])) { - this.multiplier = p[0]; - continue; - } - this.processProperty('Pseudo', p); - } - - }, - - collectOutput: function() { - - var indent = this.indentation; - var isPretty = this.isPretty; - var output = this.htmlOutput; - var attrs = this.htmlAttributes; - var content = this.htmlContent; - - output.push(indent + '<' + this.tag); - output.push(attrs.length ? ' ' + attrs.join(' ') : ''); - - if (this.isSingular) { - output.push('/>'); - } else { - - output.push('>'); - - if (content.length) { - isPretty && output.push('\n'); - output.push(content.join(isPretty ? '\n': '')); - isPretty && output.push('\n' + indent); - } - - output.push(''); - - } - - if (this.multiplier > 1) { - var all = output.join(''); - for (var m = this.multiplier - 1; m--;) { - output.push(isPretty ? '\n' : ''); - output.push(all); - } - } - - }, - - _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { - - var tail = excGroup[2]; - var exclusives = excGroup[1]; - - var branches = []; - - attachTail(excGroup, tail); - - for (var n = 0, nl = exclusives.length; n < nl; ++n) { - specChildren[specChildIndex] = exclusives[n]; // Mutate - var newBranch = deepCopyArray(this.spec); // Complete copy - specChildren[specChildIndex] = excGroup; // Return to regular - branches.push(newBranch); - } - - return branches; - - // attachTail - // Goes through children (equal candidacy) looking for places to append - // both the tailChild and tailSelector. Note: they may be placed in diff places - // as in the case of `(a 'c', b)>d` - function attachTail(start, tail, hasAttached) { - - var type = start[0]; - - var children = getChildren(start); - var tailChild = tail[0]; - var tailSelector = tail[1]; - var tailChildType = tail[2]; - - var hasAttached = hasAttached || { - child: false, - selector: false - }; - - if (hasAttached.child && hasAttached.selector) { - return hasAttached; - } - - if (children) { - for (var i = children.length; i-->0;) { - var child = children[i]; - - if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild - child = child[2][0]; - } - - if (tailChildType === 'sibling') { - var cChildren = getChildren(child); - if (!cChildren || !cChildren.length) { - // Add tailChild as sibling of child - children[i] = ['IncGroup', [ - child, - deepCopyArray(tailChild) - ]]; - hasAttached.child = true; //? - if (type === 'IncGroup') { - break; - } else { - continue; - } - } - } - hasAttached = attachTail(child, tail, { - child: false, - selector: false - }); - // Prevent descendants from being attached to more than one sibling - // e.g. a,b or a+b -- should only attach last one (i.e. b) - if (type === 'IncGroup' && hasAttached.child) { - break; - } - } - } - - if (!hasAttached.selector) { - if (start[0] === 'Element') { - if (tailSelector) { - push.apply(start[1][0], tailSelector); - } - hasAttached.selector = true; - } - } - - if (!hasAttached.child) { - if (children) { - if (tailChild) { - children.push(deepCopyArray(tailChild)); - } - hasAttached.child = true; - } - } - - return hasAttached; - } - - function getChildren(child) { - return child[0] === 'Element' ? child[1][1] : - child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? - child[1] : null; - } - }, - - processChildren: function(children) { - - var cl = children.length; - var i; - var childType; - - var exclusiveBranches = []; - - for (i = 0; i < cl; ++i) { - if (children[i][0] === 'ExcGroup') { - push.apply( - exclusiveBranches, - this._makeExclusiveBranches(children[i], children, i) - ); - } - } - - if (exclusiveBranches.length) { - - this.collectOutput = function(){}; - var html = []; - - for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { - var branch = exclusiveBranches[ei]; - html.push( - new (branch[0] === 'RootElement' ? RootElement : Element)( - branch, - this.config, - this.parentElement, - this.indentation - ).html - ); - } - - this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); - - } else { - for (i = 0; i < cl; ++i) { - var child = children[i][1]; - var childType = children[i][0]; - switch (childType) { - case 'Element': - this.processElement(child); - break; - case 'Prototype': - this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); - break; - case 'IncGroup': - this.processIncGroup(child); - break; - case 'ExcGroup': - throw new Error('SIML: Found ExcGroup in unexpected location'); - default: - this.processProperty(childType, child); - } - } - } - - }, - - processElement: function(spec) { - this.htmlContent.push( - new Generator.Element( - spec, - this.config, - this, - this.indentation + this.defaultIndentation - ).html - ); - }, - - processIncGroup: function(spec) { - this.processChildren(spec); - }, - - processProperty: function(type, args) { - // type = Attribute | Directive | Pseudo - var property = new Generator.properties[type]( - args, - this.config, - this, - this.indentation + this.defaultIndentation - ); - if (property.html) { - switch (property.type) { - case 'ATTR': - if (property.html) { - this.htmlAttributes.push(property.html); - } - break; - case 'CONTENT': - if (property.html) { - this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); - } - break; - } - } - }, - - augmentPrototypeSelector: function(selector) { - // Assume tag, if specified, to be first selector portion. - if (selector[0][0] !== 'Tag') { - return selector; - } - // Retrieve and unshift prototype selector portions: - unshift.apply(selector, this.prototypes[selector[0][1]] || []); - return selector; - } - }; - - function RootElement() { - Element.apply(this, arguments); - } - - RootElement.prototype = objCreate(Element.prototype); - RootElement.prototype.make = function(){ - // RootElement is just an empty space - }; - RootElement.prototype.collectOutput = function() { - this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; - }; - RootElement.prototype.processChildren = function() { - this.defaultIndentation = ''; - return Element.prototype.processChildren.apply(this, arguments); - }; - - function Generator(defaultGeneratorConfig) { - this.config = defaults(this.defaultConfig, defaultGeneratorConfig); - } - - Generator.escapeHTML = escapeHTML; - Generator.trim = trim; - Generator.isArray = isArray; - - Generator.Element = Element; - Generator.RootElement = RootElement; - - Generator.properties = { - Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), - Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), - Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) - }; - - Generator.prototype = { - - defaultConfig: { - pretty: true, - curly: false, - indent: DEFAULT_INDENTATION, - directives: {}, - attributes: {}, - pseudos: {}, - toTag: function(t) { - return t; - } - }, - - parse: function(spec, singleRunConfig) { - - singleRunConfig = defaults(this.config, singleRunConfig || {}); - - if (!singleRunConfig.pretty) { - singleRunConfig.indent = ''; - } - - if (!/^[\s\n\r]+$/.test(spec)) { - if (singleRunConfig.curly) { - // TODO: Find a nicer way of passing config to the PEGjs parser: - spec += '\n/*siml:curly=true*/'; - } - try { - spec = siml.PARSER.parse(spec); - } catch(e) { - if (e.line !== undefined && e.column !== undefined) { - throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); - } else { - throw new SyntaxError('SIML: ' + e.message); - } - } - } else { - spec = []; - } - - if (spec[0] === 'Element') { - return new Generator.Element( - spec[1], - singleRunConfig - ).html; - } - - return new Generator.RootElement( - ['RootElement', [['IncGroup', [spec]]]], - singleRunConfig - ).html; - } - - }; - - siml.Generator = Generator; - - siml.defaultGenerator = new Generator({ - pretty: true, - indent: DEFAULT_INDENTATION - }); - - siml.parse = function(s, c) { - return siml.defaultGenerator.parse(s, c); - }; - -}()); +(function() { + +var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; +(function() { + + 'use strict'; + + var push = [].push; + var unshift = [].unshift; + + var DEFAULT_TAG = 'div'; + var DEFAULT_INDENTATION = ' '; + + var SINGULAR_TAGS = { + input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, + source: 1, area: 1, base: 1, col: 1 + }; + + var DEFAULT_DIRECTIVES = { + _fillHTML: { + type: 'CONTENT', + make: function(_, children, t) { + return t; + } + }, + _default: { + type: 'CONTENT', + make: function(dir) { + throw new Error('SIML: Directive not resolvable: ' + dir); + } + } + }; + + var DEFAULT_ATTRIBUTES = { + _default: { + type: 'ATTR', + make: function(attrName, value) { + if (value == null) { + return attrName; + } + return attrName + '="' + value + '"'; + } + }, + text: { + type: 'CONTENT', + make: function(_, t) { + return t; + } + } + }; + + var DEFAULT_PSEUDOS = { + _default: { + type: 'ATTR', + make: function(name) { + if (this.parentElement.tag === 'input') { + return 'type="' + name + '"'; + } + console.warn('Unknown pseudo class used:', name) + } + } + } + + var objCreate = Object.create || function (o) { + function F() {} + F.prototype = o; + return new F(); + }; + + function isArray(a) { + return {}.toString.call(a) === '[object Array]'; + } + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + function trim(s) { + return String(s).replace(/^\s\s*|\s\s*$/g, ''); + } + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + if (isArray(arr[i])) { + out[i] = deepCopyArray(arr[i]); + } else { + out[i] = arr[i]; + } + } + return out; + } + function defaults(defaults, obj) { + for (var i in defaults) { + if (!obj.hasOwnProperty(i)) { + obj[i] = defaults[i]; + } + } + return obj; + } + + function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { + return function ConfigurableProperty(args, config, parentElement, indentation) { + + this.parentElement = parentElement; + this.indentation = indentation; + + args = [].slice.call(args); + + var propName = args[0]; + var propArguments = args[1]; + var propChildren = args[2]; + + if (propChildren) { + propArguments.unshift(propChildren); + } + + propArguments.unshift(propName); + + var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; + if (!propMaker) { + propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; + } + + if (!propMaker) { + throw new Error('SIML: No fallback for' + args.join()); + } + + this.type = propMaker.type; + this.html = propMaker.make.apply(this, propArguments) || ''; + + }; + } + + function Element(spec, config, parentElement, indentation) { + + this.spec = spec; + this.config = config || {}; + this.parentElement = parentElement || this; + this.indentation = indentation || ''; + this.defaultIndentation = config.indent; + + this.tag = null; + this.id = null; + this.attrs = []; + this.classes = []; + this.pseudos = []; + this.prototypes = objCreate(parentElement && parentElement.prototypes || null); + + this.isSingular = false; + this.multiplier = 1; + + this.isPretty = config.pretty; + + this.htmlOutput = []; + this.htmlContent = []; + this.htmlAttributes = []; + + this.selector = spec[0]; + + this.make(); + this.processChildren(spec[1]); + this.collectOutput(); + + this.html = this.htmlOutput.join(''); + + } + + Element.prototype = { + + make: function() { + + var attributeMap = {}; + var selector = this.selector.slice(); + var selectorPortionType; + var selectorPortion; + + this.augmentPrototypeSelector(selector); + + for (var i = 0, l = selector.length; i < l; ++i) { + selectorPortionType = selector[i][0]; + selectorPortion = selector[i][1]; + switch (selectorPortionType) { + case 'Tag': + if (!this.tag) { + this.tag = selectorPortion; + } + break; + case 'Id': + this.id = selectorPortion; break; + case 'Attr': + var attrName = selectorPortion[0]; + var attr = [attrName, [selectorPortion[1]]]; + // Attributes can only be defined once -- latest wins + if (attributeMap[attrName] != null) { + this.attrs[attributeMap[attrName]] = attr; + } else { + attributeMap[attrName] = this.attrs.push(attr) - 1; + } + break; + case 'Class': + this.classes.push(selectorPortion); break; + case 'Pseudo': + this.pseudos.push(selectorPortion); break; + } + } + + this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); + this.isSingular = this.tag in SINGULAR_TAGS; + + if (this.id) { + this.htmlAttributes.push( + 'id="' + this.id + '"' + ); + } + + if (this.classes.length) { + this.htmlAttributes.push( + 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' + ); + } + + for (var i = 0, l = this.attrs.length; i < l; ++ i) { + this.processProperty('Attribute', this.attrs[i]); + } + + for (var i = 0, l = this.pseudos.length; i < l; ++ i) { + var p = this.pseudos[i]; + if (!isNaN(p[0])) { + this.multiplier = p[0]; + continue; + } + this.processProperty('Pseudo', p); + } + + }, + + collectOutput: function() { + + var indent = this.indentation; + var isPretty = this.isPretty; + var output = this.htmlOutput; + var attrs = this.htmlAttributes; + var content = this.htmlContent; + + output.push(indent + '<' + this.tag); + output.push(attrs.length ? ' ' + attrs.join(' ') : ''); + + if (this.isSingular) { + output.push('/>'); + } else { + + output.push('>'); + + if (content.length) { + isPretty && output.push('\n'); + output.push(content.join(isPretty ? '\n': '')); + isPretty && output.push('\n' + indent); + } + + output.push(''); + + } + + if (this.multiplier > 1) { + var all = output.join(''); + for (var m = this.multiplier - 1; m--;) { + output.push(isPretty ? '\n' : ''); + output.push(all); + } + } + + }, + + _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { + + var tail = excGroup[2]; + var exclusives = excGroup[1]; + + var branches = []; + + attachTail(excGroup, tail); + + for (var n = 0, nl = exclusives.length; n < nl; ++n) { + specChildren[specChildIndex] = exclusives[n]; // Mutate + var newBranch = deepCopyArray(this.spec); // Complete copy + specChildren[specChildIndex] = excGroup; // Return to regular + branches.push(newBranch); + } + + return branches; + + // attachTail + // Goes through children (equal candidacy) looking for places to append + // both the tailChild and tailSelector. Note: they may be placed in diff places + // as in the case of `(a 'c', b)>d` + function attachTail(start, tail, hasAttached) { + + var type = start[0]; + + var children = getChildren(start); + var tailChild = tail[0]; + var tailSelector = tail[1]; + var tailChildType = tail[2]; + + var hasAttached = hasAttached || { + child: false, + selector: false + }; + + if (hasAttached.child && hasAttached.selector) { + return hasAttached; + } + + if (children) { + for (var i = children.length; i-->0;) { + var child = children[i]; + + if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild + child = child[2][0]; + } + + if (tailChildType === 'sibling') { + var cChildren = getChildren(child); + if (!cChildren || !cChildren.length) { + // Add tailChild as sibling of child + children[i] = ['IncGroup', [ + child, + deepCopyArray(tailChild) + ]]; + hasAttached.child = true; //? + if (type === 'IncGroup') { + break; + } else { + continue; + } + } + } + hasAttached = attachTail(child, tail, { + child: false, + selector: false + }); + // Prevent descendants from being attached to more than one sibling + // e.g. a,b or a+b -- should only attach last one (i.e. b) + if (type === 'IncGroup' && hasAttached.child) { + break; + } + } + } + + if (!hasAttached.selector) { + if (start[0] === 'Element') { + if (tailSelector) { + push.apply(start[1][0], tailSelector); + } + hasAttached.selector = true; + } + } + + if (!hasAttached.child) { + if (children) { + if (tailChild) { + children.push(deepCopyArray(tailChild)); + } + hasAttached.child = true; + } + } + + return hasAttached; + } + + function getChildren(child) { + return child[0] === 'Element' ? child[1][1] : + child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? + child[1] : null; + } + }, + + processChildren: function(children) { + + var cl = children.length; + var i; + var childType; + + var exclusiveBranches = []; + + for (i = 0; i < cl; ++i) { + if (children[i][0] === 'ExcGroup') { + push.apply( + exclusiveBranches, + this._makeExclusiveBranches(children[i], children, i) + ); + } + } + + if (exclusiveBranches.length) { + + this.collectOutput = function(){}; + var html = []; + + for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { + var branch = exclusiveBranches[ei]; + html.push( + new (branch[0] === 'RootElement' ? RootElement : Element)( + branch, + this.config, + this.parentElement, + this.indentation + ).html + ); + } + + this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); + + } else { + for (i = 0; i < cl; ++i) { + var child = children[i][1]; + var childType = children[i][0]; + switch (childType) { + case 'Element': + this.processElement(child); + break; + case 'Prototype': + this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); + break; + case 'IncGroup': + this.processIncGroup(child); + break; + case 'ExcGroup': + throw new Error('SIML: Found ExcGroup in unexpected location'); + default: + this.processProperty(childType, child); + } + } + } + + }, + + processElement: function(spec) { + this.htmlContent.push( + new Generator.Element( + spec, + this.config, + this, + this.indentation + this.defaultIndentation + ).html + ); + }, + + processIncGroup: function(spec) { + this.processChildren(spec); + }, + + processProperty: function(type, args) { + // type = Attribute | Directive | Pseudo + var property = new Generator.properties[type]( + args, + this.config, + this, + this.indentation + this.defaultIndentation + ); + if (property.html) { + switch (property.type) { + case 'ATTR': + if (property.html) { + this.htmlAttributes.push(property.html); + } + break; + case 'CONTENT': + if (property.html) { + this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); + } + break; + } + } + }, + + augmentPrototypeSelector: function(selector) { + // Assume tag, if specified, to be first selector portion. + if (selector[0][0] !== 'Tag') { + return selector; + } + // Retrieve and unshift prototype selector portions: + unshift.apply(selector, this.prototypes[selector[0][1]] || []); + return selector; + } + }; + + function RootElement() { + Element.apply(this, arguments); + } + + RootElement.prototype = objCreate(Element.prototype); + RootElement.prototype.make = function(){ + // RootElement is just an empty space + }; + RootElement.prototype.collectOutput = function() { + this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; + }; + RootElement.prototype.processChildren = function() { + this.defaultIndentation = ''; + return Element.prototype.processChildren.apply(this, arguments); + }; + + function Generator(defaultGeneratorConfig) { + this.config = defaults(this.defaultConfig, defaultGeneratorConfig); + } + + Generator.escapeHTML = escapeHTML; + Generator.trim = trim; + Generator.isArray = isArray; + + Generator.Element = Element; + Generator.RootElement = RootElement; + + Generator.properties = { + Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), + Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), + Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) + }; + + Generator.prototype = { + + defaultConfig: { + pretty: true, + curly: false, + indent: DEFAULT_INDENTATION, + directives: {}, + attributes: {}, + pseudos: {}, + toTag: function(t) { + return t; + } + }, + + parse: function(spec, singleRunConfig) { + + singleRunConfig = defaults(this.config, singleRunConfig || {}); + + if (!singleRunConfig.pretty) { + singleRunConfig.indent = ''; + } + + if (!/^[\s\n\r]+$/.test(spec)) { + if (singleRunConfig.curly) { + // TODO: Find a nicer way of passing config to the PEGjs parser: + spec += '\n/*siml:curly=true*/'; + } + try { + spec = siml.PARSER.parse(spec); + } catch(e) { + if (e.line !== undefined && e.column !== undefined) { + throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); + } else { + throw new SyntaxError('SIML: ' + e.message); + } + } + } else { + spec = []; + } + + if (spec[0] === 'Element') { + return new Generator.Element( + spec[1], + singleRunConfig + ).html; + } + + return new Generator.RootElement( + ['RootElement', [['IncGroup', [spec]]]], + singleRunConfig + ).html; + } + + }; + + siml.Generator = Generator; + + siml.defaultGenerator = new Generator({ + pretty: true, + indent: DEFAULT_INDENTATION + }); + + siml.parse = function(s, c) { + return siml.defaultGenerator.parse(s, c); + }; + +}()); siml.PARSER = (function(){ /* @@ -862,22 +862,22 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body) { - if (!head) { - return ['IncGroup', []]; - } - - var all = []; - - if (head[0] !== 'Element' || body.length) { - head = ['IncGroup', [head]]; - } - - for (var i = 0, l = body.length; i < l; ++i) { - head[1].push(body[i][1]); - } - - return head; + result0 = (function(offset, line, column, head, body) { + if (!head) { + return ['IncGroup', []]; + } + + var all = []; + + if (head[0] !== 'Element' || body.length) { + head = ['IncGroup', [head]]; + } + + for (var i = 0, l = body.length; i < l; ++i) { + head[1].push(body[i][1]); + } + + return head; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -940,11 +940,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, a, b) { - if (b[3]) { - return ['IncGroup', [a, b[3]], 'CommaGroup']; - } - return a; + result0 = (function(offset, line, column, a, b) { + if (b[3]) { + return ['IncGroup', [a, b[3]], 'CommaGroup']; + } + return a; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1021,47 +1021,47 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, singleA, tail, decl) { - - var seperator = tail[0] && tail[0].join(''); - var singleB = tail[1]; - - if (decl) { - var declarationChildren = decl[1][0]; - if (singleB) { - if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); - } else { - if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); - } - } - - if (!tail.length) { - return singleA; - } - - switch (singleA[0]) { - case 'Element': { - - if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { - return ['IncGroup', [singleA,singleB]]; - } - - // a>b - if (singleA[0] === 'Element') { - singleA[1][1].push(singleB); - } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { - singleA[1].push(singleB); - } - - return singleA; - } - case 'Prototype': - case 'Directive': - case 'Attribute': { - return ['IncGroup', [singleA, singleB]]; - } - } - return 'ERROR'; + result0 = (function(offset, line, column, singleA, tail, decl) { + + var seperator = tail[0] && tail[0].join(''); + var singleB = tail[1]; + + if (decl) { + var declarationChildren = decl[1][0]; + if (singleB) { + if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); + } else { + if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); + } + } + + if (!tail.length) { + return singleA; + } + + switch (singleA[0]) { + case 'Element': { + + if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { + return ['IncGroup', [singleA,singleB]]; + } + + // a>b + if (singleA[0] === 'Element') { + singleA[1][1].push(singleB); + } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { + singleA[1].push(singleB); + } + + return singleA; + } + case 'Prototype': + case 'Directive': + case 'Attribute': { + return ['IncGroup', [singleA, singleB]]; + } + } + return 'ERROR'; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[3]); } if (result0 === null) { @@ -1219,35 +1219,35 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, body, selector, tail) { - - var all = []; - var separator = ''; - - body.unshift([,,,head]); - - if (tail) { - if (tail[0] === 'Declaration') { - tail = tail[1][0]; - } else { - separator = tail[1]; - tail = tail[0]; - } - } - - for (var i = 0, l = body.length; i < l; ++i) { - if (body[i][3][2] === 'CommaGroup') { - // Make (a,b,c/g) be considered as ((a/b/c/)/g) - body[i][3][0] = 'ExcGroup'; - body[i][3][2] = []; - } - all.push(body[i][3]); - } - return ['ExcGroup', all, [ - tail, - selector, - separator.indexOf('+') > -1 ? 'sibling' : 'descendent' - ]]; + result0 = (function(offset, line, column, head, body, selector, tail) { + + var all = []; + var separator = ''; + + body.unshift([,,,head]); + + if (tail) { + if (tail[0] === 'Declaration') { + tail = tail[1][0]; + } else { + separator = tail[1]; + tail = tail[0]; + } + } + + for (var i = 0, l = body.length; i < l; ++i) { + if (body[i][3][2] === 'CommaGroup') { + // Make (a,b,c/g) be considered as ((a/b/c/)/g) + body[i][3][0] = 'ExcGroup'; + body[i][3][2] = []; + } + all.push(body[i][3]); + } + return ['ExcGroup', all, [ + tail, + selector, + separator.indexOf('+') > -1 ? 'sibling' : 'descendent' + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3], result0[6], result0[8]); } if (result0 === null) { @@ -1300,8 +1300,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, separator, tail) { - return [tail, separator]; + result0 = (function(offset, line, column, separator, tail) { + return [tail, separator]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1354,8 +1354,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return ['Declaration', [c]]; + result0 = (function(offset, line, column, c) { + return ['Declaration', [c]]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -1393,8 +1393,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_SingleSelector(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Element', [s,[]]]; + result0 = (function(offset, line, column, s) { + return ['Element', [s,[]]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1533,8 +1533,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, s) { - return ['Prototype', [name, s]]; + result0 = (function(offset, line, column, name, s) { + return ['Prototype', [name, s]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -1625,9 +1625,9 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - s[1].unshift(s[0]); - return s[1]; + result0 = (function(offset, line, column, s) { + s[1].unshift(s[0]); + return s[1]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1646,8 +1646,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return s; + result0 = (function(offset, line, column, s) { + return s; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -1763,11 +1763,11 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, f, t) { - return [ - f === '#' ? 'Id' : 'Class', - t.join('') - ]; + result0 = (function(offset, line, column, f, t) { + return [ + f === '#' ? 'Id' : 'Class', + t.join('') + ]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -1871,8 +1871,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attr', [name.join(''), value.length ? value[1] : null]]; + result0 = (function(offset, line, column, name, value) { + return ['Attr', [name.join(''), value.length ? value[1] : null]]; })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2]); } if (result0 === null) { @@ -1956,13 +1956,13 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, t, arg) { - return ['Pseudo', [ - t.join(''), - [ - arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ] - ]]; + result0 = (function(offset, line, column, t, arg) { + return ['Pseudo', [ + t.join(''), + [ + arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[2], result0[3]); } if (result0 === null) { @@ -2028,8 +2028,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2045,8 +2045,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_html(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return ['Directive', ['_fillHTML', [s], []]]; + result0 = (function(offset, line, column, s) { + return ['Directive', ['_fillHTML', [s], []]]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2121,8 +2121,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2171,8 +2171,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [escapeHTML(value)]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [escapeHTML(value)]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2221,8 +2221,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2279,8 +2279,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, value) { // explicit space - return ['Attribute', [name, [value]]]; + result0 = (function(offset, line, column, name, value) { // explicit space + return ['Attribute', [name, [value]]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[4]); } if (result0 === null) { @@ -2372,12 +2372,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, name, args, children) { - return ['Directive', [ - name, - args || [], - children || [] - ]]; + result0 = (function(offset, line, column, name, args, children) { + return ['Directive', [ + name, + args || [], + children || [] + ]]; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1], result0[2]); } if (result0 === null) { @@ -2504,8 +2504,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, args) { - return args; + result0 = (function(offset, line, column, args) { + return args; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2515,10 +2515,10 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_braced(); if (result0 !== null) { - result0 = (function(offset, line, column, arg) { - return [ - arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ]; + result0 = (function(offset, line, column, arg) { + return [ + arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ]; })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2543,8 +2543,8 @@ siml.PARSER = (function(){ } } if (result0 !== null) { - result0 = (function(offset, line, column) { - return []; + result0 = (function(offset, line, column) { + return []; })(pos0.offset, pos0.line, pos0.column); } if (result0 === null) { @@ -2596,8 +2596,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, c) { - return [c]; + result0 = (function(offset, line, column, c) { + return [c]; })(pos0.offset, pos0.line, pos0.column, result0[2]); } if (result0 === null) { @@ -2641,8 +2641,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, tail) { - return [tail]; + result0 = (function(offset, line, column, tail) { + return [tail]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2706,8 +2706,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, parts) { - return '(' + parts.join('') + ')'; + result0 = (function(offset, line, column, parts) { + return '(' + parts.join('') + ')'; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -2834,12 +2834,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, head, tail) { - var result = [head]; - for (var i = 0; i < tail.length; i++) { - result.push(tail[i][2]); - } - return result; + result0 = (function(offset, line, column, head, tail) { + var result = [head]; + for (var i = 0; i < tail.length; i++) { + result.push(tail[i][2]); + } + return result; })(pos0.offset, pos0.line, pos0.column, result0[0], result0[1]); } if (result0 === null) { @@ -2855,8 +2855,8 @@ siml.PARSER = (function(){ pos0 = clone(pos); result0 = parse_string(); if (result0 !== null) { - result0 = (function(offset, line, column, s) { - return escapeHTML(s); + result0 = (function(offset, line, column, s) { + return escapeHTML(s); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -2990,12 +2990,12 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - // Replace any `...` quotes within the String: - return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { - var str = stringTokens[ $1 ]; - return str[0] + str[1] + str[0]; - }); + result0 = (function(offset, line, column, d) { + // Replace any `...` quotes within the String: + return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { + var str = stringTokens[ $1 ]; + return str[0] + str[1] + str[0]; + }); })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3062,8 +3062,8 @@ siml.PARSER = (function(){ pos = clone(pos1); } if (result0 !== null) { - result0 = (function(offset, line, column, d) { - return stringTokens[ d.join('') ][1]; + result0 = (function(offset, line, column, d) { + return stringTokens[ d.join('') ][1]; })(pos0.offset, pos0.line, pos0.column, result0[1]); } if (result0 === null) { @@ -3109,8 +3109,8 @@ siml.PARSER = (function(){ result0 = null; } if (result0 !== null) { - result0 = (function(offset, line, column, simpleString) { - return simpleString.join(''); + result0 = (function(offset, line, column, simpleString) { + return simpleString.join(''); })(pos0.offset, pos0.line, pos0.column, result0); } if (result0 === null) { @@ -3575,145 +3575,145 @@ siml.PARSER = (function(){ } - - - var toString = {}.toString; - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; - } - return out; - } - - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - - // Replace all strings with recoverable string tokens: - // This is done to make comment-removal possible and safe. - var stringTokens = [ - // [ 'QUOTE', 'ACTUAL_STRING' ] ... - ]; - function resolveStringToken(tok) { - return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] - } - - // Replace HTML with string tokens first - input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__HTML_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\`/g, '\`')] - ) - 1); - }); - - input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__STRING_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] - ) - 1); - }); - - input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { - return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); - }); - - var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); - - // Remove comments: - input = input.replace(/\/\*[\s\S]*?\*\//g, ''); - input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); - - (function() { - - // Avoid magical whitespace if we're definitely using curlies: - if (isCurly) { - return; - } - - // Here we impose hierarchical curlies on the basis of indentation - // This is used to make, e.g. - // a\n\tb - // into - // a{b} - - input = input.replace(/^(?:\s*\n)+/g, ''); - - var cur; - var lvl = 0; - var lines = []; - var blockedFromClosing = {}; - var step = null; - - var braceDepth = 0; - var curlyDepth = 0; - - input = input.split(/[\r\n]+/); - - for (var i = 0, l = input.length; i < l; ++i) { - - var line = input[i]; - - var indent = line.match(/^\s*/)[0]; - var indentLevel = (indent.match(/\s/g)||[]).length; - - var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; - - if (step == null && nextIndentLevel !== indentLevel) { - step = nextIndentLevel - indentLevel; - } - - braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; - curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; - - if (/^\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (indentLevel < cur) { // dedent - var diff = cur - indentLevel; - while (1) { - diff -= step; - if (lvl === 0 || diff < 0) { - break; - } - if (blockedFromClosing[i-1]) { - continue; - } - lvl--; - lines[i-1] += '}'; - } - } - - if (curlyDepth || braceDepth) { - // Lines within a curly/brace nesting are blocked from future '}' closes - blockedFromClosing[i] = 1; - lines.push(line); - continue; - } - - line = line.substring(indent.length); - - // Don't seek to add curlies to places where curlies already exist: - if (/[{}]\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (nextIndentLevel > indentLevel) { // indent - lvl++; - lines.push(indent + line + '{'); - } else { - lines.push(indent+line); - } - - cur = indentLevel; - - } - - input = lines.join('\n'); //{{ // make curlies BALANCE for peg! - input += Array(lvl+1).join('}'); - }()); - + + + var toString = {}.toString; + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; + } + return out; + } + + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + + // Replace all strings with recoverable string tokens: + // This is done to make comment-removal possible and safe. + var stringTokens = [ + // [ 'QUOTE', 'ACTUAL_STRING' ] ... + ]; + function resolveStringToken(tok) { + return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] + } + + // Replace HTML with string tokens first + input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__HTML_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\`/g, '\`')] + ) - 1); + }); + + input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__STRING_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] + ) - 1); + }); + + input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { + return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); + }); + + var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); + + // Remove comments: + input = input.replace(/\/\*[\s\S]*?\*\//g, ''); + input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); + + (function() { + + // Avoid magical whitespace if we're definitely using curlies: + if (isCurly) { + return; + } + + // Here we impose hierarchical curlies on the basis of indentation + // This is used to make, e.g. + // a\n\tb + // into + // a{b} + + input = input.replace(/^(?:\s*\n)+/g, ''); + + var cur; + var lvl = 0; + var lines = []; + var blockedFromClosing = {}; + var step = null; + + var braceDepth = 0; + var curlyDepth = 0; + + input = input.split(/[\r\n]+/); + + for (var i = 0, l = input.length; i < l; ++i) { + + var line = input[i]; + + var indent = line.match(/^\s*/)[0]; + var indentLevel = (indent.match(/\s/g)||[]).length; + + var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; + + if (step == null && nextIndentLevel !== indentLevel) { + step = nextIndentLevel - indentLevel; + } + + braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; + curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; + + if (/^\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (indentLevel < cur) { // dedent + var diff = cur - indentLevel; + while (1) { + diff -= step; + if (lvl === 0 || diff < 0) { + break; + } + if (blockedFromClosing[i-1]) { + continue; + } + lvl--; + lines[i-1] += '}'; + } + } + + if (curlyDepth || braceDepth) { + // Lines within a curly/brace nesting are blocked from future '}' closes + blockedFromClosing[i] = 1; + lines.push(line); + continue; + } + + line = line.substring(indent.length); + + // Don't seek to add curlies to places where curlies already exist: + if (/[{}]\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (nextIndentLevel > indentLevel) { // indent + lvl++; + lines.push(indent + line + '{'); + } else { + lines.push(indent+line); + } + + cur = indentLevel; + + } + + input = lines.join('\n'); //{{ // make curlies BALANCE for peg! + input += Array(lvl+1).join('}'); + }()); + var result = parseFunctions[startRule](); diff --git a/dist/siml.min.js b/dist/siml.min.js index 758e33f..c6b3625 100644 --- a/dist/siml.min.js +++ b/dist/siml.min.js @@ -1,3 +1,3 @@ -/** SIML v0.3.6 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ +/** SIML v0.3.7 (c) 2013 James padolsey, MIT-licensed, http://github.com/padolsey/SIML **/ (function(){var l="undefined"!=typeof module&&module.exports?module.exports:window.siml={};(function(){"use strict";function n(l){return"[object Array]"==={}.toString.call(l)}function t(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}function u(l){return(l+"").replace(/^\s\s*|\s\s*$/g,"")}function e(l){for(var t=[],u=0,r=l.length;r>u;++u)t[u]=n(l[u])?e(l[u]):l[u];return t}function r(l,n){for(var t in l)n.hasOwnProperty(t)||(n[t]=l[t]);return n}function o(l,n){return function(t,u,e,r){this.parentElement=e,this.indentation=r,t=[].slice.call(t);var o=t[0],s=t[1],f=t[2];f&&s.unshift(f),s.unshift(o);var i=u[l][o]||n[o];if(i||(i=u[l]._default||n._default),!i)throw Error("SIML: No fallback for"+t.join());this.type=i.type,this.html=i.make.apply(this,s)||""}}function s(l,n,t,u){this.spec=l,this.config=n||{},this.parentElement=t||this,this.indentation=u||"",this.defaultIndentation=n.indent,this.tag=null,this.id=null,this.attrs=[],this.classes=[],this.pseudos=[],this.prototypes=v(t&&t.prototypes||null),this.isSingular=!1,this.multiplier=1,this.isPretty=n.pretty,this.htmlOutput=[],this.htmlContent=[],this.htmlAttributes=[],this.selector=l[0],this.make(),this.processChildren(l[1]),this.collectOutput(),this.html=this.htmlOutput.join("")}function f(){s.apply(this,arguments)}function i(l){this.config=r(this.defaultConfig,l)}var c=[].push,a=[].unshift,h="div",p=" ",A={input:1,img:1,meta:1,link:1,br:1,hr:1,source:1,area:1,base:1,col:1},m={_fillHTML:{type:"CONTENT",make:function(l,n,t){return t}},_default:{type:"CONTENT",make:function(l){throw Error("SIML: Directive not resolvable: "+l)}}},d={_default:{type:"ATTR",make:function(l,n){return null==n?l:l+'="'+n+'"'}},text:{type:"CONTENT",make:function(l,n){return n}}},g={_default:{type:"ATTR",make:function(l){return"input"===this.parentElement.tag?'type="'+l+'"':(console.warn("Unknown pseudo class used:",l),void 0)}}},v=Object.create||function(l){function n(){}return n.prototype=l,new n};s.prototype={make:function(){var l,n,t={},u=this.selector.slice();this.augmentPrototypeSelector(u);for(var e=0,r=u.length;r>e;++e)switch(l=u[e][0],n=u[e][1],l){case"Tag":this.tag||(this.tag=n);break;case"Id":this.id=n;break;case"Attr":var o=n[0],s=[o,[n[1]]];null!=t[o]?this.attrs[t[o]]=s:t[o]=this.attrs.push(s)-1;break;case"Class":this.classes.push(n);break;case"Pseudo":this.pseudos.push(n)}this.tag=this.config.toTag.call(this,this.tag||h),this.isSingular=this.tag in A,this.id&&this.htmlAttributes.push('id="'+this.id+'"'),this.classes.length&&this.htmlAttributes.push('class="'+this.classes.join(" ").replace(/(^| )\./g,"$1")+'"');for(var e=0,r=this.attrs.length;r>e;++e)this.processProperty("Attribute",this.attrs[e]);for(var e=0,r=this.pseudos.length;r>e;++e){var f=this.pseudos[e];isNaN(f[0])?this.processProperty("Pseudo",f):this.multiplier=f[0]}},collectOutput:function(){var l=this.indentation,n=this.isPretty,t=this.htmlOutput,u=this.htmlAttributes,e=this.htmlContent;if(t.push(l+"<"+this.tag),t.push(u.length?" "+u.join(" "):""),this.isSingular?t.push("/>"):(t.push(">"),e.length&&(n&&t.push("\n"),t.push(e.join(n?"\n":"")),n&&t.push("\n"+l)),t.push("")),this.multiplier>1)for(var r=t.join(""),o=this.multiplier-1;o--;)t.push(n?"\n":""),t.push(r)},_makeExclusiveBranches:function(l,n,t){function u(l,n,t){var o=l[0],s=r(l),f=n[0],i=n[1],a=n[2],t=t||{child:!1,selector:!1};if(t.child&&t.selector)return t;if(s)for(var h=s.length;h-->0;){var p=s[h];if("ExcGroup"===p[0]&&p[2][0]&&(p=p[2][0]),"sibling"===a){var A=r(p);if(!A||!A.length){if(s[h]=["IncGroup",[p,e(f)]],t.child=!0,"IncGroup"===o)break;continue}}if(t=u(p,n,{child:!1,selector:!1}),"IncGroup"===o&&t.child)break}return t.selector||"Element"===l[0]&&(i&&c.apply(l[1][0],i),t.selector=!0),t.child||s&&(f&&s.push(e(f)),t.child=!0),t}function r(l){return"Element"===l[0]?l[1][1]:"ExcGroup"===l[0]||"IncGroup"===l[0]?l[1]:null}var o=l[2],s=l[1],f=[];u(l,o);for(var i=0,a=s.length;a>i;++i){n[t]=s[i];var h=e(this.spec);n[t]=l,f.push(h)}return f},processChildren:function(l){var n,t,u=l.length,e=[];for(n=0;u>n;++n)"ExcGroup"===l[n][0]&&c.apply(e,this._makeExclusiveBranches(l[n],l,n));if(e.length){this.collectOutput=function(){};for(var r=[],o=0,i=e.length;i>o;++o){var a=e[o];r.push(new("RootElement"===a[0]?f:s)(a,this.config,this.parentElement,this.indentation).html)}this.htmlOutput.push(r.join(this.isPretty?"\n":""))}else for(n=0;u>n;++n){var h=l[n][1],t=l[n][0];switch(t){case"Element":this.processElement(h);break;case"Prototype":this.prototypes[h[0]]=this.augmentPrototypeSelector(h[1]);break;case"IncGroup":this.processIncGroup(h);break;case"ExcGroup":throw Error("SIML: Found ExcGroup in unexpected location");default:this.processProperty(t,h)}}},processElement:function(l){this.htmlContent.push(new i.Element(l,this.config,this,this.indentation+this.defaultIndentation).html)},processIncGroup:function(l){this.processChildren(l)},processProperty:function(l,n){var t=new i.properties[l](n,this.config,this,this.indentation+this.defaultIndentation);if(t.html)switch(t.type){case"ATTR":t.html&&this.htmlAttributes.push(t.html);break;case"CONTENT":t.html&&this.htmlContent.push(this.indentation+this.defaultIndentation+t.html)}},augmentPrototypeSelector:function(l){return"Tag"!==l[0][0]?l:(a.apply(l,this.prototypes[l[0][1]]||[]),l)}},f.prototype=v(s.prototype),f.prototype.make=function(){},f.prototype.collectOutput=function(){this.htmlOutput=[this.htmlContent.join(this.isPretty?"\n":"")]},f.prototype.processChildren=function(){return this.defaultIndentation="",s.prototype.processChildren.apply(this,arguments)},i.escapeHTML=t,i.trim=u,i.isArray=n,i.Element=s,i.RootElement=f,i.properties={Attribute:o("attributes",d),Directive:o("directives",m),Pseudo:o("pseudos",g)},i.prototype={defaultConfig:{pretty:!0,curly:!1,indent:p,directives:{},attributes:{},pseudos:{},toTag:function(l){return l}},parse:function(n,t){if(t=r(this.config,t||{}),t.pretty||(t.indent=""),/^[\s\n\r]+$/.test(n))n=[];else{t.curly&&(n+="\n/*siml:curly=true*/");try{n=l.PARSER.parse(n)}catch(u){throw void 0!==u.line&&void 0!==u.column?new SyntaxError("SIML: Line "+u.line+", column "+u.column+": "+u.message):new SyntaxError("SIML: "+u.message)}}return"Element"===n[0]?new i.Element(n[1],t).html:new i.RootElement(["RootElement",[["IncGroup",[n]]]],t).html}},l.Generator=i,l.defaultGenerator=new i({pretty:!0,indent:p}),l.parse=function(n,t){return l.defaultGenerator.parse(n,t)}})(),l.PARSER=function(){function l(l){return'"'+l.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var n={parse:function(n,t){function u(l){var n={};for(var t in l)n[t]=l[t];return n}function e(l,t){for(var u=l.offset+t,e=l.offset;u>e;e++){var r=n.charAt(e);"\n"===r?(l.seenCR||l.line++,l.column=1,l.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(l.line++,l.column=1,l.seenCR=!0):(l.column++,l.seenCR=!1)}l.offset+=t}function r(l){W.offsetY.offset&&(Y=u(W),ln=[]),ln.push(l))}function o(){var l,t,o,f,i,c,a,h;if(c=u(W),a=u(W),l=U(),null!==l)if(t=s(),t=null!==t?t:"",null!==t){for(o=[],h=u(W),f=[],/^[\r\n\t ]/.test(n.charAt(W.offset))?(i=n.charAt(W.offset),e(W,1)):(i=null,0===X&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(W.offset))?(i=n.charAt(W.offset),e(W,1)):(i=null,0===X&&r("[\\r\\n\\t ]"));for(null!==f?(i=s(),null!==i?f=[f,i]:(f=null,W=u(h))):(f=null,W=u(h));null!==f;){for(o.push(f),h=u(W),f=[],/^[\r\n\t ]/.test(n.charAt(W.offset))?(i=n.charAt(W.offset),e(W,1)):(i=null,0===X&&r("[\\r\\n\\t ]"));null!==i;)f.push(i),/^[\r\n\t ]/.test(n.charAt(W.offset))?(i=n.charAt(W.offset),e(W,1)):(i=null,0===X&&r("[\\r\\n\\t ]"));null!==f?(i=s(),null!==i?f=[f,i]:(f=null,W=u(h))):(f=null,W=u(h))}null!==o?(f=U(),null!==f?l=[l,t,o,f]:(l=null,W=u(a))):(l=null,W=u(a))}else l=null,W=u(a);else l=null,W=u(a);return null!==l&&(l=function(l,n,t,u,e){if(!u)return["IncGroup",[]];("Element"!==u[0]||e.length)&&(u=["IncGroup",[u]]);for(var r=0,o=e.length;o>r;++r)u[1].push(e[r][1]);return u}(c.offset,c.line,c.column,l[1],l[2])),null===l&&(W=u(c)),l}function s(){var l,t,o,i,c,a,h,p;return a=u(W),h=u(W),l=f(),null!==l?(p=u(W),t=U(),null!==t?(44===n.charCodeAt(W.offset)?(o=",",e(W,1)):(o=null,0===X&&r('","')),null!==o?(i=U(),null!==i?(c=s(),null!==c?t=[t,o,i,c]:(t=null,W=u(p))):(t=null,W=u(p))):(t=null,W=u(p))):(t=null,W=u(p)),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,W=u(h))):(l=null,W=u(h)),null!==l&&(l=function(l,n,t,u,e){return e[3]?["IncGroup",[u,e[3]],"CommaGroup"]:u}(a.offset,a.line,a.column,l[0],l[1])),null===l&&(W=u(a)),l}function f(){var l,t,s,h,p,A,m,g,v,_,E,y;if(_=u(W),E=u(W),l=a(),null!==l){for(y=u(W),t=[],/^[> \t+]/.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[> \\t+]"));null!==s;)t.push(s),/^[> \t+]/.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[> \\t+]"));null!==t?(s=f(),null!==s?t=[t,s]:(t=null,W=u(y))):(t=null,W=u(y)),t=null!==t?t:"",null!==t?(s=U(),null!==s?(h=c(),h=null!==h?h:"",null!==h?l=[l,t,s,h]:(l=null,W=u(E))):(l=null,W=u(E))):(l=null,W=u(E))}else l=null,W=u(E);if(null!==l&&(l=function(l,n,t,u,e,r){var o=e[0]&&e[0].join(""),s=e[1];if(r){var f=r[1][0];s?"Element"===s[0]&&s[1][1].push(f):"Element"===u[0]&&u[1][1].push(f)}if(!e.length)return u;switch(u[0]){case"Element":return o.indexOf(",")>-1||o.indexOf("+")>-1?["IncGroup",[u,s]]:("Element"===u[0]?u[1][1].push(s):("IncGroup"===u[0]||"ExcGroup"===u[0])&&u[1].push(s),u);case"Prototype":case"Directive":case"Attribute":return["IncGroup",[u,s]]}return"ERROR"}(_.offset,_.line,_.column,l[0],l[1],l[3])),null===l&&(W=u(_)),null===l){if(_=u(W),E=u(W),40===n.charCodeAt(W.offset)?(l="(",e(W,1)):(l=null,0===X&&r('"("')),null!==l)if(t=U(),null!==t)if(s=o(),null!==s){for(h=[],y=u(W),p=U(),null!==p?(47===n.charCodeAt(W.offset)?(A="/",e(W,1)):(A=null,0===X&&r('"/"')),null!==A?(m=U(),null!==m?(g=o(),null!==g?p=[p,A,m,g]:(p=null,W=u(y))):(p=null,W=u(y))):(p=null,W=u(y))):(p=null,W=u(y));null!==p;)h.push(p),y=u(W),p=U(),null!==p?(47===n.charCodeAt(W.offset)?(A="/",e(W,1)):(A=null,0===X&&r('"/"')),null!==A?(m=U(),null!==m?(g=o(),null!==g?p=[p,A,m,g]:(p=null,W=u(y))):(p=null,W=u(y))):(p=null,W=u(y))):(p=null,W=u(y));if(null!==h)if(p=U(),null!==p)if(41===n.charCodeAt(W.offset)?(A=")",e(W,1)):(A=null,0===X&&r('")"')),null!==A){for(m=[],g=d();null!==g;)m.push(g),g=d();null!==m?(g=U(),null!==g?(v=i(),v=null!==v?v:"",null!==v?l=[l,t,s,h,p,A,m,g,v]:(l=null,W=u(E))):(l=null,W=u(E))):(l=null,W=u(E))}else l=null,W=u(E);else l=null,W=u(E);else l=null,W=u(E)}else l=null,W=u(E);else l=null,W=u(E);else l=null,W=u(E);null!==l&&(l=function(l,n,t,u,e,r,o){var s=[],f="";e.unshift([,,,u]),o&&("Declaration"===o[0]?o=o[1][0]:(f=o[1],o=o[0]));for(var i=0,c=e.length;c>i;++i)"CommaGroup"===e[i][3][2]&&(e[i][3][0]="ExcGroup",e[i][3][2]=[]),s.push(e[i][3]);return["ExcGroup",s,[o,r,f.indexOf("+")>-1?"sibling":"descendent"]]}(_.offset,_.line,_.column,l[2],l[3],l[6],l[8])),null===l&&(W=u(_))}return l}function i(){var l,t,o,s;if(l=c(),null===l){for(o=u(W),s=u(W),l=[],/^[> \t+]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[> \\t+]"));null!==t;)l.push(t),/^[> \t+]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[> \\t+]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u,e){return[e,u]}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(W=u(o))}return l}function c(){var l,t,s,f,i;return f=u(W),i=u(W),123===n.charCodeAt(W.offset)?(l="{",e(W,1)):(l=null,0===X&&r('"{"')),null!==l?(t=o(),t=null!==t?t:"",null!==t?(125===n.charCodeAt(W.offset)?(s="}",e(W,1)):(s=null,0===X&&r('"}"')),null!==s?l=[l,t,s]:(l=null,W=u(i))):(l=null,W=u(i))):(l=null,W=u(i)),null!==l&&(l=function(l,n,t,u){return["Declaration",[u]]}(f.offset,f.line,f.column,l[1])),null===l&&(W=u(f)),l}function a(){var l;return l=T(),null===l&&(l=p(),null===l&&(l=h(),null===l&&(l=C(),null===l&&(l=b(),null===l&&(l=x()))))),l}function h(){var l,n;return n=u(W),l=m(),null!==l&&(l=function(l,n,t,u){return["Element",[u,[]]]}(n.offset,n.line,n.column,l)),null===l&&(W=u(n)),l}function p(){var l,t,o,s,f,i,c,a,h;if(a=u(W),h=u(W),l=A(),null!==l){for(t=[],/^[ \t]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[ \\t]"));null!==o;)t.push(o),/^[ \t]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[ \\t]"));if(null!==t)if(61===n.charCodeAt(W.offset)?(o="=",e(W,1)):(o=null,0===X&&r('"="')),null!==o){for(s=[],/^[ \t]/.test(n.charAt(W.offset))?(f=n.charAt(W.offset),e(W,1)):(f=null,0===X&&r("[ \\t]"));null!==f;)s.push(f),/^[ \t]/.test(n.charAt(W.offset))?(f=n.charAt(W.offset),e(W,1)):(f=null,0===X&&r("[ \\t]"));if(null!==s)if(f=m(),null!==f){for(i=[],/^[ \t]/.test(n.charAt(W.offset))?(c=n.charAt(W.offset),e(W,1)):(c=null,0===X&&r("[ \\t]"));null!==c;)i.push(c),/^[ \t]/.test(n.charAt(W.offset))?(c=n.charAt(W.offset),e(W,1)):(c=null,0===X&&r("[ \\t]"));null!==i?(59===n.charCodeAt(W.offset)?(c=";",e(W,1)):(c=null,0===X&&r('";"')),c=null!==c?c:"",null!==c?l=[l,t,o,s,f,i,c]:(l=null,W=u(h))):(l=null,W=u(h))}else l=null,W=u(h);else l=null,W=u(h)}else l=null,W=u(h);else l=null,W=u(h)}else l=null,W=u(h);return null!==l&&(l=function(l,n,t,u,e){return["Prototype",[u,e]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(W=u(a)),l}function A(){var l,t,o,s,f;if(s=u(W),f=u(W),/^[a-zA-Z_$]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[a-zA-Z_$]")),null!==l){for(t=[],/^[a-zA-Z0-9$_\-]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[a-zA-Z0-9$_\\-]"));null!==o;)t.push(o),/^[a-zA-Z0-9$_\-]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[a-zA-Z0-9$_\\-]"));null!==t?l=[l,t]:(l=null,W=u(f))}else l=null,W=u(f);return null!==l&&(l=function(l,n,t,u,e){return u+e.join("")}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(W=u(s)),l}function m(){var l,n,t,e,r;if(e=u(W),r=u(W),l=g(),null!==l){for(n=[],t=d();null!==t;)n.push(t),t=d();null!==n?l=[l,n]:(l=null,W=u(r))}else l=null,W=u(r);if(null!==l&&(l=function(l,n,t,u){return u[1].unshift(u[0]),u[1]}(e.offset,e.line,e.column,l)),null===l&&(W=u(e)),null===l){if(e=u(W),n=d(),null!==n)for(l=[];null!==n;)l.push(n),n=d();else l=null;null!==l&&(l=function(l,n,t,u){return u}(e.offset,e.line,e.column,l)),null===l&&(W=u(e))}return l}function d(){var l;return l=v(),null===l&&(l=E(),null===l&&(l=_())),l}function g(){var l,t,o;if(o=u(W),/^[a-z0-9_\-]/i.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[a-z0-9_\\-]i")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-z0-9_\-]/i.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[a-z0-9_\\-]i"));else l=null;return null!==l&&(l=function(l,n,t,u){return["Tag",u.join("")]}(o.offset,o.line,o.column,l)),null===l&&(W=u(o)),l}function v(){var l,t,o,s,f;if(s=u(W),f=u(W),/^[#.]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[#.]")),null!==l){if(/^[a-z0-9\-_$]/i.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[a-z0-9\\-_$]i")),null!==o)for(t=[];null!==o;)t.push(o),/^[a-z0-9\-_$]/i.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[a-z0-9\\-_$]i"));else t=null;null!==t?l=[l,t]:(l=null,W=u(f))}else l=null,W=u(f);return null!==l&&(l=function(l,n,t,u,e){return["#"===u?"Id":"Class",e.join("")]}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(W=u(s)),l}function _(){var l,t,o,s,f,i,c;if(f=u(W),i=u(W),91===n.charCodeAt(W.offset)?(l="[",e(W,1)):(l=null,0===X&&r('"["')),null!==l){if(/^[^[\]=]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[^[\\]=]")),null!==o)for(t=[];null!==o;)t.push(o),/^[^[\]=]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[^[\\]=]"));else t=null;null!==t?(c=u(W),61===n.charCodeAt(W.offset)?(o="=",e(W,1)):(o=null,0===X&&r('"="')),null!==o?(s=y(),null!==s?o=[o,s]:(o=null,W=u(c))):(o=null,W=u(c)),o=null!==o?o:"",null!==o?(93===n.charCodeAt(W.offset)?(s="]",e(W,1)):(s=null,0===X&&r('"]"')),null!==s?l=[l,t,o,s]:(l=null,W=u(i))):(l=null,W=u(i))):(l=null,W=u(i))}else l=null,W=u(i);return null!==l&&(l=function(l,n,t,u,e){return["Attr",[u.join(""),e.length?e[1]:null]]}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(W=u(f)),l}function E(){var l,t,o,s,f,i,c;if(f=u(W),i=u(W),58===n.charCodeAt(W.offset)?(l=":",e(W,1)):(l=null,0===X&&r('":"')),null!==l)if(c=u(W),X++,t=w(),X--,null===t?t="":(t=null,W=u(c)),null!==t){if(/^[a-z0-9\-_$]/i.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[a-z0-9\\-_$]i")),null!==s)for(o=[];null!==s;)o.push(s),/^[a-z0-9\-_$]/i.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[a-z0-9\\-_$]i"));else o=null;null!==o?(s=$(),s=null!==s?s:"",null!==s?l=[l,t,o,s]:(l=null,W=u(i))):(l=null,W=u(i))}else l=null,W=u(i);else l=null,W=u(i);return null!==l&&(l=function(l,n,t,u,e){return["Pseudo",[u.join(""),[e&&e.substr(1,e.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]]]}(f.offset,f.line,f.column,l[2],l[3])),null===l&&(W=u(f)),l}function y(){var l,t,o;if(o=u(W),l=w(),null!==l&&(l=function(l,n,t,u){return u}(o.offset,o.line,o.column,l)),null===l&&(W=u(o)),null===l){if(o=u(W),/^[^[\]]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[^[\\]]")),null!==t)for(l=[];null!==t;)l.push(t),/^[^[\]]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[^[\\]]"));else l=null;null!==l&&(l=function(l,n,t,u){return u.join("")}(o.offset,o.line,o.column,l)),null===l&&(W=u(o))}return l}function C(){var l,n;return n=u(W),l=w(),null!==l&&(l=function(l,n,t,u){return["Directive",["_fillHTML",[J(u)],[]]]}(n.offset,n.line,n.column,l)),null===l&&(W=u(n)),l}function b(){var l,n;return n=u(W),l=R(),null!==l&&(l=function(l,n,t,u){return["Directive",["_fillHTML",[u],[]]]}(n.offset,n.line,n.column,l)),null===l&&(W=u(n)),l}function T(){var l,t,o,s,f,i,c,a,h;return a=u(W),h=u(W),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(W.offset)?(o=":",e(W,1)):(o=null,0===X&&r('":"')),null!==o?(s=U(),null!==s?(f=k(),null!==f?(i=U(),null!==i?(59===n.charCodeAt(W.offset)?(c=";",e(W,1)):(c=null,0===X&&r('";"')),null!==c?l=[l,t,o,s,f,i,c]:(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h)),null!==l&&(l=function(l,n,t,u,e){return["Attribute",[u,[e]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(W=u(a)),null===l&&(a=u(W),h=u(W),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(W.offset)?(o=":",e(W,1)):(o=null,0===X&&r('":"')),null!==o?(s=U(),null!==s?(f=w(),null!==f?l=[l,t,o,s,f]:(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h)),null!==l&&(l=function(l,n,t,u,e){return["Attribute",[u,[J(e)]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(W=u(a)),null===l&&(a=u(W),h=u(W),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(W.offset)?(o=":",e(W,1)):(o=null,0===X&&r('":"')),null!==o?(s=U(),null!==s?(f=R(),null!==f?l=[l,t,o,s,f]:(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h)),null!==l&&(l=function(l,n,t,u,e){return["Attribute",[u,[e]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(W=u(a)),null===l&&(a=u(W),h=u(W),l=S(),null!==l?(t=U(),null!==t?(58===n.charCodeAt(W.offset)?(o=":",e(W,1)):(o=null,0===X&&r('":"')),null!==o?(/^[ \t]/.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[ \\t]")),null!==s?(f=k(),null!==f?l=[l,t,o,s,f]:(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h))):(l=null,W=u(h)),null!==l&&(l=function(l,n,t,u,e){return["Attribute",[u,[e]]]}(a.offset,a.line,a.column,l[0],l[4])),null===l&&(W=u(a))))),l}function S(){var l,t,o;if(X++,o=u(W),/^[A-Za-z0-9\-_]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[A-Za-z0-9\\-_]")),null!==t)for(l=[];null!==t;)l.push(t),/^[A-Za-z0-9\-_]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[A-Za-z0-9\\-_]"));else l=null;return null!==l&&(l=function(l,n,t,u){return u.join("")}(o.offset,o.line,o.column,l)),null===l&&(W=u(o)),null===l&&(l=w(),null===l&&(l=R())),X--,0===X&&null===l&&r("AttributeName"),l}function x(){var l,n,t,e,o;return X++,e=u(W),o=u(W),l=G(),null!==l?(n=I(),n=null!==n?n:"",null!==n?(t=z(),t=null!==t?t:"",null!==t?l=[l,n,t]:(l=null,W=u(o))):(l=null,W=u(o))):(l=null,W=u(o)),null!==l&&(l=function(l,n,t,u,e,r){return["Directive",[u,e||[],r||[]]]}(e.offset,e.line,e.column,l[0],l[1],l[2])),null===l&&(W=u(e)),X--,0===X&&null===l&&r("Directive"),l}function G(){var l,t,o,s,f,i;if(f=u(W),i=u(W),64===n.charCodeAt(W.offset)?(l="@",e(W,1)):(l=null,0===X&&r('"@"')),null!==l)if(/^[a-zA-Z_$]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[a-zA-Z_$]")),null!==t){for(o=[],/^[a-zA-Z0-9$_]/.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[a-zA-Z0-9$_]"));null!==s;)o.push(s),/^[a-zA-Z0-9$_]/.test(n.charAt(W.offset))?(s=n.charAt(W.offset),e(W,1)):(s=null,0===X&&r("[a-zA-Z0-9$_]"));null!==o?l=[l,t,o]:(l=null,W=u(i))}else l=null,W=u(i);else l=null,W=u(i);return null!==l&&(l=function(l,n,t,u,e){return u+e.join("")}(f.offset,f.line,f.column,l[1],l[2])),null===l&&(W=u(f)),l}function I(){var l,t,o,s,f;return s=u(W),f=u(W),40===n.charCodeAt(W.offset)?(l="(",e(W,1)):(l=null,0===X&&r('"("')),null!==l?(t=j(),t=null!==t?t:"",null!==t?(41===n.charCodeAt(W.offset)?(o=")",e(W,1)):(o=null,0===X&&r('")"')),null!==o?l=[l,t,o]:(l=null,W=u(f))):(l=null,W=u(f))):(l=null,W=u(f)),null!==l&&(l=function(l,n,t,u){return u}(s.offset,s.line,s.column,l[1])),null===l&&(W=u(s)),null===l&&(s=u(W),l=$(),null!==l&&(l=function(l,n,t,u){return[u.substr(1,u.length-2).replace(/[\s\r\n]+/g," ").replace(/^\s\s*|\s\s*$/g,"")]}(s.offset,s.line,s.column,l)),null===l&&(W=u(s))),l}function z(){var l,t,s,i,c,a;if(c=u(W),59===n.charCodeAt(W.offset)?(l=";",e(W,1)):(l=null,0===X&&r('";"')),null!==l&&(l=function(){return[]}(c.offset,c.line,c.column)),null===l&&(W=u(c)),null===l&&(c=u(W),a=u(W),l=U(),null!==l?(123===n.charCodeAt(W.offset)?(t="{",e(W,1)):(t=null,0===X&&r('"{"')),null!==t?(s=o(),s=null!==s?s:"",null!==s?(125===n.charCodeAt(W.offset)?(i="}",e(W,1)):(i=null,0===X&&r('"}"')),null!==i?l=[l,t,s,i]:(l=null,W=u(a))):(l=null,W=u(a))):(l=null,W=u(a))):(l=null,W=u(a)),null!==l&&(l=function(l,n,t,u){return[u]}(c.offset,c.line,c.column,l[2])),null===l&&(W=u(c)),null===l)){for(c=u(W),a=u(W),l=[],/^[> \t]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[> \\t]"));null!==t;)l.push(t),/^[> \t]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[> \\t]"));null!==l?(t=f(),null!==t?l=[l,t]:(l=null,W=u(a))):(l=null,W=u(a)),null!==l&&(l=function(l,n,t,u){return[u]}(c.offset,c.line,c.column,l[1])),null===l&&(W=u(c))}return l}function $(){var l,t,o,s,f;if(s=u(W),f=u(W),40===n.charCodeAt(W.offset)?(l="(",e(W,1)):(l=null,0===X&&r('"("')),null!==l){for(t=[],o=$(),null===o&&(o=O());null!==o;)t.push(o),o=$(),null===o&&(o=O());null!==t?(41===n.charCodeAt(W.offset)?(o=")",e(W,1)):(o=null,0===X&&r('")"')),null!==o?l=[l,t,o]:(l=null,W=u(f))):(l=null,W=u(f))}else l=null,W=u(f);return null!==l&&(l=function(l,n,t,u){return"("+u.join("")+")"}(s.offset,s.line,s.column,l[1])),null===l&&(W=u(s)),l}function N(){var l,n,t;if(t=u(W),n=O(),null!==n)for(l=[];null!==n;)l.push(n),n=O();else l=null;return null!==l&&(l=function(l,n,t,u){return u.join("")}(t.offset,t.line,t.column,l)),null===l&&(W=u(t)),l}function O(){var l;return/^[^()]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[^()]")),l}function j(){var l,t,o,s,f,i,c,a;if(i=u(W),c=u(W),l=k(),null!==l){for(t=[],a=u(W),44===n.charCodeAt(W.offset)?(o=",",e(W,1)):(o=null,0===X&&r('","')),null!==o?(s=U(),null!==s?(f=k(),null!==f?o=[o,s,f]:(o=null,W=u(a))):(o=null,W=u(a))):(o=null,W=u(a));null!==o;)t.push(o),a=u(W),44===n.charCodeAt(W.offset)?(o=",",e(W,1)):(o=null,0===X&&r('","')),null!==o?(s=U(),null!==s?(f=k(),null!==f?o=[o,s,f]:(o=null,W=u(a))):(o=null,W=u(a))):(o=null,W=u(a));null!==t?l=[l,t]:(l=null,W=u(c))}else l=null,W=u(c);return null!==l&&(l=function(l,n,t,u,e){for(var r=[u],o=0;e.length>o;o++)r.push(e[o][2]);return r}(i.offset,i.line,i.column,l[0],l[1])),null===l&&(W=u(i)),l}function k(){var l,t,o,s;return o=u(W),l=w(),null!==l&&(l=function(l,n,t,u){return J(u)}(o.offset,o.line,o.column,l)),null===l&&(W=u(o)),null===l&&(l=P(),null===l&&(l=R(),null===l&&(l=Z(),null===l&&(o=u(W),s=u(W),"true"===n.substr(W.offset,4)?(l="true",e(W,4)):(l=null,0===X&&r('"true"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(){return!0}(o.offset,o.line,o.column)),null===l&&(W=u(o)),null===l&&(o=u(W),s=u(W),"false"===n.substr(W.offset,5)?(l="false",e(W,5)):(l=null,0===X&&r('"false"')),null!==l?(t=U(),null!==t?l=[l,t]:(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(){return!1}(o.offset,o.line,o.column)),null===l&&(W=u(o))))))),l}function w(){var l,t,o,s,f;if(X++,s=u(W),f=u(W),"%%__STRING_TOKEN___%%"===n.substr(W.offset,21)?(l="%%__STRING_TOKEN___%%",e(W,21)):(l=null,0===X&&r('"%%__STRING_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,W=u(f))}else l=null,W=u(f);return null!==l&&(l=function(l,n,t,u){return nn[u.join("")][1].replace(/%%__HTML_TOKEN___%%(\d+)/g,function(l,n){var t=nn[n];return t[0]+t[1]+t[0]})}(s.offset,s.line,s.column,l[1])),null===l&&(W=u(s)),X--,0===X&&null===l&&r("String"),l}function R(){var l,t,o,s,f;if(X++,s=u(W),f=u(W),"%%__HTML_TOKEN___%%"===n.substr(W.offset,19)?(l="%%__HTML_TOKEN___%%",e(W,19)):(l=null,0===X&&r('"%%__HTML_TOKEN___%%"')),null!==l){if(/^[0-9]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[0-9]")),null!==o)for(t=[];null!==o;)t.push(o),/^[0-9]/.test(n.charAt(W.offset))?(o=n.charAt(W.offset),e(W,1)):(o=null,0===X&&r("[0-9]"));else t=null;null!==t?l=[l,t]:(l=null,W=u(f))}else l=null,W=u(f);return null!==l&&(l=function(l,n,t,u){return nn[u.join("")][1]}(s.offset,s.line,s.column,l[1])),null===l&&(W=u(s)),X--,0===X&&null===l&&r("HTML"),l}function P(){var l,t,o;if(X++,o=u(W),/^[a-zA-Z0-9$@#]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[a-zA-Z0-9$@#]")),null!==t)for(l=[];null!==t;)l.push(t),/^[a-zA-Z0-9$@#]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[a-zA-Z0-9$@#]"));else l=null;return null!==l&&(l=function(l,n,t,u){return u.join("")}(o.offset,o.line,o.column,l)),null===l&&(W=u(o)),X--,0===X&&null===l&&r("SimpleString"),l}function Z(){var l,n,t,e,o,s;return X++,o=u(W),s=u(W),l=M(),null!==l?(n=L(),null!==n?(t=D(),null!==t?(e=U(),null!==e?l=[l,n,t,e]:(l=null,W=u(s))):(l=null,W=u(s))):(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u,e,r){return parseFloat(u+e+r)}(o.offset,o.line,o.column,l[0],l[1],l[2])),null===l&&(W=u(o)),null===l&&(o=u(W),s=u(W),l=M(),null!==l?(n=L(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,W=u(s))):(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u,e){return parseFloat(u+e)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(W=u(o)),null===l&&(o=u(W),s=u(W),l=M(),null!==l?(n=D(),null!==n?(t=U(),null!==t?l=[l,n,t]:(l=null,W=u(s))):(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u,e){return parseFloat(u+e)}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(W=u(o)),null===l&&(o=u(W),s=u(W),l=M(),null!==l?(n=U(),null!==n?l=[l,n]:(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u){return parseFloat(u)}(o.offset,o.line,o.column,l[0])),null===l&&(W=u(o))))),X--,0===X&&null===l&&r("number"),l}function M(){var l,t,o,s,f;return s=u(W),f=u(W),l=B(),null!==l?(t=F(),null!==t?l=[l,t]:(l=null,W=u(f))):(l=null,W=u(f)),null!==l&&(l=function(l,n,t,u,e){return u+e}(s.offset,s.line,s.column,l[0],l[1])),null===l&&(W=u(s)),null===l&&(l=K(),null===l&&(s=u(W),f=u(W),45===n.charCodeAt(W.offset)?(l="-",e(W,1)):(l=null,0===X&&r('"-"')),null!==l?(t=B(),null!==t?(o=F(),null!==o?l=[l,t,o]:(l=null,W=u(f))):(l=null,W=u(f))):(l=null,W=u(f)),null!==l&&(l=function(l,n,t,u,e){return"-"+u+e}(s.offset,s.line,s.column,l[1],l[2])),null===l&&(W=u(s)),null===l&&(s=u(W),f=u(W),45===n.charCodeAt(W.offset)?(l="-",e(W,1)):(l=null,0===X&&r('"-"')),null!==l?(t=K(),null!==t?l=[l,t]:(l=null,W=u(f))):(l=null,W=u(f)),null!==l&&(l=function(l,n,t,u){return"-"+u}(s.offset,s.line,s.column,l[1])),null===l&&(W=u(s))))),l}function L(){var l,t,o,s;return o=u(W),s=u(W),46===n.charCodeAt(W.offset)?(l=".",e(W,1)):(l=null,0===X&&r('"."')),null!==l?(t=F(),null!==t?l=[l,t]:(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u){return"."+u}(o.offset,o.line,o.column,l[1])),null===l&&(W=u(o)),l}function D(){var l,n,t,e;return t=u(W),e=u(W),l=H(),null!==l?(n=F(),null!==n?l=[l,n]:(l=null,W=u(e))):(l=null,W=u(e)),null!==l&&(l=function(l,n,t,u,e){return u+e}(t.offset,t.line,t.column,l[0],l[1])),null===l&&(W=u(t)),l}function F(){var l,n,t;if(t=u(W),n=K(),null!==n)for(l=[];null!==n;)l.push(n),n=K();else l=null;return null!==l&&(l=function(l,n,t,u){return u.join("")}(t.offset,t.line,t.column,l)),null===l&&(W=u(t)),l}function H(){var l,t,o,s;return o=u(W),s=u(W),/^[eE]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[eE]")),null!==l?(/^[+\-]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[+\\-]")),t=null!==t?t:"",null!==t?l=[l,t]:(l=null,W=u(s))):(l=null,W=u(s)),null!==l&&(l=function(l,n,t,u,e){return u+e}(o.offset,o.line,o.column,l[0],l[1])),null===l&&(W=u(o)),l}function K(){var l;return/^[0-9]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[0-9]")),l}function B(){var l;return/^[1-9]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[1-9]")),l}function q(){var l;return/^[0-9a-fA-F]/.test(n.charAt(W.offset))?(l=n.charAt(W.offset),e(W,1)):(l=null,0===X&&r("[0-9a-fA-F]")),l}function U(){var l,t;for(X++,l=[],/^[ \t\n\r]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[ \\t\\n\\r]"));null!==t;)l.push(t),/^[ \t\n\r]/.test(n.charAt(W.offset))?(t=n.charAt(W.offset),e(W,1)):(t=null,0===X&&r("[ \\t\\n\\r]"));return X--,0===X&&null===l&&r("whitespace"),l}function V(l){l.sort();for(var n=null,t=[],u=0;l.length>u;u++)l[u]!==n&&(t.push(l[u]),n=l[u]);return t}function J(l){return(l+"").replace(/&/g,"&").replace(//g,">").replace(/\"/g,""")}var Q={MSeries:o,CSeries:s,LSeries:f,ExcGroupRHS:i,ChildrenDeclaration:c,Single:a,Element:h,PrototypeDefinition:p,PrototypeName:A,SingleSelector:m,selectorRepeatableComponent:d,selectorTag:g,selectorIdClass:v,selectorAttr:_,selectorPseudo:E,selectorAttrValue:y,Text:C,HTML:b,Attribute:T,attributeName:S,Directive:x,DirectiveName:G,DirectiveArguments:I,DirectiveChildren:z,braced:$,nonBraceCharacters:N,nonBraceCharacter:O,arrayElements:j,value:k,string:w,html:R,simpleString:P,number:Z,"int":M,frac:L,exp:D,digits:F,e:H,digit:K,digit19:B,hexDigit:q,_:U};if(void 0!==t){if(void 0===Q[t])throw Error("Invalid rule name: "+l(t)+".")}else t="MSeries";var W={offset:0,line:1,column:1,seenCR:!1},X=0,Y={offset:0,line:1,column:1,seenCR:!1},ln=[];({}).toString;var nn=[];n=n.replace(/(`+)((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__HTML_TOKEN___%%"+(nn.push([n,t.replace(/\\`/g,"`")])-1)}),n=n.replace(/(["'])((?:\\\1|[^\1])*?)\1/g,function(l,n,t){return"%%__STRING_TOKEN___%%"+(nn.push([n,t.replace(/\\'/g,"'").replace(/\\"/g,'"')])-1)}),n=n.replace(/(^|\n)\s*\\([^\n\r]+)/g,function(l,n,t){return n+"%%__STRING_TOKEN___%%"+(nn.push([n,t])-1)});var tn=/\/\*\s*siml:curly=true\s*\*\//i.test(n);n=n.replace(/\/\*[\s\S]*?\*\//g,""),n=n.replace(/\/\/.+?(?=[\r\n])/g,""),function(){if(!tn){n=n.replace(/^(?:\s*\n)+/g,"");var l,t=0,u=[],e={},r=null,o=0,s=0;n=n.split(/[\r\n]+/); for(var f=0,i=n.length;i>f;++f){var c=n[f],a=c.match(/^\s*/)[0],h=(a.match(/\s/g)||[]).length,p=((n[f+1]||"").match(/^\s*/)[0].match(/\s/g)||[]).length;if(null==r&&p!==h&&(r=p-h),o+=(c.match(/\(/g)||[]).length-(c.match(/\)/g)||[]).length,s+=(c.match(/\{/g)||[]).length-(c.match(/\}/g)||[]).length,/^\s*$/.test(c))u.push(c);else{if(l>h)for(var A=l-h;;){if(A-=r,0===t||0>A)break;e[f-1]||(t--,u[f-1]+="}")}s||o?(e[f]=1,u.push(c)):(c=c.substring(a.length),/[{}]\s*$/.test(c)?u.push(c):(p>h?(t++,u.push(a+c+"{")):u.push(a+c),l=h))}}n=u.join("\n"),n+=Array(t+1).join("}")}}();var un=Q[t]();if(null===un||W.offset!==n.length){var en=Math.max(W.offset,Y.offset),rn=n.length>en?n.charAt(en):null,on=W.offset>Y.offset?W:Y;throw new this.SyntaxError(V(ln),rn,en,on.line,on.column)}return un},toSource:function(){return this._source}};return n.SyntaxError=function(n,t,u,e,r){function o(n,t){var u,e;switch(n.length){case 0:u="end of input";break;case 1:u=n[0];break;default:u=n.slice(0,n.length-1).join(", ")+" or "+n[n.length-1]}return e=t?l(t):"end of input","Expected "+u+" but "+e+" found."}this.name="SyntaxError",this.expected=n,this.found=t,this.message=o(n,t),this.offset=u,this.line=e,this.column=r},n.SyntaxError.prototype=Error.prototype,n}()})(); \ No newline at end of file diff --git a/package.json b/package.json index 14d971d..2a2c031 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "siml", "title": "SIML", "description": "SIML, Simpified markup inspired by CSS", - "version": "0.3.6", + "version": "0.3.7", "author": "James Padolsey (http://git.io/padolsey)", "main": "dist/siml.all.js", "dependencies": { diff --git a/src/generators/angular.js b/src/generators/angular.js index 8fe816d..bb3fe66 100644 --- a/src/generators/angular.js +++ b/src/generators/angular.js @@ -1,37 +1,36 @@ -siml.angular = new siml.Generator({ - pretty: true, - toTag: siml.html5.config.toTag, - directives: { - doctype: siml.html5.config.directives.doctype, - dt: siml.html5.config.directives.dt, - _default: { - type: 'ATTR', - make: function(name, children, value) { - // camelCase -> snake-case - name = name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { - return $1 + '-' + $2.toLowerCase(); - }); - if (name.substring(0, 1) === '$') { - name = name.substring(1); - } else { - name = 'ng-' + name; - } - return name + '="' + value + '"'; - } - } - }, - pseudos: { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input' && siml.html5.INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - // camelCase -> snake-case - return 'ng-' + name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { - return $1 + '-' + $2.toLowerCase(); - }); - } - } - } -}); +siml.angular = new siml.Generator({ + pretty: true, + toTag: siml.html5.config.toTag, + directives: { + doctype: siml.html5.config.directives.doctype, + dt: siml.html5.config.directives.dt, + _default: { + type: 'ATTR', + make: function(name, children, value) { + // camelCase -> snake-case + name = name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { + return $1 + '-' + $2.toLowerCase(); + }); + if (name.substring(0, 1) === '$') { + name = name.substring(1); + } else { + name = 'ng-' + name; + } + return name + '="' + value + '"'; + } + } + }, + pseudos: { + _default: { + type: 'ATTR', + make: function(name) { + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + // camelCase -> snake-case + return 'ng-' + name.replace(/([a-z])([A-Z])/g, function($0,$1,$2) { + return $1 + '-' + $2.toLowerCase(); + }); + } + } + } +}); diff --git a/src/generators/html5.js b/src/generators/html5.js index 7a4b0c8..b55e341 100644 --- a/src/generators/html5.js +++ b/src/generators/html5.js @@ -16,9 +16,15 @@ ]; var INPUT_TYPES = { - button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, 'datetime-local': 1, - email: 1, file: 1, hidden: 1, image: 1, month: 1, number: 1, password: 1, radio: 1, - range: 1, reset: 1, search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + button: { + button: 1, reset: 1, submit: 1 + }, + input: { + button: 1, checkbox: 1, color: 1, date: 1, datetime: 1, + 'datetime-local': 1, email: 1, file: 1, hidden: 1, image: 1, + month: 1, number: 1, password: 1, radio: 1, range: 1, reset: 1, + search: 1, submit: 1, tel: 1, text: 1, time: 1, url: 1, week: 1 + } }; var HTML_SHORT_MAP = {}; @@ -51,14 +57,20 @@ doctype: doctypeDirective, dt: doctypeDirective }, + getPsuedoType: function(tag, name) { + var types = INPUT_TYPES[tag]; + + if (types && types[name]) { + return 'type="' + name + '"'; + } + }, pseudos: { _default: { type: 'ATTR', make: function(name) { - if (this.parentElement.tag === 'input' && INPUT_TYPES.hasOwnProperty(name)) { - return 'type="' + name + '"'; - } - throw new Error('Unknown Pseduo: ' + name); + var type = siml.html5.config.getPsuedoType(this.parentElement.tag.toLowerCase(), name); + if (type) return type; + throw new Error('Unknown Pseudo: ' + name); } } } diff --git a/src/intro.js b/src/intro.js index db031f2..04886a7 100644 --- a/src/intro.js +++ b/src/intro.js @@ -1 +1 @@ -(function() { +(function() { diff --git a/src/parser.pegjs b/src/parser.pegjs index 60492cd..158ddc5 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -1,521 +1,521 @@ -/* SIML parser [uses peg.js] */ - -/** - * Pre-processing of the string occurs BEFORE parsing: - * (Removing comments & doing tabs->curlies) - */ -{ - - var toString = {}.toString; - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; - } - return out; - } - - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - - // Replace all strings with recoverable string tokens: - // This is done to make comment-removal possible and safe. - var stringTokens = [ - // [ 'QUOTE', 'ACTUAL_STRING' ] ... - ]; - function resolveStringToken(tok) { - return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] - } - - // Replace HTML with string tokens first - input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__HTML_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\`/g, '\`')] - ) - 1); - }); - - input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { - return '%%__STRING_TOKEN___%%' + (stringTokens.push( - [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] - ) - 1); - }); - - input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { - return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); - }); - - var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); - - // Remove comments: - input = input.replace(/\/\*[\s\S]*?\*\//g, ''); - input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); - - (function() { - - // Avoid magical whitespace if we're definitely using curlies: - if (isCurly) { - return; - } - - // Here we impose hierarchical curlies on the basis of indentation - // This is used to make, e.g. - // a\n\tb - // into - // a{b} - - input = input.replace(/^(?:\s*\n)+/g, ''); - - var cur; - var lvl = 0; - var lines = []; - var blockedFromClosing = {}; - var step = null; - - var braceDepth = 0; - var curlyDepth = 0; - - input = input.split(/[\r\n]+/); - - for (var i = 0, l = input.length; i < l; ++i) { - - var line = input[i]; - - var indent = line.match(/^\s*/)[0]; - var indentLevel = (indent.match(/\s/g)||[]).length; - - var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; - - if (step == null && nextIndentLevel !== indentLevel) { - step = nextIndentLevel - indentLevel; - } - - braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; - curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; - - if (/^\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (indentLevel < cur) { // dedent - var diff = cur - indentLevel; - while (1) { - diff -= step; - if (lvl === 0 || diff < 0) { - break; - } - if (blockedFromClosing[i-1]) { - continue; - } - lvl--; - lines[i-1] += '}'; - } - } - - if (curlyDepth || braceDepth) { - // Lines within a curly/brace nesting are blocked from future '}' closes - blockedFromClosing[i] = 1; - lines.push(line); - continue; - } - - line = line.substring(indent.length); - - // Don't seek to add curlies to places where curlies already exist: - if (/[{}]\s*$/.test(line)) { - lines.push(line); - continue; - } - - if (nextIndentLevel > indentLevel) { // indent - lvl++; - lines.push(indent + line + '{'); - } else { - lines.push(indent+line); - } - - cur = indentLevel; - - } - - input = lines.join('\n'); //{{ // make curlies BALANCE for peg! - input += Array(lvl+1).join('}'); - }()); - -} - -/** - * THE ACTUAL PARSER - */ - -start - = MSeries - -/** - * MSeries -- A multiline series of LSeries - */ -MSeries - = _ head:CSeries? body:([\r\n\t ]* CSeries)* _ { - if (!head) { - return ['IncGroup', []]; - } - - var all = []; - - if (head[0] !== 'Element' || body.length) { - head = ['IncGroup', [head]]; - } - - for (var i = 0, l = body.length; i < l; ++i) { - head[1].push(body[i][1]); - } - - return head; - } - -/** - * CSeries -- A comma series of LSeries - */ -CSeries - = a:LSeries b:(_ ',' _ CSeries)? { - if (b[3]) { - return ['IncGroup', [a, b[3]], 'CommaGroup']; - } - return a; - } - -/** - * LSeries -- A single line series of Singles - */ -LSeries - = singleA:Single tail:([> \t+]* LSeries)? _ decl:ChildrenDeclaration? { - - var seperator = tail[0] && tail[0].join(''); - var singleB = tail[1]; - - if (decl) { - var declarationChildren = decl[1][0]; - if (singleB) { - if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); - } else { - if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); - } - } - - if (!tail.length) { - return singleA; - } - - switch (singleA[0]) { - case 'Element': { - - if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { - return ['IncGroup', [singleA,singleB]]; - } - - // a>b - if (singleA[0] === 'Element') { - singleA[1][1].push(singleB); - } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { - singleA[1].push(singleB); - } - - return singleA; - } - case 'Prototype': - case 'Directive': - case 'Attribute': { - return ['IncGroup', [singleA, singleB]]; - } - } - return 'ERROR'; - } - / '(' _ head:MSeries body:(_ '/' _ MSeries)* _ ')' selector:selectorRepeatableComponent* _ tail:ExcGroupRHS? { - - var all = []; - var separator = ''; - - body.unshift([,,,head]); - - if (tail) { - if (tail[0] === 'Declaration') { - tail = tail[1][0]; - } else { - separator = tail[1]; - tail = tail[0]; - } - } - - for (var i = 0, l = body.length; i < l; ++i) { - if (body[i][3][2] === 'CommaGroup') { - // Make (a,b,c/g) be considered as ((a/b/c/)/g) - body[i][3][0] = 'ExcGroup'; - body[i][3][2] = []; - } - all.push(body[i][3]); - } - return ['ExcGroup', all, [ - tail, - selector, - separator.indexOf('+') > -1 ? 'sibling' : 'descendent' - ]]; - } - -ExcGroupRHS - = ChildrenDeclaration - / separator:[> \t+]* tail:LSeries { - return [tail, separator]; - } - -ChildrenDeclaration - = '{' c:MSeries? '}' { - return ['Declaration', [c]]; - } - -/** - * Single -- A single simple component, such as an Element or Attribute - */ -Single - = Attribute - / PrototypeDefinition - / Element - / Text - / HTML - / Directive - -/** - * Element - */ -Element - = s:Selector { - return ['Element', [s,[]]]; - } - -/** - * PrototypeDefinition - */ -PrototypeDefinition - = name:PrototypeName [ \t]* '=' [ \t]* s:SingleSelector [ \t]* ';'? { - return ['Prototype', [name, s]]; - } - -PrototypeName - = a:[a-zA-Z_$] b:[a-zA-Z0-9$_-]* { return a+b.join(''); } - -/** - * Selector - */ -Selector "Selector" - = SingleSelector - -SingleSelector - = s:(selectorTag selectorRepeatableComponent*) { - s[1].unshift(s[0]); - return s[1]; - } - / s:selectorRepeatableComponent+ { - return s; - } - -selectorRepeatableComponent - = selectorIdClass - / selectorPseudo - / selectorAttr - -selectorTag - = t:[a-z0-9_-]i+ { return ['Tag', t.join('')]; } - -selectorIdClass - = f:[#.] t:[a-z0-9-_$]i+ { - return [ - f === '#' ? 'Id' : 'Class', - t.join('') - ]; - } - -selectorAttr - = '[' name:[^\[\]=]+ value:('=' selectorAttrValue)? ']' { - return ['Attr', [name.join(''), value.length ? value[1] : null]]; - } - -selectorPseudo - = ':' !string t:[a-z0-9-_$]i+ arg:braced? { - return ['Pseudo', [ - t.join(''), - [ - arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ] - ]]; - } - -selectorAttrValue - = v:string { return v; } - / v:[^\[\]]+ { return v.join(''); } - -/** - * Text - */ -Text - = s:string { - return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; - } - -/** - * HTML - */ -HTML - = s:html { - return ['Directive', ['_fillHTML', [s], []]]; - } - -/** - * Attribute - */ -Attribute - = name:attributeName _ ":" _ value:value _ ";" { - return ['Attribute', [name, [value]]]; - } - / name:attributeName _ ":" _ value:string { - return ['Attribute', [name, [escapeHTML(value)]]]; - } - / name:attributeName _ ":" _ value:html { - return ['Attribute', [name, [value]]]; - } - / name:attributeName _ ":" [ \t] value:value { // explicit space - return ['Attribute', [name, [value]]]; - } - -attributeName "AttributeName" - = name:[A-Za-z0-9-_]+ { return name.join(''); } - / string - / html - -/** - * Directive - */ -Directive "Directive" - = name:DirectiveName args:DirectiveArguments? children:DirectiveChildren? { - return ['Directive', [ - name, - args || [], - children || [] - ]]; - } - -DirectiveName - = '@' a:[a-zA-Z_$] b:[a-zA-Z0-9$_]* { return a+b.join(''); } - -DirectiveArguments - = "(" args:arrayElements? ")" { - return args; - } - / arg:braced { - return [ - arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') - ]; - } - -DirectiveChildren - = ';' { - return []; - } - / _ '{' c:MSeries? '}' { - return [c]; - } - / [> \t]* tail:LSeries { - return [tail]; - } - -braced - = "(" parts:(braced / nonBraceCharacter)* ")" { - return '(' + parts.join('') + ')'; - } - -nonBraceCharacters - = chars:nonBraceCharacter+ { return chars.join(''); } - -nonBraceCharacter - = [^()] - - -/*** JSON-LIKE TYPES ***/ -/*** (c) Copyright (c) 2010-2012 David Majda ***/ -/*** FROM: https://github.com/dmajda/pegjs/blob/master/examples/json.pegjs ***/ -arrayElements - = head:value tail:("," _ value)* { - var result = [head]; - for (var i = 0; i < tail.length; i++) { - result.push(tail[i][2]); - } - return result; - } - -value - = s:string { - return escapeHTML(s); - } - / simpleString - / html - / number - / "true" _ { return true; } - / "false" _ { return false; } - -/* ===== Lexical Elements ===== */ - -string "String" - = '%%__STRING_TOKEN___%%' d:[0-9]+ { - // Replace any `...` quotes within the String: - return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { - var str = stringTokens[ $1 ]; - return str[0] + str[1] + str[0]; - }); - } - -html "HTML" - = '%%__HTML_TOKEN___%%' d:[0-9]+ { - return stringTokens[ d.join('') ][1]; - } - -simpleString "SimpleString" - = simpleString:[a-zA-Z0-9$@#]+ { - return simpleString.join(''); - } - -number "number" - = int_:int frac:frac exp:exp _ { return parseFloat(int_ + frac + exp); } - / int_:int frac:frac _ { return parseFloat(int_ + frac); } - / int_:int exp:exp _ { return parseFloat(int_ + exp); } - / int_:int _ { return parseFloat(int_); } - -int - = digit19:digit19 digits:digits { return digit19 + digits; } - / digit:digit - / "-" digit19:digit19 digits:digits { return "-" + digit19 + digits; } - / "-" digit:digit { return "-" + digit; } - -frac - = "." digits:digits { return "." + digits; } - -exp - = e:e digits:digits { return e + digits; } - -digits - = digits:digit+ { return digits.join(""); } - -e - = e:[eE] sign:[+-]? { return e + sign; } - -digit - = [0-9] - -digit19 - = [1-9] - -hexDigit - = [0-9a-fA-F] - -/* ===== Whitespace ===== */ - -_ "whitespace" - = [ \t\n\r]* +/* SIML parser [uses peg.js] */ + +/** + * Pre-processing of the string occurs BEFORE parsing: + * (Removing comments & doing tabs->curlies) + */ +{ + + var toString = {}.toString; + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + out[i] = toString.call(arr[i]) === '[object Array]' ? deepCopyArray(arr[i]) : arr[i]; + } + return out; + } + + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + + // Replace all strings with recoverable string tokens: + // This is done to make comment-removal possible and safe. + var stringTokens = [ + // [ 'QUOTE', 'ACTUAL_STRING' ] ... + ]; + function resolveStringToken(tok) { + return stringTokens[tok.substring('%%__STRING_TOKEN___%%'.length)] + } + + // Replace HTML with string tokens first + input = input.replace(/(`+)((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__HTML_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\`/g, '\`')] + ) - 1); + }); + + input = input.replace(/(["'])((?:\\\1|[^\1])*?)\1/g, function($0, $1, $2) { + return '%%__STRING_TOKEN___%%' + (stringTokens.push( + [$1, $2.replace(/\\'/g, '\'').replace(/\\"/g, '"')] + ) - 1); + }); + + input = input.replace(/(^|\n)\s*\\([^\n\r]+)/g, function($0, $1, $2) { + return $1 + '%%__STRING_TOKEN___%%' + (stringTokens.push([$1, $2]) - 1); + }); + + var isCurly = /\/\*\s*siml:curly=true\s*\*\//i.test(input); + + // Remove comments: + input = input.replace(/\/\*[\s\S]*?\*\//g, ''); + input = input.replace(/\/\/.+?(?=[\r\n])/g, ''); + + (function() { + + // Avoid magical whitespace if we're definitely using curlies: + if (isCurly) { + return; + } + + // Here we impose hierarchical curlies on the basis of indentation + // This is used to make, e.g. + // a\n\tb + // into + // a{b} + + input = input.replace(/^(?:\s*\n)+/g, ''); + + var cur; + var lvl = 0; + var lines = []; + var blockedFromClosing = {}; + var step = null; + + var braceDepth = 0; + var curlyDepth = 0; + + input = input.split(/[\r\n]+/); + + for (var i = 0, l = input.length; i < l; ++i) { + + var line = input[i]; + + var indent = line.match(/^\s*/)[0]; + var indentLevel = (indent.match(/\s/g)||[]).length; + + var nextIndentLevel = ((input[i+1] || '').match(/^\s*/)[0].match(/\s/g)||[]).length; + + if (step == null && nextIndentLevel !== indentLevel) { + step = nextIndentLevel - indentLevel; + } + + braceDepth += (line.match(/\(/g)||[]).length - (line.match(/\)/g)||[]).length; + curlyDepth += (line.match(/\{/g)||[]).length - (line.match(/\}/g)||[]).length; + + if (/^\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (indentLevel < cur) { // dedent + var diff = cur - indentLevel; + while (1) { + diff -= step; + if (lvl === 0 || diff < 0) { + break; + } + if (blockedFromClosing[i-1]) { + continue; + } + lvl--; + lines[i-1] += '}'; + } + } + + if (curlyDepth || braceDepth) { + // Lines within a curly/brace nesting are blocked from future '}' closes + blockedFromClosing[i] = 1; + lines.push(line); + continue; + } + + line = line.substring(indent.length); + + // Don't seek to add curlies to places where curlies already exist: + if (/[{}]\s*$/.test(line)) { + lines.push(line); + continue; + } + + if (nextIndentLevel > indentLevel) { // indent + lvl++; + lines.push(indent + line + '{'); + } else { + lines.push(indent+line); + } + + cur = indentLevel; + + } + + input = lines.join('\n'); //{{ // make curlies BALANCE for peg! + input += Array(lvl+1).join('}'); + }()); + +} + +/** + * THE ACTUAL PARSER + */ + +start + = MSeries + +/** + * MSeries -- A multiline series of LSeries + */ +MSeries + = _ head:CSeries? body:([\r\n\t ]* CSeries)* _ { + if (!head) { + return ['IncGroup', []]; + } + + var all = []; + + if (head[0] !== 'Element' || body.length) { + head = ['IncGroup', [head]]; + } + + for (var i = 0, l = body.length; i < l; ++i) { + head[1].push(body[i][1]); + } + + return head; + } + +/** + * CSeries -- A comma series of LSeries + */ +CSeries + = a:LSeries b:(_ ',' _ CSeries)? { + if (b[3]) { + return ['IncGroup', [a, b[3]], 'CommaGroup']; + } + return a; + } + +/** + * LSeries -- A single line series of Singles + */ +LSeries + = singleA:Single tail:([> \t+]* LSeries)? _ decl:ChildrenDeclaration? { + + var seperator = tail[0] && tail[0].join(''); + var singleB = tail[1]; + + if (decl) { + var declarationChildren = decl[1][0]; + if (singleB) { + if (singleB[0] === 'Element') singleB[1][1].push(declarationChildren); + } else { + if (singleA[0] === 'Element') singleA[1][1].push(declarationChildren); + } + } + + if (!tail.length) { + return singleA; + } + + switch (singleA[0]) { + case 'Element': { + + if (seperator.indexOf(',') > -1 || seperator.indexOf('+') > -1) { + return ['IncGroup', [singleA,singleB]]; + } + + // a>b + if (singleA[0] === 'Element') { + singleA[1][1].push(singleB); + } else if (singleA[0] === 'IncGroup' || singleA[0] === 'ExcGroup') { + singleA[1].push(singleB); + } + + return singleA; + } + case 'Prototype': + case 'Directive': + case 'Attribute': { + return ['IncGroup', [singleA, singleB]]; + } + } + return 'ERROR'; + } + / '(' _ head:MSeries body:(_ '/' _ MSeries)* _ ')' selector:selectorRepeatableComponent* _ tail:ExcGroupRHS? { + + var all = []; + var separator = ''; + + body.unshift([,,,head]); + + if (tail) { + if (tail[0] === 'Declaration') { + tail = tail[1][0]; + } else { + separator = tail[1]; + tail = tail[0]; + } + } + + for (var i = 0, l = body.length; i < l; ++i) { + if (body[i][3][2] === 'CommaGroup') { + // Make (a,b,c/g) be considered as ((a/b/c/)/g) + body[i][3][0] = 'ExcGroup'; + body[i][3][2] = []; + } + all.push(body[i][3]); + } + return ['ExcGroup', all, [ + tail, + selector, + separator.indexOf('+') > -1 ? 'sibling' : 'descendent' + ]]; + } + +ExcGroupRHS + = ChildrenDeclaration + / separator:[> \t+]* tail:LSeries { + return [tail, separator]; + } + +ChildrenDeclaration + = '{' c:MSeries? '}' { + return ['Declaration', [c]]; + } + +/** + * Single -- A single simple component, such as an Element or Attribute + */ +Single + = Attribute + / PrototypeDefinition + / Element + / Text + / HTML + / Directive + +/** + * Element + */ +Element + = s:Selector { + return ['Element', [s,[]]]; + } + +/** + * PrototypeDefinition + */ +PrototypeDefinition + = name:PrototypeName [ \t]* '=' [ \t]* s:SingleSelector [ \t]* ';'? { + return ['Prototype', [name, s]]; + } + +PrototypeName + = a:[a-zA-Z_$] b:[a-zA-Z0-9$_-]* { return a+b.join(''); } + +/** + * Selector + */ +Selector "Selector" + = SingleSelector + +SingleSelector + = s:(selectorTag selectorRepeatableComponent*) { + s[1].unshift(s[0]); + return s[1]; + } + / s:selectorRepeatableComponent+ { + return s; + } + +selectorRepeatableComponent + = selectorIdClass + / selectorPseudo + / selectorAttr + +selectorTag + = t:[a-z0-9_-]i+ { return ['Tag', t.join('')]; } + +selectorIdClass + = f:[#.] t:[a-z0-9-_$]i+ { + return [ + f === '#' ? 'Id' : 'Class', + t.join('') + ]; + } + +selectorAttr + = '[' name:[^\[\]=]+ value:('=' selectorAttrValue)? ']' { + return ['Attr', [name.join(''), value.length ? value[1] : null]]; + } + +selectorPseudo + = ':' !string t:[a-z0-9-_$]i+ arg:braced? { + return ['Pseudo', [ + t.join(''), + [ + arg && arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ] + ]]; + } + +selectorAttrValue + = v:string { return v; } + / v:[^\[\]]+ { return v.join(''); } + +/** + * Text + */ +Text + = s:string { + return ['Directive', ['_fillHTML', [escapeHTML(s)], []]]; + } + +/** + * HTML + */ +HTML + = s:html { + return ['Directive', ['_fillHTML', [s], []]]; + } + +/** + * Attribute + */ +Attribute + = name:attributeName _ ":" _ value:value _ ";" { + return ['Attribute', [name, [value]]]; + } + / name:attributeName _ ":" _ value:string { + return ['Attribute', [name, [escapeHTML(value)]]]; + } + / name:attributeName _ ":" _ value:html { + return ['Attribute', [name, [value]]]; + } + / name:attributeName _ ":" [ \t] value:value { // explicit space + return ['Attribute', [name, [value]]]; + } + +attributeName "AttributeName" + = name:[A-Za-z0-9-_]+ { return name.join(''); } + / string + / html + +/** + * Directive + */ +Directive "Directive" + = name:DirectiveName args:DirectiveArguments? children:DirectiveChildren? { + return ['Directive', [ + name, + args || [], + children || [] + ]]; + } + +DirectiveName + = '@' a:[a-zA-Z_$] b:[a-zA-Z0-9$_]* { return a+b.join(''); } + +DirectiveArguments + = "(" args:arrayElements? ")" { + return args; + } + / arg:braced { + return [ + arg.substr(1, arg.length-2).replace(/[\s\r\n]+/g, ' ').replace(/^\s\s*|\s\s*$/g, '') + ]; + } + +DirectiveChildren + = ';' { + return []; + } + / _ '{' c:MSeries? '}' { + return [c]; + } + / [> \t]* tail:LSeries { + return [tail]; + } + +braced + = "(" parts:(braced / nonBraceCharacter)* ")" { + return '(' + parts.join('') + ')'; + } + +nonBraceCharacters + = chars:nonBraceCharacter+ { return chars.join(''); } + +nonBraceCharacter + = [^()] + + +/*** JSON-LIKE TYPES ***/ +/*** (c) Copyright (c) 2010-2012 David Majda ***/ +/*** FROM: https://github.com/dmajda/pegjs/blob/master/examples/json.pegjs ***/ +arrayElements + = head:value tail:("," _ value)* { + var result = [head]; + for (var i = 0; i < tail.length; i++) { + result.push(tail[i][2]); + } + return result; + } + +value + = s:string { + return escapeHTML(s); + } + / simpleString + / html + / number + / "true" _ { return true; } + / "false" _ { return false; } + +/* ===== Lexical Elements ===== */ + +string "String" + = '%%__STRING_TOKEN___%%' d:[0-9]+ { + // Replace any `...` quotes within the String: + return stringTokens[ d.join('') ][1].replace(/%%__HTML_TOKEN___%%(\d+)/g, function(_, $1) { + var str = stringTokens[ $1 ]; + return str[0] + str[1] + str[0]; + }); + } + +html "HTML" + = '%%__HTML_TOKEN___%%' d:[0-9]+ { + return stringTokens[ d.join('') ][1]; + } + +simpleString "SimpleString" + = simpleString:[a-zA-Z0-9$@#]+ { + return simpleString.join(''); + } + +number "number" + = int_:int frac:frac exp:exp _ { return parseFloat(int_ + frac + exp); } + / int_:int frac:frac _ { return parseFloat(int_ + frac); } + / int_:int exp:exp _ { return parseFloat(int_ + exp); } + / int_:int _ { return parseFloat(int_); } + +int + = digit19:digit19 digits:digits { return digit19 + digits; } + / digit:digit + / "-" digit19:digit19 digits:digits { return "-" + digit19 + digits; } + / "-" digit:digit { return "-" + digit; } + +frac + = "." digits:digits { return "." + digits; } + +exp + = e:e digits:digits { return e + digits; } + +digits + = digits:digit+ { return digits.join(""); } + +e + = e:[eE] sign:[+-]? { return e + sign; } + +digit + = [0-9] + +digit19 + = [1-9] + +hexDigit + = [0-9a-fA-F] + +/* ===== Whitespace ===== */ + +_ "whitespace" + = [ \t\n\r]* diff --git a/src/siml.js b/src/siml.js index bb5ed96..6f02bac 100644 --- a/src/siml.js +++ b/src/siml.js @@ -1,583 +1,583 @@ -var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; -(function() { - - 'use strict'; - - var push = [].push; - var unshift = [].unshift; - - var DEFAULT_TAG = 'div'; - var DEFAULT_INDENTATION = ' '; - - var SINGULAR_TAGS = { - input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, - source: 1, area: 1, base: 1, col: 1 - }; - - var DEFAULT_DIRECTIVES = { - _fillHTML: { - type: 'CONTENT', - make: function(_, children, t) { - return t; - } - }, - _default: { - type: 'CONTENT', - make: function(dir) { - throw new Error('SIML: Directive not resolvable: ' + dir); - } - } - }; - - var DEFAULT_ATTRIBUTES = { - _default: { - type: 'ATTR', - make: function(attrName, value) { - if (value == null) { - return attrName; - } - return attrName + '="' + value + '"'; - } - }, - text: { - type: 'CONTENT', - make: function(_, t) { - return t; - } - } - }; - - var DEFAULT_PSEUDOS = { - _default: { - type: 'ATTR', - make: function(name) { - if (this.parentElement.tag === 'input') { - return 'type="' + name + '"'; - } - console.warn('Unknown pseudo class used:', name) - } - } - } - - var objCreate = Object.create || function (o) { - function F() {} - F.prototype = o; - return new F(); - }; - - function isArray(a) { - return {}.toString.call(a) === '[object Array]'; - } - function escapeHTML(h) { - return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); - } - function trim(s) { - return String(s).replace(/^\s\s*|\s\s*$/g, ''); - } - function deepCopyArray(arr) { - var out = []; - for (var i = 0, l = arr.length; i < l; ++i) { - if (isArray(arr[i])) { - out[i] = deepCopyArray(arr[i]); - } else { - out[i] = arr[i]; - } - } - return out; - } - function defaults(defaults, obj) { - for (var i in defaults) { - if (!obj.hasOwnProperty(i)) { - obj[i] = defaults[i]; - } - } - return obj; - } - - function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { - return function ConfigurableProperty(args, config, parentElement, indentation) { - - this.parentElement = parentElement; - this.indentation = indentation; - - args = [].slice.call(args); - - var propName = args[0]; - var propArguments = args[1]; - var propChildren = args[2]; - - if (propChildren) { - propArguments.unshift(propChildren); - } - - propArguments.unshift(propName); - - var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; - if (!propMaker) { - propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; - } - - if (!propMaker) { - throw new Error('SIML: No fallback for' + args.join()); - } - - this.type = propMaker.type; - this.html = propMaker.make.apply(this, propArguments) || ''; - - }; - } - - function Element(spec, config, parentElement, indentation) { - - this.spec = spec; - this.config = config || {}; - this.parentElement = parentElement || this; - this.indentation = indentation || ''; - this.defaultIndentation = config.indent; - - this.tag = null; - this.id = null; - this.attrs = []; - this.classes = []; - this.pseudos = []; - this.prototypes = objCreate(parentElement && parentElement.prototypes || null); - - this.isSingular = false; - this.multiplier = 1; - - this.isPretty = config.pretty; - - this.htmlOutput = []; - this.htmlContent = []; - this.htmlAttributes = []; - - this.selector = spec[0]; - - this.make(); - this.processChildren(spec[1]); - this.collectOutput(); - - this.html = this.htmlOutput.join(''); - - } - - Element.prototype = { - - make: function() { - - var attributeMap = {}; - var selector = this.selector.slice(); - var selectorPortionType; - var selectorPortion; - - this.augmentPrototypeSelector(selector); - - for (var i = 0, l = selector.length; i < l; ++i) { - selectorPortionType = selector[i][0]; - selectorPortion = selector[i][1]; - switch (selectorPortionType) { - case 'Tag': - if (!this.tag) { - this.tag = selectorPortion; - } - break; - case 'Id': - this.id = selectorPortion; break; - case 'Attr': - var attrName = selectorPortion[0]; - var attr = [attrName, [selectorPortion[1]]]; - // Attributes can only be defined once -- latest wins - if (attributeMap[attrName] != null) { - this.attrs[attributeMap[attrName]] = attr; - } else { - attributeMap[attrName] = this.attrs.push(attr) - 1; - } - break; - case 'Class': - this.classes.push(selectorPortion); break; - case 'Pseudo': - this.pseudos.push(selectorPortion); break; - } - } - - this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); - this.isSingular = this.tag in SINGULAR_TAGS; - - if (this.id) { - this.htmlAttributes.push( - 'id="' + this.id + '"' - ); - } - - if (this.classes.length) { - this.htmlAttributes.push( - 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' - ); - } - - for (var i = 0, l = this.attrs.length; i < l; ++ i) { - this.processProperty('Attribute', this.attrs[i]); - } - - for (var i = 0, l = this.pseudos.length; i < l; ++ i) { - var p = this.pseudos[i]; - if (!isNaN(p[0])) { - this.multiplier = p[0]; - continue; - } - this.processProperty('Pseudo', p); - } - - }, - - collectOutput: function() { - - var indent = this.indentation; - var isPretty = this.isPretty; - var output = this.htmlOutput; - var attrs = this.htmlAttributes; - var content = this.htmlContent; - - output.push(indent + '<' + this.tag); - output.push(attrs.length ? ' ' + attrs.join(' ') : ''); - - if (this.isSingular) { - output.push('/>'); - } else { - - output.push('>'); - - if (content.length) { - isPretty && output.push('\n'); - output.push(content.join(isPretty ? '\n': '')); - isPretty && output.push('\n' + indent); - } - - output.push(''); - - } - - if (this.multiplier > 1) { - var all = output.join(''); - for (var m = this.multiplier - 1; m--;) { - output.push(isPretty ? '\n' : ''); - output.push(all); - } - } - - }, - - _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { - - var tail = excGroup[2]; - var exclusives = excGroup[1]; - - var branches = []; - - attachTail(excGroup, tail); - - for (var n = 0, nl = exclusives.length; n < nl; ++n) { - specChildren[specChildIndex] = exclusives[n]; // Mutate - var newBranch = deepCopyArray(this.spec); // Complete copy - specChildren[specChildIndex] = excGroup; // Return to regular - branches.push(newBranch); - } - - return branches; - - // attachTail - // Goes through children (equal candidacy) looking for places to append - // both the tailChild and tailSelector. Note: they may be placed in diff places - // as in the case of `(a 'c', b)>d` - function attachTail(start, tail, hasAttached) { - - var type = start[0]; - - var children = getChildren(start); - var tailChild = tail[0]; - var tailSelector = tail[1]; - var tailChildType = tail[2]; - - var hasAttached = hasAttached || { - child: false, - selector: false - }; - - if (hasAttached.child && hasAttached.selector) { - return hasAttached; - } - - if (children) { - for (var i = children.length; i-->0;) { - var child = children[i]; - - if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild - child = child[2][0]; - } - - if (tailChildType === 'sibling') { - var cChildren = getChildren(child); - if (!cChildren || !cChildren.length) { - // Add tailChild as sibling of child - children[i] = ['IncGroup', [ - child, - deepCopyArray(tailChild) - ]]; - hasAttached.child = true; //? - if (type === 'IncGroup') { - break; - } else { - continue; - } - } - } - hasAttached = attachTail(child, tail, { - child: false, - selector: false - }); - // Prevent descendants from being attached to more than one sibling - // e.g. a,b or a+b -- should only attach last one (i.e. b) - if (type === 'IncGroup' && hasAttached.child) { - break; - } - } - } - - if (!hasAttached.selector) { - if (start[0] === 'Element') { - if (tailSelector) { - push.apply(start[1][0], tailSelector); - } - hasAttached.selector = true; - } - } - - if (!hasAttached.child) { - if (children) { - if (tailChild) { - children.push(deepCopyArray(tailChild)); - } - hasAttached.child = true; - } - } - - return hasAttached; - } - - function getChildren(child) { - return child[0] === 'Element' ? child[1][1] : - child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? - child[1] : null; - } - }, - - processChildren: function(children) { - - var cl = children.length; - var i; - var childType; - - var exclusiveBranches = []; - - for (i = 0; i < cl; ++i) { - if (children[i][0] === 'ExcGroup') { - push.apply( - exclusiveBranches, - this._makeExclusiveBranches(children[i], children, i) - ); - } - } - - if (exclusiveBranches.length) { - - this.collectOutput = function(){}; - var html = []; - - for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { - var branch = exclusiveBranches[ei]; - html.push( - new (branch[0] === 'RootElement' ? RootElement : Element)( - branch, - this.config, - this.parentElement, - this.indentation - ).html - ); - } - - this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); - - } else { - for (i = 0; i < cl; ++i) { - var child = children[i][1]; - var childType = children[i][0]; - switch (childType) { - case 'Element': - this.processElement(child); - break; - case 'Prototype': - this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); - break; - case 'IncGroup': - this.processIncGroup(child); - break; - case 'ExcGroup': - throw new Error('SIML: Found ExcGroup in unexpected location'); - default: - this.processProperty(childType, child); - } - } - } - - }, - - processElement: function(spec) { - this.htmlContent.push( - new Generator.Element( - spec, - this.config, - this, - this.indentation + this.defaultIndentation - ).html - ); - }, - - processIncGroup: function(spec) { - this.processChildren(spec); - }, - - processProperty: function(type, args) { - // type = Attribute | Directive | Pseudo - var property = new Generator.properties[type]( - args, - this.config, - this, - this.indentation + this.defaultIndentation - ); - if (property.html) { - switch (property.type) { - case 'ATTR': - if (property.html) { - this.htmlAttributes.push(property.html); - } - break; - case 'CONTENT': - if (property.html) { - this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); - } - break; - } - } - }, - - augmentPrototypeSelector: function(selector) { - // Assume tag, if specified, to be first selector portion. - if (selector[0][0] !== 'Tag') { - return selector; - } - // Retrieve and unshift prototype selector portions: - unshift.apply(selector, this.prototypes[selector[0][1]] || []); - return selector; - } - }; - - function RootElement() { - Element.apply(this, arguments); - } - - RootElement.prototype = objCreate(Element.prototype); - RootElement.prototype.make = function(){ - // RootElement is just an empty space - }; - RootElement.prototype.collectOutput = function() { - this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; - }; - RootElement.prototype.processChildren = function() { - this.defaultIndentation = ''; - return Element.prototype.processChildren.apply(this, arguments); - }; - - function Generator(defaultGeneratorConfig) { - this.config = defaults(this.defaultConfig, defaultGeneratorConfig); - } - - Generator.escapeHTML = escapeHTML; - Generator.trim = trim; - Generator.isArray = isArray; - - Generator.Element = Element; - Generator.RootElement = RootElement; - - Generator.properties = { - Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), - Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), - Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) - }; - - Generator.prototype = { - - defaultConfig: { - pretty: true, - curly: false, - indent: DEFAULT_INDENTATION, - directives: {}, - attributes: {}, - pseudos: {}, - toTag: function(t) { - return t; - } - }, - - parse: function(spec, singleRunConfig) { - - singleRunConfig = defaults(this.config, singleRunConfig || {}); - - if (!singleRunConfig.pretty) { - singleRunConfig.indent = ''; - } - - if (!/^[\s\n\r]+$/.test(spec)) { - if (singleRunConfig.curly) { - // TODO: Find a nicer way of passing config to the PEGjs parser: - spec += '\n/*siml:curly=true*/'; - } - try { - spec = siml.PARSER.parse(spec); - } catch(e) { - if (e.line !== undefined && e.column !== undefined) { - throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); - } else { - throw new SyntaxError('SIML: ' + e.message); - } - } - } else { - spec = []; - } - - if (spec[0] === 'Element') { - return new Generator.Element( - spec[1], - singleRunConfig - ).html; - } - - return new Generator.RootElement( - ['RootElement', [['IncGroup', [spec]]]], - singleRunConfig - ).html; - } - - }; - - siml.Generator = Generator; - - siml.defaultGenerator = new Generator({ - pretty: true, - indent: DEFAULT_INDENTATION - }); - - siml.parse = function(s, c) { - return siml.defaultGenerator.parse(s, c); - }; - -}()); +var siml = typeof module != 'undefined' && module.exports ? module.exports : window.siml = {}; +(function() { + + 'use strict'; + + var push = [].push; + var unshift = [].unshift; + + var DEFAULT_TAG = 'div'; + var DEFAULT_INDENTATION = ' '; + + var SINGULAR_TAGS = { + input: 1, img: 1, meta: 1, link: 1, br: 1, hr: 1, + source: 1, area: 1, base: 1, col: 1 + }; + + var DEFAULT_DIRECTIVES = { + _fillHTML: { + type: 'CONTENT', + make: function(_, children, t) { + return t; + } + }, + _default: { + type: 'CONTENT', + make: function(dir) { + throw new Error('SIML: Directive not resolvable: ' + dir); + } + } + }; + + var DEFAULT_ATTRIBUTES = { + _default: { + type: 'ATTR', + make: function(attrName, value) { + if (value == null) { + return attrName; + } + return attrName + '="' + value + '"'; + } + }, + text: { + type: 'CONTENT', + make: function(_, t) { + return t; + } + } + }; + + var DEFAULT_PSEUDOS = { + _default: { + type: 'ATTR', + make: function(name) { + if (this.parentElement.tag === 'input') { + return 'type="' + name + '"'; + } + console.warn('Unknown pseudo class used:', name) + } + } + } + + var objCreate = Object.create || function (o) { + function F() {} + F.prototype = o; + return new F(); + }; + + function isArray(a) { + return {}.toString.call(a) === '[object Array]'; + } + function escapeHTML(h) { + return String(h).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """); + } + function trim(s) { + return String(s).replace(/^\s\s*|\s\s*$/g, ''); + } + function deepCopyArray(arr) { + var out = []; + for (var i = 0, l = arr.length; i < l; ++i) { + if (isArray(arr[i])) { + out[i] = deepCopyArray(arr[i]); + } else { + out[i] = arr[i]; + } + } + return out; + } + function defaults(defaults, obj) { + for (var i in defaults) { + if (!obj.hasOwnProperty(i)) { + obj[i] = defaults[i]; + } + } + return obj; + } + + function ConfigurablePropertyFactory(methodRepoName, fallbackMethodRepo) { + return function ConfigurableProperty(args, config, parentElement, indentation) { + + this.parentElement = parentElement; + this.indentation = indentation; + + args = [].slice.call(args); + + var propName = args[0]; + var propArguments = args[1]; + var propChildren = args[2]; + + if (propChildren) { + propArguments.unshift(propChildren); + } + + propArguments.unshift(propName); + + var propMaker = config[methodRepoName][propName] || fallbackMethodRepo[propName]; + if (!propMaker) { + propMaker = config[methodRepoName]._default || fallbackMethodRepo._default; + } + + if (!propMaker) { + throw new Error('SIML: No fallback for' + args.join()); + } + + this.type = propMaker.type; + this.html = propMaker.make.apply(this, propArguments) || ''; + + }; + } + + function Element(spec, config, parentElement, indentation) { + + this.spec = spec; + this.config = config || {}; + this.parentElement = parentElement || this; + this.indentation = indentation || ''; + this.defaultIndentation = config.indent; + + this.tag = null; + this.id = null; + this.attrs = []; + this.classes = []; + this.pseudos = []; + this.prototypes = objCreate(parentElement && parentElement.prototypes || null); + + this.isSingular = false; + this.multiplier = 1; + + this.isPretty = config.pretty; + + this.htmlOutput = []; + this.htmlContent = []; + this.htmlAttributes = []; + + this.selector = spec[0]; + + this.make(); + this.processChildren(spec[1]); + this.collectOutput(); + + this.html = this.htmlOutput.join(''); + + } + + Element.prototype = { + + make: function() { + + var attributeMap = {}; + var selector = this.selector.slice(); + var selectorPortionType; + var selectorPortion; + + this.augmentPrototypeSelector(selector); + + for (var i = 0, l = selector.length; i < l; ++i) { + selectorPortionType = selector[i][0]; + selectorPortion = selector[i][1]; + switch (selectorPortionType) { + case 'Tag': + if (!this.tag) { + this.tag = selectorPortion; + } + break; + case 'Id': + this.id = selectorPortion; break; + case 'Attr': + var attrName = selectorPortion[0]; + var attr = [attrName, [selectorPortion[1]]]; + // Attributes can only be defined once -- latest wins + if (attributeMap[attrName] != null) { + this.attrs[attributeMap[attrName]] = attr; + } else { + attributeMap[attrName] = this.attrs.push(attr) - 1; + } + break; + case 'Class': + this.classes.push(selectorPortion); break; + case 'Pseudo': + this.pseudos.push(selectorPortion); break; + } + } + + this.tag = this.config.toTag.call(this, this.tag || DEFAULT_TAG); + this.isSingular = this.tag in SINGULAR_TAGS; + + if (this.id) { + this.htmlAttributes.push( + 'id="' + this.id + '"' + ); + } + + if (this.classes.length) { + this.htmlAttributes.push( + 'class="' + this.classes.join(' ').replace(/(^| )\./g, '$1') + '"' + ); + } + + for (var i = 0, l = this.attrs.length; i < l; ++ i) { + this.processProperty('Attribute', this.attrs[i]); + } + + for (var i = 0, l = this.pseudos.length; i < l; ++ i) { + var p = this.pseudos[i]; + if (!isNaN(p[0])) { + this.multiplier = p[0]; + continue; + } + this.processProperty('Pseudo', p); + } + + }, + + collectOutput: function() { + + var indent = this.indentation; + var isPretty = this.isPretty; + var output = this.htmlOutput; + var attrs = this.htmlAttributes; + var content = this.htmlContent; + + output.push(indent + '<' + this.tag); + output.push(attrs.length ? ' ' + attrs.join(' ') : ''); + + if (this.isSingular) { + output.push('/>'); + } else { + + output.push('>'); + + if (content.length) { + isPretty && output.push('\n'); + output.push(content.join(isPretty ? '\n': '')); + isPretty && output.push('\n' + indent); + } + + output.push(''); + + } + + if (this.multiplier > 1) { + var all = output.join(''); + for (var m = this.multiplier - 1; m--;) { + output.push(isPretty ? '\n' : ''); + output.push(all); + } + } + + }, + + _makeExclusiveBranches: function(excGroup, specChildren, specChildIndex) { + + var tail = excGroup[2]; + var exclusives = excGroup[1]; + + var branches = []; + + attachTail(excGroup, tail); + + for (var n = 0, nl = exclusives.length; n < nl; ++n) { + specChildren[specChildIndex] = exclusives[n]; // Mutate + var newBranch = deepCopyArray(this.spec); // Complete copy + specChildren[specChildIndex] = excGroup; // Return to regular + branches.push(newBranch); + } + + return branches; + + // attachTail + // Goes through children (equal candidacy) looking for places to append + // both the tailChild and tailSelector. Note: they may be placed in diff places + // as in the case of `(a 'c', b)>d` + function attachTail(start, tail, hasAttached) { + + var type = start[0]; + + var children = getChildren(start); + var tailChild = tail[0]; + var tailSelector = tail[1]; + var tailChildType = tail[2]; + + var hasAttached = hasAttached || { + child: false, + selector: false + }; + + if (hasAttached.child && hasAttached.selector) { + return hasAttached; + } + + if (children) { + for (var i = children.length; i-->0;) { + var child = children[i]; + + if (child[0] === 'ExcGroup' && child[2][0]) { // has tailChild + child = child[2][0]; + } + + if (tailChildType === 'sibling') { + var cChildren = getChildren(child); + if (!cChildren || !cChildren.length) { + // Add tailChild as sibling of child + children[i] = ['IncGroup', [ + child, + deepCopyArray(tailChild) + ]]; + hasAttached.child = true; //? + if (type === 'IncGroup') { + break; + } else { + continue; + } + } + } + hasAttached = attachTail(child, tail, { + child: false, + selector: false + }); + // Prevent descendants from being attached to more than one sibling + // e.g. a,b or a+b -- should only attach last one (i.e. b) + if (type === 'IncGroup' && hasAttached.child) { + break; + } + } + } + + if (!hasAttached.selector) { + if (start[0] === 'Element') { + if (tailSelector) { + push.apply(start[1][0], tailSelector); + } + hasAttached.selector = true; + } + } + + if (!hasAttached.child) { + if (children) { + if (tailChild) { + children.push(deepCopyArray(tailChild)); + } + hasAttached.child = true; + } + } + + return hasAttached; + } + + function getChildren(child) { + return child[0] === 'Element' ? child[1][1] : + child[0] === 'ExcGroup' || child[0] === 'IncGroup' ? + child[1] : null; + } + }, + + processChildren: function(children) { + + var cl = children.length; + var i; + var childType; + + var exclusiveBranches = []; + + for (i = 0; i < cl; ++i) { + if (children[i][0] === 'ExcGroup') { + push.apply( + exclusiveBranches, + this._makeExclusiveBranches(children[i], children, i) + ); + } + } + + if (exclusiveBranches.length) { + + this.collectOutput = function(){}; + var html = []; + + for (var ei = 0, el = exclusiveBranches.length; ei < el; ++ei) { + var branch = exclusiveBranches[ei]; + html.push( + new (branch[0] === 'RootElement' ? RootElement : Element)( + branch, + this.config, + this.parentElement, + this.indentation + ).html + ); + } + + this.htmlOutput.push(html.join(this.isPretty ? '\n' : '')); + + } else { + for (i = 0; i < cl; ++i) { + var child = children[i][1]; + var childType = children[i][0]; + switch (childType) { + case 'Element': + this.processElement(child); + break; + case 'Prototype': + this.prototypes[child[0]] = this.augmentPrototypeSelector(child[1]); + break; + case 'IncGroup': + this.processIncGroup(child); + break; + case 'ExcGroup': + throw new Error('SIML: Found ExcGroup in unexpected location'); + default: + this.processProperty(childType, child); + } + } + } + + }, + + processElement: function(spec) { + this.htmlContent.push( + new Generator.Element( + spec, + this.config, + this, + this.indentation + this.defaultIndentation + ).html + ); + }, + + processIncGroup: function(spec) { + this.processChildren(spec); + }, + + processProperty: function(type, args) { + // type = Attribute | Directive | Pseudo + var property = new Generator.properties[type]( + args, + this.config, + this, + this.indentation + this.defaultIndentation + ); + if (property.html) { + switch (property.type) { + case 'ATTR': + if (property.html) { + this.htmlAttributes.push(property.html); + } + break; + case 'CONTENT': + if (property.html) { + this.htmlContent.push(this.indentation + this.defaultIndentation + property.html); + } + break; + } + } + }, + + augmentPrototypeSelector: function(selector) { + // Assume tag, if specified, to be first selector portion. + if (selector[0][0] !== 'Tag') { + return selector; + } + // Retrieve and unshift prototype selector portions: + unshift.apply(selector, this.prototypes[selector[0][1]] || []); + return selector; + } + }; + + function RootElement() { + Element.apply(this, arguments); + } + + RootElement.prototype = objCreate(Element.prototype); + RootElement.prototype.make = function(){ + // RootElement is just an empty space + }; + RootElement.prototype.collectOutput = function() { + this.htmlOutput = [this.htmlContent.join(this.isPretty ? '\n': '')]; + }; + RootElement.prototype.processChildren = function() { + this.defaultIndentation = ''; + return Element.prototype.processChildren.apply(this, arguments); + }; + + function Generator(defaultGeneratorConfig) { + this.config = defaults(this.defaultConfig, defaultGeneratorConfig); + } + + Generator.escapeHTML = escapeHTML; + Generator.trim = trim; + Generator.isArray = isArray; + + Generator.Element = Element; + Generator.RootElement = RootElement; + + Generator.properties = { + Attribute: ConfigurablePropertyFactory('attributes', DEFAULT_ATTRIBUTES), + Directive: ConfigurablePropertyFactory('directives', DEFAULT_DIRECTIVES), + Pseudo: ConfigurablePropertyFactory('pseudos', DEFAULT_PSEUDOS) + }; + + Generator.prototype = { + + defaultConfig: { + pretty: true, + curly: false, + indent: DEFAULT_INDENTATION, + directives: {}, + attributes: {}, + pseudos: {}, + toTag: function(t) { + return t; + } + }, + + parse: function(spec, singleRunConfig) { + + singleRunConfig = defaults(this.config, singleRunConfig || {}); + + if (!singleRunConfig.pretty) { + singleRunConfig.indent = ''; + } + + if (!/^[\s\n\r]+$/.test(spec)) { + if (singleRunConfig.curly) { + // TODO: Find a nicer way of passing config to the PEGjs parser: + spec += '\n/*siml:curly=true*/'; + } + try { + spec = siml.PARSER.parse(spec); + } catch(e) { + if (e.line !== undefined && e.column !== undefined) { + throw new SyntaxError('SIML: Line ' + e.line + ', column ' + e.column + ': ' + e.message); + } else { + throw new SyntaxError('SIML: ' + e.message); + } + } + } else { + spec = []; + } + + if (spec[0] === 'Element') { + return new Generator.Element( + spec[1], + singleRunConfig + ).html; + } + + return new Generator.RootElement( + ['RootElement', [['IncGroup', [spec]]]], + singleRunConfig + ).html; + } + + }; + + siml.Generator = Generator; + + siml.defaultGenerator = new Generator({ + pretty: true, + indent: DEFAULT_INDENTATION + }); + + siml.parse = function(s, c) { + return siml.defaultGenerator.parse(s, c); + }; + +}()); diff --git a/test/ConfigurationSpec.js b/test/ConfigurationSpec.js index 02e4835..2902c60 100644 --- a/test/ConfigurationSpec.js +++ b/test/ConfigurationSpec.js @@ -1,100 +1,100 @@ -describe('Configuration', function() { - describe('config:pretty', function() { - it('Prints HTML using the passed method of indentation', function() { - expect(siml.parse('\ - section {\ - id: 123\ - header {\ - h1 > em { text: "FooBar" }\ - id : 456\ - }\ - div.foo {\ - span > a {\ - strong { text: \'ok\' }\ - em\ - }\ - }\ - }\ - ', { pretty: true, indent: '___:' })).toBe([ - '
', - '___:
', - '___:___:

', - '___:___:___:', - '___:___:___:___:FooBar', - '___:___:___:', - '___:___:

', - '___:
', - '___:', - '
' - ].join('\n')); - }); - }); - describe('config:curly', function() { - it('Does attempt magical whitespace when curly is undefined/false [default]', function() { - expect(siml.parse('\ - a\n\ - b\n\ - c\n\ - d\n\ - e\n\ - f\n\ - ', {pretty:false})).toBe([ - '', - '', - '', - '', - '', - '', - '', - '' - ].join('')); - expect(siml.parse('\ - a\n\ - b\n\ - c { // curly here, even though the rest of the doc is tabbed \n\ - d\n\ - }\n\ - e\n\ - f\n\ - ', {pretty:false})).toBe([ - '', - '', - '', - '', - '', - '', - '', - '' - ].join('')); - }); - it('Does not attempt magical whitespace when curly is true', function() { - expect(siml.parse('\ - a\n\ - b\n\ - c {\n\ - d\n\ - }\n\ - e\n\ - f\n\ - ', {pretty:false,curly:true})).toBe([ - // In this case it has assumed a structure of: 'a b c{d} e f': - '', - '', - '', - '', - '', - '', - '' - ].join('')); - }); - }); +describe('Configuration', function() { + describe('config:pretty', function() { + it('Prints HTML using the passed method of indentation', function() { + expect(siml.parse('\ + section {\ + id: 123\ + header {\ + h1 > em { text: "FooBar" }\ + id : 456\ + }\ + div.foo {\ + span > a {\ + strong { text: \'ok\' }\ + em\ + }\ + }\ + }\ + ', { pretty: true, indent: '___:' })).toBe([ + '
', + '___:
', + '___:___:

', + '___:___:___:', + '___:___:___:___:FooBar', + '___:___:___:', + '___:___:

', + '___:
', + '___:', + '
' + ].join('\n')); + }); + }); + describe('config:curly', function() { + it('Does attempt magical whitespace when curly is undefined/false [default]', function() { + expect(siml.parse('\ + a\n\ + b\n\ + c\n\ + d\n\ + e\n\ + f\n\ + ', {pretty:false})).toBe([ + '', + '', + '', + '', + '', + '', + '', + '' + ].join('')); + expect(siml.parse('\ + a\n\ + b\n\ + c { // curly here, even though the rest of the doc is tabbed \n\ + d\n\ + }\n\ + e\n\ + f\n\ + ', {pretty:false})).toBe([ + '', + '', + '', + '', + '', + '', + '', + '' + ].join('')); + }); + it('Does not attempt magical whitespace when curly is true', function() { + expect(siml.parse('\ + a\n\ + b\n\ + c {\n\ + d\n\ + }\n\ + e\n\ + f\n\ + ', {pretty:false,curly:true})).toBe([ + // In this case it has assumed a structure of: 'a b c{d} e f': + '', + '', + '', + '', + '', + '', + '' + ].join('')); + }); + }); }); \ No newline at end of file diff --git a/test/DefaultGeneratorSpec.js b/test/DefaultGeneratorSpec.js index 40670ba..ee768e8 100644 --- a/test/DefaultGeneratorSpec.js +++ b/test/DefaultGeneratorSpec.js @@ -1,482 +1,482 @@ -describe('DefaultParser: HTML Generation', function() { - - it('Should parse+convert basic schemas', function() { - expect('a').toGenerate(''); - expect('a { id: "foo" }').toGenerate(''); - expect('a>b').toGenerate(''); - expect('x { a b c d }').toGenerate(''); - expect('a {id:1;href:"http://foo.com";target:"blah"}').toGenerate(''); - }); - - describe('Siblings & Descendants', function() { - it('Handles sibling+descendant combos correctly', function() { - expect('a>b{c}d').toGenerate(''); - expect('a:2{b>c}').toGenerate(''); - expect('a+b{c} d').toGenerate(''); - expect('a>b>c+d>e').toGenerate(''); - expect('a b c + d > p + x').toGenerate('

'); - expect('f>(s{"SIML"} "is" a)').toGenerate('SIMLis'); - }); - describe('Descendant combinator', function() { - it('Should be able to handle them', function() { - expect('a > b').toGenerate(''); - expect('a > b > c').toGenerate(''); - expect('a>b > c >d').toGenerate(''); - expect('div > ul { li > a { href:"foo" }}').toGenerate('
'); - }); - }); - }); - - describe('Text', function() { - it('Should be able to parse+convert quoted text', function() { - expect('t "foo"').toGenerate('foo'); - expect("t 'foo'").toGenerate('foo'); - expect('t { "This" "is" "Sparta" }').toGenerate('ThisisSparta'); - expect('foo { "Look: " span "HERE!" }').toGenerate('Look: HERE!'); - expect('foo { "Look: " span{} "HERE!" }').toGenerate('Look: HERE!'); - expect('a "b" c "d"').toGenerate('bd'); - expect(' a { @_fillHTML("foo"); @_fillHTML("baz"); " " em } ').toGenerate('foobaz '); - }); - }); - - describe('ExclusiveGroups `(x,y/t)` shortcut', function() { - describe('Following Series', function() { - it('Should be able to parse uses correctly', function() { - expect('t (b/c)').toGenerate(''); - expect('t (b>a/c)').toGenerate(''); - expect('t (a.klass/a#id)').toGenerate(''); - expect('t{ b (x/z) }').toGenerate(''); - expect('body (b/a b)').toGenerate(''); - expect('a (b, (c/d))').toGenerate(''); - expect('a>b>c>(x/y)').toGenerate(''); - expect('a>b>c>(x,y)').toGenerate(''); - expect('ul li ("foo"/"blah"/"bam"/"whoa")').toGenerate('
  • foo
  • blah
  • bam
  • whoa
') - }); - }); - describe('Preceeding Series', function() { - it('Should be able to parse uses correctly', function() { - expect('body (b/a b) "txt"').toGenerate('txttxt'); - expect('t (a.klass/a#id)+j').toGenerate(''); - expect('a (b, (c/d)) "eggs"').toGenerate('eggseggs'); - expect('((b/c) x) t').toGenerate(''); - expect('((a))').toGenerate(''); - expect('(a{id:blah;}/b[id=foo]).same').toGenerate(''); - expect('((a/b)/(c/d))x').toGenerate(''); - expect('(a/B)"foo"').toGenerate('foofoo'); - }); - }); - describe('Deeper test cases', function() { - it('Should be able to parse correctly', function() { - expect('t (a m+q/a)+j').toGenerate(''); - expect('\ - section+(X/Y(diva/divb)) {\n\ - h1(a/span)em[id=foo]\n\ - (body)(a)(href:foo;)\ - }\ - ').toGenerate([ - '
', - '', - '

', - '

', - '', - '
', - '
', - '', - '', - '

', - '

', - '', - '
', - '
', - '', - '', - '

', - '

', - '', - '
', - '
' - ].join('')); - }); - }); - }); - - describe('Attributes', function() { - it('Should be able to parse attributes in the form x:Number|String', function() { - expect('a{a:1;}').toGenerate(''); - expect('a{a: 1}').toGenerate(''); - expect('a{a:"1"}').toGenerate(''); - expect('a{a: "1";}').toGenerate(''); - expect('a{a:1}').toGenerate(''); // CONSIDERED A PSEUDO !! - expect('\ - section {\n\ - a:y; // optional semi-colon (used for differentiating it from pseudo classes)\n\ - b: 2\n\ - c:"9999" d:9847; href:\'http://foo.com\'\n\ - }\ - ').toGenerate('
'); - }); - }); - - describe('Selector Support', function() { - describe('When I do not specify a tag', function() { - it('Should use DIV as default', function() { - expect('#foo').toGenerate('
'); - expect('.foo').toGenerate('
'); - expect('em > #a.b').toGenerate('
'); - }); - }); - describe('When using a.b#c (In various orders)', function() { - it('Should generate correctly', function() { - expect('t#foo').toGenerate(''); - expect('#foo').toGenerate('
'); - expect('t#foo.baz').toGenerate(''); - expect('t#foo#abc').toGenerate(''); // take MOST RECENT - expect('t.a.b.c.d#e').toGenerate(''); - }); - }); - describe('Attribute selectors [abc=def]', function() { - describe('Various different attribute selectors', function() { - it('Should parse correctly', function() { - expect('a[foo=1]').toGenerate(''); - expect('a[foo=abc]').toGenerate(''); - expect('a[b=ThisIsABitLonger]').toGenerate(''); - expect('a[b="c"][d=e][f=\'g\']').toGenerate(''); - }); - }); - }); - }); - - describe('Prototypes', function() { - describe('Basic use-cases', function() { - describe('Reference prototype with default/placeholder attributes', function() { - it('Should generate HTML by augmenting the prototype with the subject selector', function() { - expect('\ - link = a.link.special[href=""][title="placeholder"] \n\ - link \n\ - link.another \n\ - link[href="http://foo.com/blah"].yet.another \n\ - link[href="foo"][title="blah"] \n\ - ').toGenerate([ - '', - '', - '', - '', - ].join('')); - }); - }); - }); - describe('Referencing a prototype that has been set', function() { - it('Should recall the prototype selector', function() { - expect('a=b;a').toGenerate(''); - }); - }); - describe('Referencing a prototype that has been set and augmenting', function() { - it('Should recall the prototype selector and augment', function() { - expect('a=b.foo; a.baz').toGenerate(''); - }); - }); - describe('Overwriting a prototype with an augmentation of itself', function() { - it('Should be successfully overwritten', function() { - expect('\ - a = b.foo#bar[c=123]\n\ - a\n\ - a = a.more\n\ - a\n\ - ').toGenerate(''); - }); - }); - describe('Scoping prototype definitions', function() { - it('Should successfully scope prototypes to their nested level', function() { - expect('\ - foo=a \n\ - lvl_0 \n\ - foo=b \n\ - lvl_1 \n\ - foo=c \n\ - lvl_2 \n\ - foo=d \n\ - foo \n\ - foo \n\ - foo \n\ - foo \n\ - ').toGenerate([ - '', - '', - '', - '', - '', - '', - '', - '', - '', - '' - ].join('')); - }); - }); - }); - - describe('Nesting', function() { - it('Should be able to handle various levels of nesting', function() { - expect('a{b{c{d{e{f{g{h{i}}}}}}}}').toGenerate(''); - expect('\ - section {\ - id: 123;\ - header {\ - h1 > em { text: "FooBar" }\ - id : 456;\ - }\ - div.foo {\ - span > a > strong { text: \'ok\' }\ - }\ - }\ - ').toGenerate([ - '
', - '
', - '

FooBar

', - '
', - '
', - '', - 'ok', - '', - '
', - '
' - ].join('')); - }); - }); - - describe('Plain HTML', function() { - it('Should be able to output plain HTML within `...`', function() { - expect('a `wow`').toGenerate('wow'); - expect('\ - section {\ - ``\ - data-x: `raw-<>`;\ - `\ - This <><>\n\ - is\n\ - \n\ - ` "this is es"\n\ - // Ensure I can use back-tick without escaping if my delimiters\n\ - // are multi-back-tick (heredoc-esque):\n\ - ```\n\ - more``\n\ - unescaped`\n\ - ``\n\ - ```\ - }\ - ').toGenerate([ - '
', - '', - // Inner HTML whitespace is maintained - ' This <><>\n', - ' is\n', - ' \n', - ' ', - 'this is es<caped>', - '\n', - ' more``\n', - ' unescaped`\n', - ' ``\n', - ' ', - '
' - ].join('')); - }); - }); - - describe('Escaping', function() { - it('Escapes qouted text', function() { - expect('"O < K"').toGenerate('O < K'); - expect('"O < K" \'&&\'').toGenerate('O < K&&'); - }); - it('Escapes quoted attribute values', function() { - expect('d { id: "<<" }').toGenerate(''); - }); - it('Does not escape backticked text', function() { - expect('`O < K`').toGenerate('O < K'); - }); - it('Quotes strings are not parsed within backticks', function() { - expect('` "this" and \'this ... \' ..`').toGenerate(' "this" and \'this ... \' ..'); - }); - it('Does not escape backticked attribute values', function() { - expect('d { id: `<<` }').toGenerate(''); - }); - it('Does not escape/parse backticked strings within regular quoted strings', function() { - expect('"`ok` .. `ok2`"').toGenerate('`ok` .. `ok2`'); - }); - }); - - describe('Significant whitespace', function() { - it('Should be able to create a hierarchy from indentation instead of curlies', function() { - expect('\ - x\n\ - a\n\ - b\n\ - c\n\ - d\n\ - e\n\ - f\n\ - ').toGenerate([ - '', - '', - '', - '', - '', - '', - '', - '', - '' - ].join('')); - }); - it('Should handle fillText directives correctly', function() { - expect('\ - body\n\ - "a"\n\ - "b"\n\ - section\n\ - ""\n\ - "d"\n\ - ').toGenerate([ - '', - 'ab
<c>d', - '' - ].join('')); - }); - it('Should handle inner braces and curlies by ignoring them and content within', function() { - expect('\ - body\n\ - a\n\ - b {\n\ - // These should be considered equal indentation since they\'re within curlies\n\ - c\n\ - e\n\ - f\n\ - }\n\ - p {\n\ - e\n\ - u\n\ - }\n\ - m\n\ - xp {a:123;}\n\ - lp#a.g {b:123;}\n\ - a(\n\ - a/\n\ - b/\n\ - c\n\ - )\n\ - ').toGenerate([ - '', - '', - '', - '', - '', - '', - '', - '

', - '', - '', - '

', - '', - '', - '', - '
', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '' - ].join('')); - }); - it('Should handle inner-brace case #2', function() { - expect('\ -html\n\ - head\n\ - meta\n\ - title\n\ - body\n\ - section\n\ - h1 \'ok\'\n\ - p (\n\ - \'a\'/\'b\'\n\ - )\n\ - ').toGenerate([ - '', - '', - '', - '', - '', - '', - '
', - '

ok

', - '
', - '

a

', - '

b

', - '', - '' - ].join('')); - }); - it('Should handle a large document correctly', function() { - expect('\ - html\n\ - head\n\ - meta\n\ - charset: \'utf-8\'\n\ - title \'Testing Testing \\\' ok\'\n\ - body \n\ - section.foo#t[tab-index=1] \n\ - ul > li\n\ - \'A mixture of tabs and curlies!??\'\n\ - footer\n\ - br\n\ - em span br\n\ - br\n\ - div\n\ - div > strong > em \n\ - id: \'anEM\' \n\ - input \n\ - type: "checkbox"\n\ - ').toGenerate([ - '', - '', - '', - 'Testing Testing \' ok', - '', - '', - '
', - '
  • A mixture of tabs and curlies!??
', - '
', - '
', - '
', - '
', - '
', - '
', - '
', - '', - '
', - '
', - '
', - '', - '' - ].join('')); - }); - }); - - describe('Multiplier [SimplerSelector:Number]', function() { - it('Should multiply subject element by N times', function() { - expect('a:3{href:"f";text:"ok"}').toGenerate([ - 'ok', - 'ok', - 'ok' - ].join('')); - }); - it('Should work on singular tags', function() { - expect('br:2').toGenerate('

'); - }); - }); - +describe('DefaultParser: HTML Generation', function() { + + it('Should parse+convert basic schemas', function() { + expect('a').toGenerate(''); + expect('a { id: "foo" }').toGenerate(''); + expect('a>b').toGenerate(''); + expect('x { a b c d }').toGenerate(''); + expect('a {id:1;href:"http://foo.com";target:"blah"}').toGenerate(''); + }); + + describe('Siblings & Descendants', function() { + it('Handles sibling+descendant combos correctly', function() { + expect('a>b{c}d').toGenerate(''); + expect('a:2{b>c}').toGenerate(''); + expect('a+b{c} d').toGenerate(''); + expect('a>b>c+d>e').toGenerate(''); + expect('a b c + d > p + x').toGenerate('

'); + expect('f>(s{"SIML"} "is" a)').toGenerate('SIMLis'); + }); + describe('Descendant combinator', function() { + it('Should be able to handle them', function() { + expect('a > b').toGenerate(''); + expect('a > b > c').toGenerate(''); + expect('a>b > c >d').toGenerate(''); + expect('div > ul { li > a { href:"foo" }}').toGenerate('
'); + }); + }); + }); + + describe('Text', function() { + it('Should be able to parse+convert quoted text', function() { + expect('t "foo"').toGenerate('foo'); + expect("t 'foo'").toGenerate('foo'); + expect('t { "This" "is" "Sparta" }').toGenerate('ThisisSparta'); + expect('foo { "Look: " span "HERE!" }').toGenerate('Look: HERE!'); + expect('foo { "Look: " span{} "HERE!" }').toGenerate('Look: HERE!'); + expect('a "b" c "d"').toGenerate('bd'); + expect(' a { @_fillHTML("foo"); @_fillHTML("baz"); " " em } ').toGenerate('foobaz '); + }); + }); + + describe('ExclusiveGroups `(x,y/t)` shortcut', function() { + describe('Following Series', function() { + it('Should be able to parse uses correctly', function() { + expect('t (b/c)').toGenerate(''); + expect('t (b>a/c)').toGenerate(''); + expect('t (a.klass/a#id)').toGenerate(''); + expect('t{ b (x/z) }').toGenerate(''); + expect('body (b/a b)').toGenerate(''); + expect('a (b, (c/d))').toGenerate(''); + expect('a>b>c>(x/y)').toGenerate(''); + expect('a>b>c>(x,y)').toGenerate(''); + expect('ul li ("foo"/"blah"/"bam"/"whoa")').toGenerate('
  • foo
  • blah
  • bam
  • whoa
') + }); + }); + describe('Preceeding Series', function() { + it('Should be able to parse uses correctly', function() { + expect('body (b/a b) "txt"').toGenerate('txttxt'); + expect('t (a.klass/a#id)+j').toGenerate(''); + expect('a (b, (c/d)) "eggs"').toGenerate('eggseggs'); + expect('((b/c) x) t').toGenerate(''); + expect('((a))').toGenerate(''); + expect('(a{id:blah;}/b[id=foo]).same').toGenerate(''); + expect('((a/b)/(c/d))x').toGenerate(''); + expect('(a/B)"foo"').toGenerate('foofoo'); + }); + }); + describe('Deeper test cases', function() { + it('Should be able to parse correctly', function() { + expect('t (a m+q/a)+j').toGenerate(''); + expect('\ + section+(X/Y(diva/divb)) {\n\ + h1(a/span)em[id=foo]\n\ + (body)(a)(href:foo;)\ + }\ + ').toGenerate([ + '
', + '', + '

', + '

', + '', + '
', + '
', + '', + '', + '

', + '

', + '', + '
', + '
', + '', + '', + '

', + '

', + '', + '
', + '
' + ].join('')); + }); + }); + }); + + describe('Attributes', function() { + it('Should be able to parse attributes in the form x:Number|String', function() { + expect('a{a:1;}').toGenerate(''); + expect('a{a: 1}').toGenerate(''); + expect('a{a:"1"}').toGenerate(''); + expect('a{a: "1";}').toGenerate(''); + expect('a{a:1}').toGenerate(''); // CONSIDERED A PSEUDO !! + expect('\ + section {\n\ + a:y; // optional semi-colon (used for differentiating it from pseudo classes)\n\ + b: 2\n\ + c:"9999" d:9847; href:\'http://foo.com\'\n\ + }\ + ').toGenerate('
'); + }); + }); + + describe('Selector Support', function() { + describe('When I do not specify a tag', function() { + it('Should use DIV as default', function() { + expect('#foo').toGenerate('
'); + expect('.foo').toGenerate('
'); + expect('em > #a.b').toGenerate('
'); + }); + }); + describe('When using a.b#c (In various orders)', function() { + it('Should generate correctly', function() { + expect('t#foo').toGenerate(''); + expect('#foo').toGenerate('
'); + expect('t#foo.baz').toGenerate(''); + expect('t#foo#abc').toGenerate(''); // take MOST RECENT + expect('t.a.b.c.d#e').toGenerate(''); + }); + }); + describe('Attribute selectors [abc=def]', function() { + describe('Various different attribute selectors', function() { + it('Should parse correctly', function() { + expect('a[foo=1]').toGenerate(''); + expect('a[foo=abc]').toGenerate(''); + expect('a[b=ThisIsABitLonger]').toGenerate(''); + expect('a[b="c"][d=e][f=\'g\']').toGenerate(''); + }); + }); + }); + }); + + describe('Prototypes', function() { + describe('Basic use-cases', function() { + describe('Reference prototype with default/placeholder attributes', function() { + it('Should generate HTML by augmenting the prototype with the subject selector', function() { + expect('\ + link = a.link.special[href=""][title="placeholder"] \n\ + link \n\ + link.another \n\ + link[href="http://foo.com/blah"].yet.another \n\ + link[href="foo"][title="blah"] \n\ + ').toGenerate([ + '', + '', + '', + '', + ].join('')); + }); + }); + }); + describe('Referencing a prototype that has been set', function() { + it('Should recall the prototype selector', function() { + expect('a=b;a').toGenerate(''); + }); + }); + describe('Referencing a prototype that has been set and augmenting', function() { + it('Should recall the prototype selector and augment', function() { + expect('a=b.foo; a.baz').toGenerate(''); + }); + }); + describe('Overwriting a prototype with an augmentation of itself', function() { + it('Should be successfully overwritten', function() { + expect('\ + a = b.foo#bar[c=123]\n\ + a\n\ + a = a.more\n\ + a\n\ + ').toGenerate(''); + }); + }); + describe('Scoping prototype definitions', function() { + it('Should successfully scope prototypes to their nested level', function() { + expect('\ + foo=a \n\ + lvl_0 \n\ + foo=b \n\ + lvl_1 \n\ + foo=c \n\ + lvl_2 \n\ + foo=d \n\ + foo \n\ + foo \n\ + foo \n\ + foo \n\ + ').toGenerate([ + '', + '', + '', + '', + '', + '', + '', + '', + '', + '' + ].join('')); + }); + }); + }); + + describe('Nesting', function() { + it('Should be able to handle various levels of nesting', function() { + expect('a{b{c{d{e{f{g{h{i}}}}}}}}').toGenerate(''); + expect('\ + section {\ + id: 123;\ + header {\ + h1 > em { text: "FooBar" }\ + id : 456;\ + }\ + div.foo {\ + span > a > strong { text: \'ok\' }\ + }\ + }\ + ').toGenerate([ + '
', + '
', + '

FooBar

', + '
', + '
', + '', + 'ok', + '', + '
', + '
' + ].join('')); + }); + }); + + describe('Plain HTML', function() { + it('Should be able to output plain HTML within `...`', function() { + expect('a `wow`').toGenerate('wow'); + expect('\ + section {\ + ``\ + data-x: `raw-<>`;\ + `\ + This <><>\n\ + is\n\ + \n\ + ` "this is es"\n\ + // Ensure I can use back-tick without escaping if my delimiters\n\ + // are multi-back-tick (heredoc-esque):\n\ + ```\n\ + more``\n\ + unescaped`\n\ + ``\n\ + ```\ + }\ + ').toGenerate([ + '
', + '', + // Inner HTML whitespace is maintained + ' This <><>\n', + ' is\n', + ' \n', + ' ', + 'this is es<caped>', + '\n', + ' more``\n', + ' unescaped`\n', + ' ``\n', + ' ', + '
' + ].join('')); + }); + }); + + describe('Escaping', function() { + it('Escapes qouted text', function() { + expect('"O < K"').toGenerate('O < K'); + expect('"O < K" \'&&\'').toGenerate('O < K&&'); + }); + it('Escapes quoted attribute values', function() { + expect('d { id: "<<" }').toGenerate(''); + }); + it('Does not escape backticked text', function() { + expect('`O < K`').toGenerate('O < K'); + }); + it('Quotes strings are not parsed within backticks', function() { + expect('` "this" and \'this ... \' ..`').toGenerate(' "this" and \'this ... \' ..'); + }); + it('Does not escape backticked attribute values', function() { + expect('d { id: `<<` }').toGenerate(''); + }); + it('Does not escape/parse backticked strings within regular quoted strings', function() { + expect('"`ok` .. `ok2`"').toGenerate('`ok` .. `ok2`'); + }); + }); + + describe('Significant whitespace', function() { + it('Should be able to create a hierarchy from indentation instead of curlies', function() { + expect('\ + x\n\ + a\n\ + b\n\ + c\n\ + d\n\ + e\n\ + f\n\ + ').toGenerate([ + '', + '', + '', + '', + '', + '', + '', + '', + '' + ].join('')); + }); + it('Should handle fillText directives correctly', function() { + expect('\ + body\n\ + "a"\n\ + "b"\n\ + section\n\ + ""\n\ + "d"\n\ + ').toGenerate([ + '', + 'ab
<c>d', + '' + ].join('')); + }); + it('Should handle inner braces and curlies by ignoring them and content within', function() { + expect('\ + body\n\ + a\n\ + b {\n\ + // These should be considered equal indentation since they\'re within curlies\n\ + c\n\ + e\n\ + f\n\ + }\n\ + p {\n\ + e\n\ + u\n\ + }\n\ + m\n\ + xp {a:123;}\n\ + lp#a.g {b:123;}\n\ + a(\n\ + a/\n\ + b/\n\ + c\n\ + )\n\ + ').toGenerate([ + '', + '', + '', + '', + '', + '', + '', + '

', + '', + '', + '

', + '', + '', + '', + '
', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '' + ].join('')); + }); + it('Should handle inner-brace case #2', function() { + expect('\ +html\n\ + head\n\ + meta\n\ + title\n\ + body\n\ + section\n\ + h1 \'ok\'\n\ + p (\n\ + \'a\'/\'b\'\n\ + )\n\ + ').toGenerate([ + '', + '', + '', + '', + '', + '', + '
', + '

ok

', + '
', + '

a

', + '

b

', + '', + '' + ].join('')); + }); + it('Should handle a large document correctly', function() { + expect('\ + html\n\ + head\n\ + meta\n\ + charset: \'utf-8\'\n\ + title \'Testing Testing \\\' ok\'\n\ + body \n\ + section.foo#t[tab-index=1] \n\ + ul > li\n\ + \'A mixture of tabs and curlies!??\'\n\ + footer\n\ + br\n\ + em span br\n\ + br\n\ + div\n\ + div > strong > em \n\ + id: \'anEM\' \n\ + input \n\ + type: "checkbox"\n\ + ').toGenerate([ + '', + '', + '', + 'Testing Testing \' ok', + '', + '', + '
', + '
  • A mixture of tabs and curlies!??
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '', + '
', + '
', + '
', + '', + '' + ].join('')); + }); + }); + + describe('Multiplier [SimplerSelector:Number]', function() { + it('Should multiply subject element by N times', function() { + expect('a:3{href:"f";text:"ok"}').toGenerate([ + 'ok', + 'ok', + 'ok' + ].join('')); + }); + it('Should work on singular tags', function() { + expect('br:2').toGenerate('

'); + }); + }); + }); \ No newline at end of file diff --git a/test/DirectivesSpec.js b/test/DirectivesSpec.js index 6e87bb8..5e22f46 100644 --- a/test/DirectivesSpec.js +++ b/test/DirectivesSpec.js @@ -1,66 +1,66 @@ -describe('Directives', function() { - - describe('Custom Generator with directives', function() { - - var directives = {}; - - var customGen = new siml.Generator({ - directives: directives, - pretty: false - }); - - it('Throws error on undefined directives', function() { - expect(function() { - customGen.parse('a @foo'); - }).toThrow('SIML: Directive not resolvable: foo'); - }); - - describe('Custom @foo directive', function() { - - beforeEach(function() { - directives.foo = { - type: 'CONTENT', - make: function(name, children/*, args */) { - this.parentElement.htmlContent.push( - '' + [].slice.call(arguments, 2).join() - ); - if (children.length) { - this.parentElement.processChildren(children); - } - this.parentElement.htmlContent.push(''); - } - }; - }); - - afterEach(function() { - delete directives.foo; - }); - - it('Generates @foo with no args correctly', function() { - expect(customGen.parse('div @foo')).toBe('
'); - }); - - it('Generates @foo with args correctly', function() { - expect(customGen.parse('div @foo(123,"four", false)')).toBe('
123,four,false
'); - }); - - it('Generates @foo with args & children correctly', function() { - expect(customGen.parse('div @foo(1,2,3) { a, b }')).toBe('
1,2,3
'); - expect(customGen.parse('\ - div\n\ - h1\n\ - @foo WOW\n\ - ')).toBe('

'); - expect(customGen.parse('\ - div\n\ - @foo\n\ - @foo\n\ - @foo(4) @foo\n\ - ')).toBe('
4
'); - }); - - }); - - }); - +describe('Directives', function() { + + describe('Custom Generator with directives', function() { + + var directives = {}; + + var customGen = new siml.Generator({ + directives: directives, + pretty: false + }); + + it('Throws error on undefined directives', function() { + expect(function() { + customGen.parse('a @foo'); + }).toThrow('SIML: Directive not resolvable: foo'); + }); + + describe('Custom @foo directive', function() { + + beforeEach(function() { + directives.foo = { + type: 'CONTENT', + make: function(name, children/*, args */) { + this.parentElement.htmlContent.push( + '' + [].slice.call(arguments, 2).join() + ); + if (children.length) { + this.parentElement.processChildren(children); + } + this.parentElement.htmlContent.push(''); + } + }; + }); + + afterEach(function() { + delete directives.foo; + }); + + it('Generates @foo with no args correctly', function() { + expect(customGen.parse('div @foo')).toBe('
'); + }); + + it('Generates @foo with args correctly', function() { + expect(customGen.parse('div @foo(123,"four", false)')).toBe('
123,four,false
'); + }); + + it('Generates @foo with args & children correctly', function() { + expect(customGen.parse('div @foo(1,2,3) { a, b }')).toBe('
1,2,3
'); + expect(customGen.parse('\ + div\n\ + h1\n\ + @foo WOW\n\ + ')).toBe('

'); + expect(customGen.parse('\ + div\n\ + @foo\n\ + @foo\n\ + @foo(4) @foo\n\ + ')).toBe('
4
'); + }); + + }); + + }); + }); \ No newline at end of file diff --git a/test/ErrorReportingSpec.js b/test/ErrorReportingSpec.js index 1118d1a..07865ae 100644 --- a/test/ErrorReportingSpec.js +++ b/test/ErrorReportingSpec.js @@ -1,42 +1,42 @@ -describe('Error Reporting', function() { - describe('When a syntax error occurs during parsing', function() { - it('Should throw the correct line and character number', function() { - -// TODO: IMPROVE ERROR REPORTING - /* - - expect(function() { - siml.parse('^'); - }).toThrow('SIML: Line 1, column 1: Expected AttributeName, Directive, Element or String but "^" found.'); - - expect(function() { - siml.parse('\ -abc {\n\ - ;\n\ -}\n\ - '); - }).toThrow('SIML: Line 1, column 5: Expected ":", ";", AttributeName, Directive, Element or String but "{" found.'); - - - expect(function() { - siml.parse('\ -abc {\n\ - // Just a comment\n\ - "a\n\ - multiline\n\ - string...\n\ - "\n\ - a { href: "foo" }\n\ - /**\n\ - * Another comment \n\ - /\n\ - a b c\n\ - #\n\ - div.foo#b "thing"\n\ -}\n\ - '); - }).toThrow('s');*/ - - }); - }); +describe('Error Reporting', function() { + describe('When a syntax error occurs during parsing', function() { + it('Should throw the correct line and character number', function() { + +// TODO: IMPROVE ERROR REPORTING + /* + + expect(function() { + siml.parse('^'); + }).toThrow('SIML: Line 1, column 1: Expected AttributeName, Directive, Element or String but "^" found.'); + + expect(function() { + siml.parse('\ +abc {\n\ + ;\n\ +}\n\ + '); + }).toThrow('SIML: Line 1, column 5: Expected ":", ";", AttributeName, Directive, Element or String but "{" found.'); + + + expect(function() { + siml.parse('\ +abc {\n\ + // Just a comment\n\ + "a\n\ + multiline\n\ + string...\n\ + "\n\ + a { href: "foo" }\n\ + /**\n\ + * Another comment \n\ + /\n\ + a b c\n\ + #\n\ + div.foo#b "thing"\n\ +}\n\ + '); + }).toThrow('s');*/ + + }); + }); }); \ No newline at end of file diff --git a/test/HTML5GeneratorSpec.js b/test/HTML5GeneratorSpec.js index 7c55f7c..99b8b19 100644 --- a/test/HTML5GeneratorSpec.js +++ b/test/HTML5GeneratorSpec.js @@ -1,39 +1,45 @@ -describe('HTML5 Parser: HTML Generation', function() { - describe('Example case', function() { - it('Parses correctly', function() { - expect(siml.html5.parse('\ - @doctype()\n\ - div\n\ - a\n\ - input:checkbox\n\ - input:datetime\n\ - input:radio\n\ - input:url\n\ - ', {pretty:false})).toBe([ - '', - '
', - '', - '', - '', - '', - '', - '
' - ].join('')); - }); - }); - describe('Quick tags + Single line parsing', function() { - it('Parses a simple doc from a single line', function() { - expect(siml.html5.parse('html (hd{meta[charset=utf-8]+title{"cool"}}bdy "Look ma, no hands!")',{pretty:false})).toBe([ - '', - '', - '', - 'cool', - '', - '', - 'Look ma, no hands!', - '', - '' - ].join('')); - }); - }); -}); +describe('HTML5 Parser: HTML Generation', function() { + describe('Example case', function() { + it('Parses correctly', function() { + expect(siml.html5.parse('\ + @doctype()\n\ + div\n\ + a\n\ + input:checkbox\n\ + input:datetime\n\ + input:radio\n\ + input:url\n\ + button:submit\n\ + button:reset\n\ + button:button\n\ + ', {pretty:false})).toBe([ + '', + '
', + '', + '', + '', + '', + '', + '', + '', + '', + '
' + ].join('')); + }); + }); + describe('Quick tags + Single line parsing', function() { + it('Parses a simple doc from a single line', function() { + expect(siml.html5.parse('html (hd{meta[charset=utf-8]+title{"cool"}}bdy "Look ma, no hands!")',{pretty:false})).toBe([ + '', + '', + '', + 'cool', + '', + '', + 'Look ma, no hands!', + '', + '' + ].join('')); + }); + }); +}); diff --git a/test/resources/angular-test.siml b/test/resources/angular-test.siml index 782178a..df2b4e0 100644 --- a/test/resources/angular-test.siml +++ b/test/resources/angular-test.siml @@ -1,31 +1,31 @@ -section#main:cloak - @show( todos.length ) - - input#toggle-all:checkbox - @model( allChecked ) - @click( markAll(allChecked) ) - label[for=toggle-all] 'Mark all as complete' - - ul#todo-list > li - @repeat( todo in todos | filter:statusFilter ) - @class({ - completed: todo.completed, - editing: todo == editedTodo - }) - - div.view - input.toggle:checkbox - @model( todo.completed ) - @change( todoCompleted(todo) ) - label - '{{todo.title}}' - @dblclick( editTodo(todo) ) - button.destroy - @click( removeTodo(todo) ) - - form - @submit( doneEditing(todo) ) - input.edit - @model( todo.title ) - @$todoBlur( doneEditing(todo) ) +section#main:cloak + @show( todos.length ) + + input#toggle-all:checkbox + @model( allChecked ) + @click( markAll(allChecked) ) + label[for=toggle-all] 'Mark all as complete' + + ul#todo-list > li + @repeat( todo in todos | filter:statusFilter ) + @class({ + completed: todo.completed, + editing: todo == editedTodo + }) + + div.view + input.toggle:checkbox + @model( todo.completed ) + @change( todoCompleted(todo) ) + label + '{{todo.title}}' + @dblclick( editTodo(todo) ) + button.destroy + @click( removeTodo(todo) ) + + form + @submit( doneEditing(todo) ) + input.edit + @model( todo.title ) + @$todoBlur( doneEditing(todo) ) @$todoFocus( todo == editedTodo ) \ No newline at end of file diff --git a/test/resources/buildParser.js b/test/resources/buildParser.js index b42333e..302ac42 100644 --- a/test/resources/buildParser.js +++ b/test/resources/buildParser.js @@ -1,13 +1,13 @@ -function buildParser(src) { - - var xhr = new XMLHttpRequest(); - xhr.open('GET', src + '?' + +new Date, false); - xhr.send(null); - var parserCode = xhr.responseText; - - siml.PARSER = PEG.buildParser(parserCode, { - cache: false, - trackLineAndColumn: true - }); - +function buildParser(src) { + + var xhr = new XMLHttpRequest(); + xhr.open('GET', src + '?' + +new Date, false); + xhr.send(null); + var parserCode = xhr.responseText; + + siml.PARSER = PEG.buildParser(parserCode, { + cache: false, + trackLineAndColumn: true + }); + } \ No newline at end of file diff --git a/test/resources/html-lab.html b/test/resources/html-lab.html index 5211284..f8336dd 100644 --- a/test/resources/html-lab.html +++ b/test/resources/html-lab.html @@ -1,47 +1,47 @@ - - - - - JH LAB - - - - - - - - - - - - - - - - + + + + + JH LAB + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/resources/lab.html b/test/resources/lab.html index a2c8b6d..822cf0b 100644 --- a/test/resources/lab.html +++ b/test/resources/lab.html @@ -1,39 +1,39 @@ - - - - - JH LAB - - - - - - - - - - - - - - - - + + + + + JH LAB + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/resources/live-parser.html b/test/resources/live-parser.html index 90bd2f5..81272d1 100644 --- a/test/resources/live-parser.html +++ b/test/resources/live-parser.html @@ -1,182 +1,182 @@ - - - - - SIML -- Try it out! - - - - - - -
-
-
- -
- - -html - head - meta - title - body - section - h1 'ok' - p ( - 'a'/'b' - ) - -
-
-

-		
-
- - - - - - - - - - - - + + + + + SIML -- Try it out! + + + + + + +
+
+
+ +
+ + +html + head + meta + title + body + section + h1 'ok' + p ( + 'a'/'b' + ) + +
+
+

+		
+
+ + + + + + + + + + + + \ No newline at end of file diff --git a/test/resources/specHelpers.js b/test/resources/specHelpers.js index 70a55de..f85b178 100644 --- a/test/resources/specHelpers.js +++ b/test/resources/specHelpers.js @@ -1,7 +1,7 @@ -beforeEach(function() { - this.addMatchers({ - toGenerate: function(expected) { - return siml.parse(this.actual, {pretty:false}) === expected; - } - }); +beforeEach(function() { + this.addMatchers({ + toGenerate: function(expected) { + return siml.parse(this.actual, {pretty:false}) === expected; + } + }); }); \ No newline at end of file