made with requirebin
Created
November 25, 2014 15:18
-
-
Save joshski/45de55a4ab4ff515b121 to your computer and use it in GitHub Desktop.
css-to-xpath example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cssToXPath = require('css-to-xpath'); | |
document.body.innerHTML = cssToXPath('p:not(:has(a.x))'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){},{}],2:[function(require,module,exports){(function(process){function normalizeArray(parts,allowAboveRoot){var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var splitPath=function(filename){return splitPathRe.exec(filename).slice(1)};exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start<arr.length;start++){if(arr[start]!=="")break}var end=arr.length-1;for(;end>=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i<length;i++){if(fromParts[i]!==toParts[i]){samePartsLength=i;break}}var outputParts=[];for(var i=samePartsLength;i<fromParts.length;i++){outputParts.push("..")}outputParts=outputParts.concat(toParts.slice(samePartsLength));return outputParts.join("/")};exports.sep="/";exports.delimiter=":";exports.dirname=function(path){var result=splitPath(path),root=result[0],dir=result[1];if(!root&&!dir){return"."}if(dir){dir=dir.substr(0,dir.length-1)}return root+dir};exports.basename=function(path,ext){var f=splitPath(path)[2];if(ext&&f.substr(-1*ext.length)===ext){f=f.substr(0,f.length-ext.length)}return f};exports.extname=function(path){return splitPath(path)[3]};function filter(xs,f){if(xs.filter)return xs.filter(f);var res=[];for(var i=0;i<xs.length;i++){if(f(xs[i],i,xs))res.push(xs[i])}return res}var substr="ab".substr(-1)==="b"?function(str,start,len){return str.substr(start,len)}:function(str,start,len){if(start<0)start=str.length+start;return str.substr(start,len)}}).call(this,require("_process"))},{_process:3}],3:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}if(canPost){var queue=[];window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],4:[function(require,module,exports){(function(){var self=this;var Renderer,Expression,extend;Renderer=require("./renderer");Expression=function(data){extend(this,data);return this};Expression.prototype.render=function(xpath,combinator){var self=this;return(new Renderer).render(self,xpath,combinator)};extend=function(o,d){var k;for(k in d){(function(k){o[k]=d[k]})(k)}return void 0};module.exports=Expression}).call(this)},{"./renderer":5}],5:[function(require,module,exports){(function(){var self=this;var xpathBuilder,Renderer;xpathBuilder=require("xpath-builder").dsl();Renderer=function(){return this};Renderer.prototype={render:function(node,xpath,combinator){var self=this;var fn;fn=self[node.type];if(!fn){throw new Error("No renderer for '"+node.type+"'")}return fn.call(self,node,xpath,combinator)},selector_list:function(node,xpath,combinator){var self=this;var x,i;x=self.render(node.selectors[0],xpath,combinator);for(i=1;i<node.selectors.length;++i){x=x.union(self.render(node.selectors[i],xpath,combinator))}return x},constraint_list:function(node,xpath,combinator){var self=this;return self.element(node,xpath,combinator)},element:function(node,xpath,combinator){var self=this;return self.applyConstraints(node,xpath[combinator].call(xpath,node.name||"*"))},combinator_selector:function(node,xpath,combinator){var self=this;var left;left=self.render(node.left,xpath,combinator);return self.render(node.right,left,node.combinator)},immediate_child:function(node,xpath){var self=this;return self.render(node.child,xpath,"child")},pseudo_func:function(node,xpath){var self=this;var fn;fn=self[node.func.name.replace(/-/g,"_")];if(fn){return fn.call(self,node,xpath)}else{throw new Error("Unsupported pseudo function :"+node.func.name+"()")}},pseudo_class:function(node,xpath){var self=this;var fn;fn=self[node.name.replace(/-/g,"_")];if(fn){return fn.call(self,node,xpath)}else{throw new Error("Unsupported pseudo class :"+node.name)}},has:function(node,xpath){var self=this;return self.render(node.func.args,xpathBuilder,"descendant")},not:function(node,xpath){var self=this;var firstChild,childType;firstChild=node.func.args.selectors[0];childType=firstChild.type;if(childType==="constraint_list"){return self.combineConstraints(firstChild,xpath).inverse()}else{return self.matchesSelectorList(node.func.args,xpath).inverse()}},nth_child:function(node,xpath){var self=this;return xpath.nthChild(Number(node.func.args))},first_child:function(node,xpath){var self=this;return xpath.firstChild()},last_child:function(node,xpath){var self=this;return xpath.lastChild()},nth_last_child:function(node,xpath){var self=this;return xpath.nthLastChild(Number(node.func.args))},only_child:function(node,xpath){var self=this;return xpath.onlyChild()},only_of_type:function(node,xpath){var self=this;return xpath.onlyOfType()},nth_of_type:function(node,xpath){var self=this;var type;type=node.func.args.type;if(type==="odd"){return xpath.nthOfTypeOdd()}else if(type==="even"){return xpath.nthOfTypeEven()}else if(type==="an"){return xpath.nthOfTypeMod(Number(node.func.args.a))}else if(type==="n_plus_b"){return xpath.nthOfTypeMod(1,Number(node.func.args.b))}else if(type==="an_plus_b"){return xpath.nthOfTypeMod(Number(node.func.args.a),Number(node.func.args.b))}else{return xpath.nthOfType(Number(node.func.args))}},nth_last_of_type:function(node,xpath){var self=this;var type;type=node.func.args.type;if(type==="odd"){return xpath.nthLastOfTypeOdd()}else if(type==="even"){return xpath.nthLastOfTypeEven()}else if(type==="an"){return xpath.nthLastOfTypeMod(Number(node.func.args.a))}else if(type==="n_plus_b"){return xpath.nthLastOfTypeMod(1,Number(node.func.args.b))}else if(type==="an_plus_b"){return xpath.nthLastOfTypeMod(Number(node.func.args.a),Number(node.func.args.b))}else{return xpath.nthLastOfType(Number(node.func.args))}},last_of_type:function(node,xpath){var self=this;return xpath.lastOfType()},empty:function(node,xpath){var self=this;return xpath.empty()},has_attribute:function(node,xpath){var self=this;return xpathBuilder.attr(node.name)},attribute_equals:function(node,xpath){var self=this;return xpathBuilder.attr(node.name).equals(node.value)},attribute_contains:function(node,xpath){var self=this;return xpathBuilder.attr(node.name).contains(node.value)},attribute_contains_word:function(node,xpath){var self=this;return xpath.concat(" ",xpathBuilder.attr(node.name).normalize()," ").contains(" "+node.value+" ")},attribute_contains_prefix:function(node){var self=this;return xpathBuilder.attr(node.name).startsWith(node.value).or(xpathBuilder.attr(node.name).startsWith(node.value+"-"))},attribute_starts_with:function(node,xpath){var self=this;return xpathBuilder.attr(node.name).startsWith(node.value)},attribute_ends_with:function(node){var self=this;return xpathBuilder.attr(node.name).endsWith(node.value)},"class":function(node){var self=this;return self.attribute_contains_word({name:"class",value:node.name},xpathBuilder)},id:function(node){var self=this;return xpathBuilder.attr("id").equals(node.name)},previous_sibling:function(node,xpath,combinator){var self=this;var left;left=self.render(node.left,xpath,combinator);return self.applyConstraints(node.right,left.axis("following-sibling",node.right.name))},adjacent_sibling:function(node,xpath,combinator){var self=this;var left;left=self.render(node.left,xpath,combinator);return self.applyConstraints(node.right,left.axis("following-sibling::*[1]/self",node.right.name))},first_of_type:function(node,xpath){var self=this;return xpath.firstOfType()},matchesSelectorList:function(node,xpath){var self=this;var condition,i;if(node.selectors.length>0){condition=self.matchesSelector(node.selectors[0],xpathBuilder);for(i=1;i<node.selectors.length;++i){condition=condition.or(self.matchesSelector(node.selectors[i],xpathBuilder))}return condition}else{return xpath}},matchesSelector:function(node,xpath){var self=this;return xpath.name().equals(node.name)},combineConstraints:function(node,xpath){var self=this;var condition,i;condition=self.render(node.constraints[0],xpath);for(i=1;i<node.constraints.length;++i){condition=condition.and(self.render(node.constraints[i],condition))}return condition},applyConstraints:function(node,xpath){var self=this;if(node.constraints.length>0){return xpath.where(self.combineConstraints(node,xpath))}else{return xpath}}};module.exports=Renderer}).call(this)},{"xpath-builder":8}],6:[function(require,module,exports){var parser=require("./parser").parser;parser.yy.create=function(data){return data};exports.parser=parser},{"./parser":7}],7:[function(require,module,exports){(function(process){var parser=function(){var parser={trace:function trace(){},yy:{},symbols_:{error:2,expressions:3,selector_list:4,EOF:5,comma:6,selector:7,",":8,S:9,combinator_selector:10,simple_selector:11,element:12,constraint_list:13,padded_child_combinator:14,padded_tilde:15,padded_plus:16,">":17,ident:18,"*":19,constraint:20,"class":21,hash:22,attrib:23,pseudo:24,".":25,"#":26,IDENT:27,n:28,"[":29,padded_ident:30,"]":31,"=":32,padded_ident_or_string:33,CONTAINS:34,DOES_NOT_CONTAIN:35,CONTAINS_WORD:36,CONTAINS_PREFIX:37,STARTS_WITH:38,ENDS_WITH:39,string:40,"~":41,"+":42,SINGLE_QUOTED_STRING:43,DOUBLE_QUOTED_STRING:44,":":45,func:46,ODD_ARGUMENT:47,EVEN_ARGUMENT:48,"(":49,func_arguments:50,")":51,INTEGER:52,an_plus_b:53,odd:54,even:55,negative_integer:56,signed_integer:57,positive_integer:58,unsigned_integer:59,"-":60,NEGATIVE_INTEGER:61,POSITIVE_INTEGER:62,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:",",9:"S",17:">",19:"*",25:".",26:"#",27:"IDENT",28:"n",29:"[",31:"]",32:"=",34:"CONTAINS",35:"DOES_NOT_CONTAIN",36:"CONTAINS_WORD",37:"CONTAINS_PREFIX",38:"STARTS_WITH",39:"ENDS_WITH",41:"~",42:"+",43:"SINGLE_QUOTED_STRING",44:"DOUBLE_QUOTED_STRING",45:":",47:"ODD_ARGUMENT",48:"EVEN_ARGUMENT",49:"(",51:")",52:"INTEGER",54:"odd",55:"even",60:"-",61:"NEGATIVE_INTEGER",62:"POSITIVE_INTEGER"},productions_:[0,[3,2],[4,3],[4,1],[6,1],[6,2],[7,1],[7,1],[11,2],[11,1],[11,1],[10,3],[10,3],[10,3],[10,3],[10,3],[10,2],[12,1],[12,1],[13,2],[13,1],[20,1],[20,1],[20,1],[20,1],[21,2],[22,2],[18,1],[18,1],[23,3],[23,5],[23,5],[23,5],[23,5],[23,5],[23,5],[23,5],[30,3],[30,2],[30,2],[30,1],[33,1],[33,3],[33,2],[33,2],[33,1],[14,3],[14,2],[14,2],[14,1],[15,3],[15,2],[15,2],[15,1],[16,3],[16,2],[16,2],[16,1],[40,1],[40,1],[24,2],[24,2],[46,2],[46,2],[46,4],[46,4],[46,3],[50,1],[50,1],[53,1],[53,1],[53,3],[53,3],[53,3],[53,3],[53,2],[53,2],[53,2],[57,1],[57,1],[56,1],[58,1],[59,1]],performAction:function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$){var $0=$$.length-1;switch(yystate){case 1:return $$[$0-1];break;case 2:$$[$0-2].selectors.push($$[$0]);this.$=$$[$0-2];break;case 3:this.$=yy.create({type:"selector_list",selectors:[$$[$0]]});break;case 8:$$[$0-1].constraints=$$[$0].constraints;this.$=$$[$0-1];break;case 10:this.$=yy.create({type:"constraint_list",constraints:$$[$0].constraints});break;case 11:this.$=yy.create({type:"combinator_selector",left:$$[$0-2],right:$$[$0],combinator:"child"});break;case 12:this.$=yy.create({type:"combinator_selector",left:$$[$0-2],right:$$[$0],combinator:"descendant"});break;case 13:this.$=yy.create({type:"previous_sibling",left:$$[$0-2],right:$$[$0]});break;case 14:this.$=yy.create({type:"adjacent_sibling",left:$$[$0-2],right:$$[$0]});break;case 15:this.$=yy.create({type:"immediate_child",child:$$[$0],combinator:"child"});break;case 16:this.$=yy.create({type:"immediate_child",child:$$[$0],combinator:"child"});break;case 17:this.$=yy.create({type:"element",name:$$[$0],constraints:[]});break;case 18:this.$=yy.create({type:"element",name:$$[$0],constraints:[]});break;case 19:$$[$0-1].constraints.push($$[$0]);this.$=$$[$0-1];break;case 20:this.$=yy.create({type:"constraint_list",constraints:[$$[$0]]});break;case 25:this.$={type:"class",name:$$[$0]};break;case 26:this.$={type:"id",name:$$[$0]};break;case 29:this.$=yy.create({type:"has_attribute",name:$$[$0-1]});break;case 30:this.$=yy.create({type:"attribute_equals",name:$$[$0-3],value:$$[$0-1]});break;case 31:this.$=yy.create({type:"attribute_contains",name:$$[$0-3],value:$$[$0-1]});break;case 32:this.$=yy.create({type:"attribute_does_not_contain",name:$$[$0-3],value:$$[$0-1]});break;case 33:this.$=yy.create({type:"attribute_contains_word",name:$$[$0-3],value:$$[$0-1]});break;case 34:this.$=yy.create({type:"attribute_contains_prefix",name:$$[$0-3],value:$$[$0-1]});break;case 35:this.$=yy.create({type:"attribute_starts_with",name:$$[$0-3],value:$$[$0-1]});break;case 36:this.$=yy.create({type:"attribute_ends_with",name:$$[$0-3],value:$$[$0-1]});break;case 37:this.$=$$[$0-1];break;case 38:this.$=$$[$0];break;case 39:this.$=$$[$0-1];break;case 40:this.$=$$[$0];break;case 42:this.$=$$[$0-2];break;case 43:this.$=$$[$0];break;case 44:this.$=$$[$0-1];break;case 45:this.$=$$[$0];break;case 58:this.$=$$[$0].substr(1,$$[$0].length-2);break;case 59:this.$=$$[$0].substr(1,$$[$0].length-2);break;case 60:this.$=yy.create({type:"pseudo_func",func:$$[$0]});break;case 61:this.$=yy.create({type:"pseudo_class",name:$$[$0]});break;case 62:this.$={type:"function",name:$$[$0-1],args:{type:"odd"}};break;case 63:this.$={type:"function",name:$$[$0-1],args:{type:"even"}};break;case 64:this.$={type:"function",name:$$[$0-3],args:$$[$0-1]};break;case 65:this.$={type:"function",name:$$[$0-3],args:$$[$0-1]};break;case 66:this.$={type:"function",name:$$[$0-2]};break;case 69:this.$={type:"odd"};break;case 70:this.$={type:"even"};break;case 71:this.$={type:"an_plus_b",a:$$[$0-2],b:$$[$0]};break;case 72:this.$={type:"an_plus_b",a:$$[$0-2],b:$$[$0]};break;case 73:this.$={type:"an_plus_b",a:$$[$0-2],b:$$[$0]};break;case 74:this.$={type:"an_plus_b",a:-1,b:$$[$0]};break;case 75:this.$={type:"n_plus_b",b:$$[$0]};break;case 76:this.$={type:"an",a:$$[$0-1]};break;case 77:this.$={type:"an",a:$$[$0-1]};break;case 80:this.$=Number($$[$0]);break;case 81:this.$=Number($$[$0]);break;case 82:this.$=Number($$[$0]);break}},table:[{3:1,4:2,7:3,10:4,11:5,12:7,13:8,17:[1,6],18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{1:[3]},{5:[1,22],6:23,8:[1,24]},{5:[2,3],8:[2,3],9:[1,26],14:25,15:27,16:28,17:[1,29],41:[1,30],42:[1,31],51:[2,3]},{5:[2,6],8:[2,6],9:[2,6],17:[2,6],41:[2,6],42:[2,6],51:[2,6]},{5:[2,7],8:[2,7],9:[2,7],17:[2,7],41:[2,7],42:[2,7],51:[2,7]},{9:[1,32],11:33,12:7,13:8,18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{5:[2,9],8:[2,9],9:[2,9],13:34,17:[2,9],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],29:[1,20],41:[2,9],42:[2,9],45:[1,21],51:[2,9]},{5:[2,10],8:[2,10],9:[2,10],17:[2,10],20:35,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],29:[1,20],41:[2,10],42:[2,10],45:[1,21],51:[2,10]},{5:[2,17],8:[2,17],9:[2,17],17:[2,17],25:[2,17],26:[2,17],29:[2,17],41:[2,17],42:[2,17],45:[2,17],51:[2,17]},{5:[2,18],8:[2,18],9:[2,18],17:[2,18],25:[2,18],26:[2,18],29:[2,18],41:[2,18],42:[2,18],45:[2,18],51:[2,18]},{5:[2,20],8:[2,20],9:[2,20],17:[2,20],25:[2,20],26:[2,20],29:[2,20],41:[2,20],42:[2,20],45:[2,20],51:[2,20]},{5:[2,27],8:[2,27],9:[2,27],17:[2,27],25:[2,27],26:[2,27],29:[2,27],31:[2,27],32:[2,27],34:[2,27],35:[2,27],36:[2,27],37:[2,27],38:[2,27],39:[2,27],41:[2,27],42:[2,27],45:[2,27],47:[2,27],48:[2,27],49:[2,27],51:[2,27]},{5:[2,28],8:[2,28],9:[2,28],17:[2,28],25:[2,28],26:[2,28],29:[2,28],31:[2,28],32:[2,28],34:[2,28],35:[2,28],36:[2,28],37:[2,28],38:[2,28],39:[2,28],41:[2,28],42:[2,28],45:[2,28],47:[2,28],48:[2,28],49:[2,28],51:[2,28]},{5:[2,21],8:[2,21],9:[2,21],17:[2,21],25:[2,21],26:[2,21],29:[2,21],41:[2,21],42:[2,21],45:[2,21],51:[2,21]},{5:[2,22],8:[2,22],9:[2,22],17:[2,22],25:[2,22],26:[2,22],29:[2,22],41:[2,22],42:[2,22],45:[2,22],51:[2,22]},{5:[2,23],8:[2,23],9:[2,23],17:[2,23],25:[2,23],26:[2,23],29:[2,23],41:[2,23],42:[2,23],45:[2,23],51:[2,23]},{5:[2,24],8:[2,24],9:[2,24],17:[2,24],25:[2,24],26:[2,24],29:[2,24],41:[2,24],42:[2,24],45:[2,24],51:[2,24]},{18:36,27:[1,12],28:[1,13]},{18:37,27:[1,12],28:[1,13]},{9:[1,39],18:40,27:[1,12],28:[1,13],30:38},{18:42,27:[1,12],28:[1,13],46:41},{1:[2,1]},{7:43,10:4,11:5,12:7,13:8,17:[1,6],18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{9:[1,44],17:[2,4],19:[2,4],25:[2,4],26:[2,4],27:[2,4],28:[2,4],29:[2,4],45:[2,4]},{11:45,12:7,13:8,18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{11:46,12:7,13:8,17:[1,47],18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],41:[1,48],42:[1,49],45:[1,21]},{11:50,12:7,13:8,18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{11:51,12:7,13:8,18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{9:[1,52],19:[2,49],25:[2,49],26:[2,49],27:[2,49],28:[2,49],29:[2,49],45:[2,49]},{9:[1,53],19:[2,53],25:[2,53],26:[2,53],27:[2,53],28:[2,53],29:[2,53],45:[2,53]},{9:[1,54],19:[2,57],25:[2,57],26:[2,57],27:[2,57],28:[2,57],29:[2,57],45:[2,57]},{11:55,12:7,13:8,18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,13],29:[1,20],45:[1,21]},{5:[2,16],8:[2,16],9:[2,16],17:[2,16],41:[2,16],42:[2,16],51:[2,16]},{5:[2,8],8:[2,8],9:[2,8],17:[2,8],20:35,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],29:[1,20],41:[2,8],42:[2,8],45:[1,21],51:[2,8]},{5:[2,19],8:[2,19],9:[2,19],17:[2,19],25:[2,19],26:[2,19],29:[2,19],41:[2,19],42:[2,19],45:[2,19],51:[2,19]},{5:[2,25],8:[2,25],9:[2,25],17:[2,25],25:[2,25],26:[2,25],29:[2,25],41:[2,25],42:[2,25],45:[2,25],51:[2,25]},{5:[2,26],8:[2,26],9:[2,26],17:[2,26],25:[2,26],26:[2,26],29:[2,26],41:[2,26],42:[2,26],45:[2,26],51:[2,26]},{31:[1,56],32:[1,57],34:[1,58],35:[1,59],36:[1,60],37:[1,61],38:[1,62],39:[1,63]},{18:64,27:[1,12],28:[1,13]},{9:[1,65],31:[2,40],32:[2,40],34:[2,40],35:[2,40],36:[2,40],37:[2,40],38:[2,40],39:[2,40]},{5:[2,60],8:[2,60],9:[2,60],17:[2,60],25:[2,60],26:[2,60],29:[2,60],41:[2,60],42:[2,60],45:[2,60],51:[2,60]},{5:[2,61],8:[2,61],9:[2,61],17:[2,61],25:[2,61],26:[2,61],29:[2,61],41:[2,61],42:[2,61],45:[2,61],47:[1,66],48:[1,67],49:[1,68],51:[2,61]},{5:[2,2],8:[2,2],9:[1,26],14:25,15:27,16:28,17:[1,29],41:[1,30],42:[1,31],51:[2,2]},{17:[2,5],19:[2,5],25:[2,5],26:[2,5],27:[2,5],28:[2,5],29:[2,5],45:[2,5]},{5:[2,11],8:[2,11],9:[2,11],17:[2,11],41:[2,11],42:[2,11],51:[2,11]},{5:[2,12],8:[2,12],9:[2,12],17:[2,12],41:[2,12],42:[2,12],51:[2,12]},{9:[1,69],19:[2,47],25:[2,47],26:[2,47],27:[2,47],28:[2,47],29:[2,47],45:[2,47]},{9:[1,70],19:[2,51],25:[2,51],26:[2,51],27:[2,51],28:[2,51],29:[2,51],45:[2,51]},{9:[1,71],19:[2,55],25:[2,55],26:[2,55],27:[2,55],28:[2,55],29:[2,55],45:[2,55]},{5:[2,13],8:[2,13],9:[2,13],17:[2,13],41:[2,13],42:[2,13],51:[2,13]},{5:[2,14],8:[2,14],9:[2,14],17:[2,14],41:[2,14],42:[2,14],51:[2,14]},{19:[2,48],25:[2,48],26:[2,48],27:[2,48],28:[2,48],29:[2,48],45:[2,48]},{19:[2,52],25:[2,52],26:[2,52],27:[2,52],28:[2,52],29:[2,52],45:[2,52]},{19:[2,56],25:[2,56],26:[2,56],27:[2,56],28:[2,56],29:[2,56],45:[2,56]},{5:[2,15],8:[2,15],9:[2,15],17:[2,15],41:[2,15],42:[2,15],51:[2,15]},{5:[2,29],8:[2,29],9:[2,29],17:[2,29],25:[2,29],26:[2,29],29:[2,29],41:[2,29],42:[2,29],45:[2,29],51:[2,29]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:72,40:75,43:[1,76],44:[1,77]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:78,40:75,43:[1,76],44:[1,77]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:79,40:75,43:[1,76],44:[1,77]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:80,40:75,43:[1,76],44:[1,77]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:81,40:75,43:[1,76],44:[1,77]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:82,40:75,43:[1,76],44:[1,77]},{9:[1,74],18:40,27:[1,12],28:[1,13],30:73,33:83,40:75,43:[1,76],44:[1,77]},{9:[1,84],31:[2,38],32:[2,38],34:[2,38],35:[2,38],36:[2,38],37:[2,38],38:[2,38],39:[2,38]},{31:[2,39],32:[2,39],34:[2,39],35:[2,39],36:[2,39],37:[2,39],38:[2,39],39:[2,39]},{5:[2,62],8:[2,62],9:[2,62],17:[2,62],25:[2,62],26:[2,62],29:[2,62],41:[2,62],42:[2,62],45:[2,62],51:[2,62]},{5:[2,63],8:[2,63],9:[2,63],17:[2,63],25:[2,63],26:[2,63],29:[2,63],41:[2,63],42:[2,63],45:[2,63],51:[2,63]},{4:88,7:3,10:4,11:5,12:7,13:8,17:[1,6],18:9,19:[1,10],20:11,21:14,22:15,23:16,24:17,25:[1,18],26:[1,19],27:[1,12],28:[1,96],29:[1,20],45:[1,21],50:85,51:[1,87],52:[1,86],53:89,54:[1,90],55:[1,91],56:92,58:93,59:94,60:[1,95],61:[1,97],62:[1,98]},{19:[2,46],25:[2,46],26:[2,46],27:[2,46],28:[2,46],29:[2,46],45:[2,46]},{19:[2,50],25:[2,50],26:[2,50],27:[2,50],28:[2,50],29:[2,50],45:[2,50]},{19:[2,54],25:[2,54],26:[2,54],27:[2,54],28:[2,54],29:[2,54],45:[2,54]},{31:[1,99]},{31:[2,41]},{18:64,27:[1,12],28:[1,13],40:100,43:[1,76],44:[1,77]},{9:[1,101],31:[2,45]},{9:[2,58],31:[2,58]},{9:[2,59],31:[2,59]},{31:[1,102]},{31:[1,103]},{31:[1,104]},{31:[1,105]},{31:[1,106]},{31:[1,107]},{31:[2,37],32:[2,37],34:[2,37],35:[2,37],36:[2,37],37:[2,37],38:[2,37],39:[2,37]},{51:[1,108]},{28:[2,82],51:[1,109]},{5:[2,66],8:[2,66],9:[2,66],17:[2,66],25:[2,66],26:[2,66],29:[2,66],41:[2,66],42:[2,66],45:[2,66],51:[2,66]},{6:23,8:[1,24],51:[2,67]},{51:[2,68]},{51:[2,69]},{51:[2,70]},{28:[1,110]},{28:[1,111]},{28:[1,112]},{28:[1,113]},{8:[2,28],9:[2,28],17:[2,28],25:[2,28],26:[2,28],29:[2,28],41:[2,28],42:[2,28],45:[2,28],51:[2,28],56:116,57:114,58:115,61:[1,97],62:[1,98]},{28:[2,80],51:[2,80]},{28:[2,81],51:[2,81]},{5:[2,30],8:[2,30],9:[2,30],17:[2,30],25:[2,30],26:[2,30],29:[2,30],41:[2,30],42:[2,30],45:[2,30],51:[2,30]},{9:[1,117],31:[2,43]},{31:[2,44]},{5:[2,31],8:[2,31],9:[2,31],17:[2,31],25:[2,31],26:[2,31],29:[2,31],41:[2,31],42:[2,31],45:[2,31],51:[2,31]},{5:[2,32],8:[2,32],9:[2,32],17:[2,32],25:[2,32],26:[2,32],29:[2,32],41:[2,32],42:[2,32],45:[2,32],51:[2,32]},{5:[2,33],8:[2,33],9:[2,33],17:[2,33],25:[2,33],26:[2,33],29:[2,33],41:[2,33],42:[2,33],45:[2,33],51:[2,33]},{5:[2,34],8:[2,34],9:[2,34],17:[2,34],25:[2,34],26:[2,34],29:[2,34],41:[2,34],42:[2,34],45:[2,34],51:[2,34]},{5:[2,35],8:[2,35],9:[2,35],17:[2,35],25:[2,35],26:[2,35],29:[2,35],41:[2,35],42:[2,35],45:[2,35],51:[2,35]},{5:[2,36],8:[2,36],9:[2,36],17:[2,36],25:[2,36],26:[2,36],29:[2,36],41:[2,36],42:[2,36],45:[2,36],51:[2,36]},{5:[2,64],8:[2,64],9:[2,64],17:[2,64],25:[2,64],26:[2,64],29:[2,64],41:[2,64],42:[2,64],45:[2,64],51:[2,64]},{5:[2,65],8:[2,65],9:[2,65],17:[2,65],25:[2,65],26:[2,65],29:[2,65],41:[2,65],42:[2,65],45:[2,65],51:[2,65]},{51:[2,76],56:116,57:118,58:115,61:[1,97],62:[1,98]},{56:116,57:119,58:115,61:[1,97],62:[1,98]},{51:[2,77],56:116,57:120,58:115,61:[1,97],62:[1,98]},{56:116,57:121,58:115,61:[1,97],62:[1,98]},{51:[2,75]},{51:[2,78]},{51:[2,79]},{31:[2,42]},{51:[2,71]},{51:[2,72]},{51:[2,73]},{51:[2,74]}],defaultActions:{22:[2,1],73:[2,41],89:[2,68],90:[2,69],91:[2,70],101:[2,44],114:[2,75],115:[2,78],116:[2,79],117:[2,42],118:[2,71],119:[2,72],120:[2,73],121:[2,74]},parseError:function parseError(str,hash){if(hash.recoverable){this.trace(str)}else{throw new Error(str)}},parse:function parse(input){var self=this,stack=[0],vstack=[null],lstack=[],table=this.table,yytext="",yylineno=0,yyleng=0,recovering=0,TERROR=2,EOF=1;var args=lstack.slice.call(arguments,1);this.lexer.setInput(input);this.lexer.yy=this.yy;this.yy.lexer=this.lexer;this.yy.parser=this;if(typeof this.lexer.yylloc=="undefined"){this.lexer.yylloc={}}var yyloc=this.lexer.yylloc;lstack.push(yyloc);var ranges=this.lexer.options&&this.lexer.options.ranges;if(typeof this.yy.parseError==="function"){this.parseError=this.yy.parseError}else{this.parseError=Object.getPrototypeOf(this).parseError}function popStack(n){stack.length=stack.length-2*n;vstack.length=vstack.length-n;lstack.length=lstack.length-n}function lex(){var token;token=self.lexer.lex()||EOF;if(typeof token!=="number"){token=self.symbols_[token]||token}return token}var symbol,preErrorSymbol,state,action,a,r,yyval={},p,len,newState,expected;while(true){state=stack[stack.length-1];if(this.defaultActions[state]){action=this.defaultActions[state]}else{if(symbol===null||typeof symbol=="undefined"){symbol=lex()}action=table[state]&&table[state][symbol]}if(typeof action==="undefined"||!action.length||!action[0]){var errStr="";expected=[];for(p in table[state]){if(this.terminals_[p]&&p>TERROR){expected.push("'"+this.terminals_[p]+"'")}}if(this.lexer.showPosition){errStr="Parse error on line "+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(", ")+", got '"+(this.terminals_[symbol]||symbol)+"'"}else{errStr="Parse error on line "+(yylineno+1)+": Unexpected "+(symbol==EOF?"end of input":"'"+(this.terminals_[symbol]||symbol)+"'")}this.parseError(errStr,{text:this.lexer.match,token:this.terminals_[symbol]||symbol,line:this.lexer.yylineno,loc:yyloc,expected:expected})}if(action[0]instanceof Array&&action.length>1){throw new Error("Parse Error: multiple actions possible at state: "+state+", token: "+symbol)}switch(action[0]){case 1:stack.push(symbol);vstack.push(this.lexer.yytext);lstack.push(this.lexer.yylloc);stack.push(action[1]);symbol=null;if(!preErrorSymbol){yyleng=this.lexer.yyleng;yytext=this.lexer.yytext;yylineno=this.lexer.yylineno;yyloc=this.lexer.yylloc;if(recovering>0){recovering--}}else{symbol=preErrorSymbol;preErrorSymbol=null}break;case 2:len=this.productions_[action[1]][1];yyval.$=vstack[vstack.length-len];yyval._$={first_line:lstack[lstack.length-(len||1)].first_line,last_line:lstack[lstack.length-1].last_line,first_column:lstack[lstack.length-(len||1)].first_column,last_column:lstack[lstack.length-1].last_column};if(ranges){yyval._$.range=[lstack[lstack.length-(len||1)].range[0],lstack[lstack.length-1].range[1]]}r=this.performAction.apply(yyval,[yytext,yyleng,yylineno,this.yy,action[1],vstack,lstack].concat(args));if(typeof r!=="undefined"){return r}if(len){stack=stack.slice(0,-1*len*2);vstack=vstack.slice(0,-1*len);lstack=lstack.slice(0,-1*len)}stack.push(this.productions_[action[1]][0]);vstack.push(yyval.$);lstack.push(yyval._$);newState=table[stack[stack.length-2]][stack[stack.length-1]];stack.push(newState);break;case 3:return true}}return true}};var lexer=function(){var lexer={EOF:1,parseError:function parseError(str,hash){if(this.yy.parser){this.yy.parser.parseError(str,hash)}else{throw new Error(str)}},setInput:function(input){this._input=input;this._more=this._backtrack=this.done=false;this.yylineno=this.yyleng=0;this.yytext=this.matched=this.match="";this.conditionStack=["INITIAL"];this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0};if(this.options.ranges){this.yylloc.range=[0,0]}this.offset=0;return this},input:function(){var ch=this._input[0];this.yytext+=ch;this.yyleng++;this.offset++;this.match+=ch;this.matched+=ch;var lines=ch.match(/(?:\r\n?|\n).*/g);if(lines){this.yylineno++;this.yylloc.last_line++}else{this.yylloc.last_column++}if(this.options.ranges){this.yylloc.range[1]++}this._input=this._input.slice(1);return ch},unput:function(ch){var len=ch.length;var lines=ch.split(/(?:\r\n?|\n)/g);this._input=ch+this._input;this.yytext=this.yytext.substr(0,this.yytext.length-len-1);this.offset-=len;var oldLines=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1);this.matched=this.matched.substr(0,this.matched.length-1);if(lines.length-1){this.yylineno-=lines.length-1}var r=this.yylloc.range;this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:lines?(lines.length===oldLines.length?this.yylloc.first_column:0)+oldLines[oldLines.length-lines.length].length-lines[0].length:this.yylloc.first_column-len};if(this.options.ranges){this.yylloc.range=[r[0],r[0]+this.yyleng-len]}this.yyleng=this.yytext.length;return this},more:function(){this._more=true;return this},reject:function(){if(this.options.backtrack_lexer){this._backtrack=true}else{return this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})}return this},less:function(n){this.unput(this.match.slice(n))},pastInput:function(){var past=this.matched.substr(0,this.matched.length-this.match.length);return(past.length>20?"...":"")+past.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var next=this.match;if(next.length<20){next+=this._input.substr(0,20-next.length)}return(next.substr(0,20)+(next.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var pre=this.pastInput();var c=new Array(pre.length+1).join("-");return pre+this.upcomingInput()+"\n"+c+"^"},test_match:function(match,indexed_rule){var token,lines,backup;if(this.options.backtrack_lexer){backup={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done};if(this.options.ranges){backup.yylloc.range=this.yylloc.range.slice(0)}}lines=match[0].match(/(?:\r\n?|\n).*/g);if(lines){this.yylineno+=lines.length}this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:lines?lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+match[0].length}; | |
this.yytext+=match[0];this.match+=match[0];this.matches=match;this.yyleng=this.yytext.length;if(this.options.ranges){this.yylloc.range=[this.offset,this.offset+=this.yyleng]}this._more=false;this._backtrack=false;this._input=this._input.slice(match[0].length);this.matched+=match[0];token=this.performAction.call(this,this.yy,this,indexed_rule,this.conditionStack[this.conditionStack.length-1]);if(this.done&&this._input){this.done=false}if(token){return token}else if(this._backtrack){for(var k in backup){this[k]=backup[k]}return false}return false},next:function(){if(this.done){return this.EOF}if(!this._input){this.done=true}var token,match,tempMatch,index;if(!this._more){this.yytext="";this.match=""}var rules=this._currentRules();for(var i=0;i<rules.length;i++){tempMatch=this._input.match(this.rules[rules[i]]);if(tempMatch&&(!match||tempMatch[0].length>match[0].length)){match=tempMatch;index=i;if(this.options.backtrack_lexer){token=this.test_match(tempMatch,rules[i]);if(token!==false){return token}else if(this._backtrack){match=false;continue}else{return false}}else if(!this.options.flex){break}}}if(match){token=this.test_match(match,rules[index]);if(token!==false){return token}return false}if(this._input===""){return this.EOF}else{return this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})}},lex:function lex(){var r=this.next();if(r){return r}else{return this.lex()}},begin:function begin(condition){this.conditionStack.push(condition)},popState:function popState(){var n=this.conditionStack.length-1;if(n>0){return this.conditionStack.pop()}else{return this.conditionStack[0]}},_currentRules:function _currentRules(){if(this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules}else{return this.conditions["INITIAL"].rules}},topState:function topState(n){n=this.conditionStack.length-1-Math.abs(n||0);if(n>=0){return this.conditionStack[n]}else{return"INITIAL"}},pushState:function pushState(condition){this.begin(condition)},stateStackSize:function stateStackSize(){return this.conditionStack.length},options:{},performAction:function anonymous(yy,yy_,$avoiding_name_collisions,YY_START){var YYSTATE=YY_START;switch($avoiding_name_collisions){case 0:return 28;break;case 1:return 27;break;case 2:return 5;break;case 3:return 36;break;case 4:return 34;break;case 5:return 37;break;case 6:return 35;break;case 7:return 38;break;case 8:return 39;break;case 9:return 43;break;case 10:return 44;break;case 11:return 62;break;case 12:return 61;break;case 13:return 52;break;case 14:return 47;break;case 15:return 48;break;case 16:return 26;break;case 17:return 8;break;case 18:return 25;break;case 19:return 29;break;case 20:return 31;break;case 21:return 32;break;case 22:return 45;break;case 23:return 49;break;case 24:return 51;break;case 25:return 17;break;case 26:return"'";break;case 27:return 19;break;case 28:return 41;break;case 29:return 42;break;case 30:return 60;break;case 31:return 9;break}},rules:[/^(?:n\b)/,/^(?:[_a-zA-Z][_a-zA-Z0-9-]*)/,/^(?:$)/,/^(?:~=)/,/^(?:\*=)/,/^(?:\|=)/,/^(?:!=)/,/^(?:\^=)/,/^(?:\$=)/,/^(?:"[^\n\r\f\\"]*")/,/^(?:'[^\n\r\f\\']*')/,/^(?:\+\d+)/,/^(?:-\d+)/,/^(?:\d+)/,/^(?:\(odd\))/,/^(?:\(even\))/,/^(?:#)/,/^(?:,)/,/^(?:\.)/,/^(?:\[)/,/^(?:\])/,/^(?:=)/,/^(?::)/,/^(?:\()/,/^(?:\))/,/^(?:>)/,/^(?:')/,/^(?:\*)/,/^(?:~)/,/^(?:\+)/,/^(?:-)/,/^(?:\s+)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],inclusive:true}}};return lexer}();parser.lexer=lexer;function Parser(){this.yy={}}Parser.prototype=parser;parser.Parser=Parser;return new Parser}();if(typeof require!=="undefined"&&typeof exports!=="undefined"){exports.parser=parser;exports.Parser=parser.Parser;exports.parse=function(){return parser.parse.apply(parser,arguments)};exports.main=function commonjsMain(args){if(!args[1]){console.log("Usage: "+args[0]+" FILE");process.exit(1)}var source=require("fs").readFileSync(require("path").normalize(args[1]),"utf8");return exports.parser.parse(source)};if(typeof module!=="undefined"&&require.main===module){exports.main(process.argv.slice(1))}}}).call(this,require("_process"))},{_process:3,fs:1,path:2}],8:[function(require,module,exports){(function(){var self=this;var expression,Literal,topLevelMethods,expressionLevelMethods,literals,TopLevel,ExpressionLevel,method,Expression,Union;expression=require("./expression");Literal=require("./literal").Literal;topLevelMethods={current:function(){var self=this;return new Expression("thisNode")},name:function(){var self=this;return new Expression("nodeName",self.current())},descendant:function(){var self=this;var elementNames=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("descendant",self.current(),literals(elementNames))},child:function(){var self=this;var elementNames=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("child",self.current(),literals(elementNames))},axis:function(name,tagName){var self=this;return new Expression("axis",self.current(),new Literal(name),new Literal(tagName||"*"))},nextSibling:function(){var self=this;var names=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("nextSibling",self.current(),literals(names))},previousSibling:function(){var self=this;var names=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("previousSibling",self.current(),literals(names))},anywhere:function(){var self=this;var names=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("anywhere",literals(names))},attr:function(name){var self=this;return new Expression("attribute",self.current(),new Literal(name))},contains:function(expression){var self=this;return new Expression("contains",self.current(),expression)},startsWith:function(expression){var self=this;return new Expression("startsWith",self.current(),expression)},endsWith:function(expression){var self=this;return new Expression("endsWith",self.current(),expression)},text:function(){var self=this;return new Expression("text",self.current())},string:function(){var self=this;return new Expression("stringFunction",self.current())},substring:function(expressionA,expressionB){var self=this;var expressions;expressions=[expressionA];if(expressionB){expressions.push(expressionB)}return new Expression("substringFunction",self.current(),expressions)},stringLength:function(){var self=this;return new Expression("stringLengthFunction",self.current())},literal:function(string){var self=this;return new Literal(string)},concat:function(){var self=this;var expressions=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("concatFunction",expressions)},nthChild:function(n){var self=this;return new Expression("nthChild",n)},nthLastChild:function(n){var self=this;return new Expression("nthLastChild",n)},firstChild:function(){var self=this;return new Expression("firstChild")},lastChild:function(){var self=this;return new Expression("lastChild")},onlyChild:function(){var self=this;return new Expression("onlyChild")},onlyOfType:function(){var self=this;return new Expression("onlyOfType")},firstOfType:function(){var self=this;return new Expression("nthOfType",1)},lastOfType:function(){var self=this;return new Expression("lastOfType")},nthOfType:function(n){var self=this;return new Expression("nthOfType",n)},nthLastOfType:function(n){var self=this;return new Expression("nthLastOfType",n)},nthOfTypeMod:function(m,n){var self=this;return new Expression("nthOfTypeMod",m,n||0)},nthOfTypeOdd:function(){var self=this;return new Expression("nthOfTypeOdd")},nthOfTypeEven:function(){var self=this;return new Expression("nthOfTypeEven")},nthLastOfTypeMod:function(m,n){var self=this;return new Expression("nthLastOfTypeMod",m,n||0)},nthLastOfTypeOdd:function(){var self=this;return new Expression("nthLastOfTypeOdd")},nthLastOfTypeEven:function(){var self=this;return new Expression("nthLastOfTypeEven")},empty:function(){var self=this;return new Expression("empty")}};expressionLevelMethods={where:function(expression){var self=this;return new Expression("where",self.current(),expression)},oneOf:function(){var self=this;var expressions=Array.prototype.slice.call(arguments,0,arguments.length);return new Expression("oneOf",self.current(),expressions)},equals:function(expression){var self=this;return new Expression("equality",self.current(),expression)},is:function(expression){var self=this;return new Expression("is",self.current(),expression)},or:function(expression){var self=this;return new Expression("or",self.current(),expression)},and:function(expression){var self=this;return new Expression("and",self.current(),expression)},union:function(){var self=this;var expressions=Array.prototype.slice.call(arguments,0,arguments.length);return new Union([self].concat(expressions))},inverse:function(){var self=this;return new Expression("inverse",self.current())},stringLiteral:function(){var self=this;return new Expression("stringLiteral",self)},normalize:function(){var self=this;return new Expression("normalizedSpace",self.current())},n:function(){var self=this;return self.normalize()},add:function(number){var self=this;return new Expression("addition",self.current(),number)},subtract:function(number){var self=this;return new Expression("subtraction",self.current(),number)},count:function(){var self=this;return new Expression("countFunction",self.current())}};literals=function(items){return items.map(function(item){return new Literal(item)})};TopLevel=function(){return this};TopLevel.prototype=topLevelMethods;ExpressionLevel=function(){return this};ExpressionLevel.prototype=new TopLevel;for(method in expressionLevelMethods){(function(method){ExpressionLevel.prototype[method]=expressionLevelMethods[method]})(method)}Expression=expression.createExpression(ExpressionLevel.prototype);Union=function(expressions){this.expression="union";this.args=expressions;return this};Union.prototype=Expression.prototype;exports.dsl=function(){var self=this;return new TopLevel}}).call(this)},{"./expression":9,"./literal":10}],9:[function(require,module,exports){(function(){var self=this;var Renderer,createExpression;Renderer=require("./renderer").Renderer;createExpression=function(prototype){var Expression;Expression=function(expression){var args=Array.prototype.slice.call(arguments,1,arguments.length);this.expression=expression;this.args=args;return this};Expression.prototype=prototype;Expression.prototype.isExpression=true;Expression.prototype.toXPath=function(type){var self=this;return Renderer.render(self,type)};Expression.prototype.toString=function(){var self=this;return self.toXPath()};Expression.prototype.inspect=function(){var self=this;return self.toXPath()};Expression.prototype.current=function(){var self=this;return self};return Expression};exports.createExpression=createExpression}).call(this)},{"./renderer":11}],10:[function(require,module,exports){(function(){var self=this;var Literal;Literal=function(value){this.value=value;this.isLiteral=true;return this};Literal.prototype.isLiteral=true;exports.Literal=Literal}).call(this)},{}],11:[function(require,module,exports){(function(){var self=this;var Renderer;Renderer=function(type){this.type=type;return this};Renderer.prototype={render:function(node){var self=this;var a;a=node.args.map(function(arg){return self.convertArgument(arg)});return self[node.expression].apply(self,a)},convertArgument:function(argument){var self=this;if(argument.isExpression||argument.isUnion){return self.render(argument)}else if(argument instanceof Array){return argument.map(function(e){return self.convertArgument(e)})}else if(typeof argument==="string"){return self.stringLiteral(argument)}else if(typeof argument==="number"){return argument}else if(argument.isLiteral){return argument.value}else{return argument.toString()}},stringLiteral:function(string){var self=this;if(string.indexOf("'")>-1){string=string.split("'",-1).map(function(substr){return"'"+substr+"'"}).join(',"\'",');return"concat("+string+")"}else{return"'"+string+"'"}},thisNode:function(){var self=this;return"."},descendant:function(parent,elementNames){var self=this;var names;if(elementNames.length===1){return parent+"//"+elementNames[0]}else if(elementNames.length>1){names=elementNames.map(function(e){return"self::"+e});return parent+"//*["+names.join(" | ")+"]"}else{return parent+"//*"}},child:function(parent,elementNames){var self=this;var names;if(elementNames.length===1){return parent+"/"+elementNames[0]}else if(elementNames.length>1){names=elementNames.map(function(e){return"self::"+e});return parent+"/*["+names.join(" | ")+"]"}else{return parent+"/*"}},axis:function(parent,name,tagName){var self=this;return parent+"/"+name+"::"+tagName},nodeName:function(current){var self=this;return"name("+current+")"},where:function(on,condition){var self=this;return on+"["+condition+"]"},attribute:function(current,name){var self=this;return current+"/@"+name},equality:function(one,two){var self=this;return one+" = "+two},addition:function(one,two){var self=this;return one+" + "+two},subtraction:function(one,two){var self=this;return one+" - "+two},is:function(one,two){var self=this;if(self.type==="exact"){return self.equality(one,two)}else{return self.contains(one,two)}},variable:function(name){var self=this;return"%{"+name+"}"},text:function(current){var self=this;return current+"/text()"},normalizedSpace:function(current){var self=this;return"normalize-space("+current+")"},literal:function(node){var self=this;return node},union:function(){var self=this;var expressions=Array.prototype.slice.call(arguments,0,arguments.length);return expressions.join(" | ")},anywhere:function(elementNames){var self=this;var names;if(elementNames.length===1){return"//"+elementNames[0]}else if(elementNames.length>1){names=elementNames.map(function(e){return"self::"+e}).join(" | ");return"//*["+names+"]"}else{return"//*"}},contains:function(current,value){var self=this;return"contains("+current+", "+value+")"},startsWith:function(current,value){var self=this;return"starts-with("+current+", "+value+")"},endsWith:function(current,value){var self=this;return"substring("+current+", string-length("+current+") - string-length("+value+") + 1, string-length("+current+")) = "+value},and:function(one,two){var self=this;return"("+one+" and "+two+")"},or:function(one,two){var self=this;return"("+one+" or "+two+")"},oneOf:function(current,values){var self=this;return values.map(function(value){return current+" = "+value}).join(" or ")},nextSibling:function(current,elementNames){var self=this;var names;if(elementNames.length===1){return current+"/following-sibling::*[1]/self::"+elementNames[0]}else if(elementNames.length>1){names=elementNames.map(function(e){return"self::"+e});return current+"/following-sibling::*[1]/self::*["+names.join(" | ")+"]"}else{return current+"/following-sibling::*[1]/self::*"}},previousSibling:function(current,elementNames){var self=this;var names;if(elementNames.length===1){return current+"/preceding-sibling::*[1]/self::"+elementNames[0]}else if(elementNames.length>1){names=elementNames.map(function(e){return"self::"+e});return current+"/preceding-sibling::*[1]/self::*["+names.join(" | ")+"]"}else{return current+"/preceding-sibling::*[1]/self::*"}},inverse:function(current){var self=this;return"not("+current+")"},stringFunction:function(current){var self=this;return"string("+current+")"},substringFunction:function(current,args){var self=this;return"substring("+current+", "+args.join(", ")+")"},concatFunction:function(args){var self=this;return"concat("+args.join(", ")+")"},stringLengthFunction:function(current){var self=this;return"string-length("+current+")"},countFunction:function(current){var self=this;return"count("+current+")"},nthOfType:function(n){var self=this;return"position() = "+n},nthOfTypeMod:function(m,n){var self=this;if(m===-1){return"(position() <= "+n+") and (((position() - "+n+") mod 1) = 0)"}else if(n>0){return"(position() >= "+n+") and (((position() - "+n+") mod "+m+") = 0)"}else{return"(position() mod "+m+") = 0"}},nthOfTypeOdd:function(){var self=this;return"(position() mod 2) = 1"},nthOfTypeEven:function(){var self=this;return"(position() mod 2) = 0"},nthLastOfType:function(n){var self=this;return"position() = last() - "+(n-1)},nthLastOfTypeMod:function(m,n){var self=this;if(m===-1){return"((last() - position() + 1) <= "+n+") and ((((last() - position() + 1) - "+n+") mod 1) = 0)"}else if(n>0){return"((last() - position() + 1) >= "+n+") and ((((last() - position() + 1) - "+n+") mod "+m+") = 0)"}else{return"((last() - position() + 1) mod "+m+") = 0"}},nthLastOfTypeOdd:function(){var self=this;return"((last() - position() + 1) >= 1) and ((((last() - position() + 1) - 1) mod 2) = 0)"},nthLastOfTypeEven:function(){var self=this;return"((last() - position() + 1) mod 2) = 0"},lastOfType:function(){var self=this;return"position() = last()"},nthChild:function(n){var self=this;return"count(preceding-sibling::*) = "+(n-1)},nthLastChild:function(n){var self=this;return"count(following-sibling::*) = "+(n-1)},firstChild:function(){var self=this;return"count(preceding-sibling::*) = 0"},lastChild:function(){var self=this;return"count(following-sibling::*) = 0"},onlyChild:function(){var self=this;return"count(preceding-sibling::*) = 0 and count(following-sibling::*) = 0"},onlyOfType:function(){var self=this;return"last() = 1"},empty:function(){var self=this;return"not(node())"}};Renderer.render=function(node,type){var self=this;if(typeof type==="undefined"){type="*"}return new Renderer(type).render(node)};exports.Renderer=Renderer}).call(this)},{}],"css-to-xpath":[function(require,module,exports){(function(){var self=this;var parser,xpathBuilder,Expression,parse,convertToXpath;parser=require("bo-selector").parser;xpathBuilder=require("xpath-builder").dsl();Expression=require("./expression");parser.yy.create=function(data){var self=this;return new Expression(data)};parse=function(selector){return parser.parse(selector).render(xpathBuilder,"descendant")};convertToXpath=function(selector){return parse(selector).toXPath()};convertToXpath.parse=parse;module.exports=convertToXpath}).call(this)},{"./expression":4,"bo-selector":6,"xpath-builder":8}]},{},[]);var cssToXPath=require("css-to-xpath");document.body.innerHTML=cssToXPath("p:not(:has(a.x))"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"css-to-xpath": "0.0.2" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment