syndicate-2017/dist/syndicatecompiler.min.js

8 lines
258 KiB
JavaScript
Raw Normal View History

2016-08-08 02:03:35 +00:00
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SyndicateCompiler=f()}})(function(){var define,module,exports;return 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){(function(Buffer){"use strict";var path=require("path");var ohm=require("ohm-js");var ES5=require("./es5.js");var grammarSource=Buffer("Ly8gLSotIGphdmFzY3JpcHQgLSotCi8vIFN5bnRhY3RpYyBleHRlbnNpb25zIHRvIEVTNSBmb3IgU3luZGljYXRlL2pzLiBTZWUgY29tcGlsZXIuanMgZm9yCi8vIHRoZSByZXN0IG9mIHRoZSB0cmFuc2xhdG9yLgoKU3luZGljYXRlIDw6IEVTNSB7CiAgLy8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICAvLyBFeHRlbnNpb25zIHRvIGV4cHJlc3Npb25zLgoKICBTdGF0ZW1lbnQKICAgICs9IEFjdG9yU3RhdGVtZW50CiAgICB8IERhdGFzcGFjZVN0YXRlbWVudAogICAgfCBBY3RvckZhY2V0U3RhdGVtZW50CiAgICB8IEFzc2VydGlvblR5cGVEZWNsYXJhdGlvblN0YXRlbWVudAogICAgfCBGaWVsZERl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gICAgICAgICAgICAgICAgICAgICAgIC0tIG9uRXZlbnQKICAgIHwgZGF0YWZsb3cgRnVuY3Rpb25Cb2R5QmxvY2sgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtLSBkYXRhZmxvdwogICAgfCBkdXJpbmcgRmFjZXRQYXR0ZXJuIEZhY2V0QmxvY2sgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC0tIGR1cmluZwogICAgfCBkdXJpbmcgRmFjZXRQYXR0ZXJuIGFjdG9yIChuYW1lZCBFeHByZXNzaW9uPHdpdGhJbj4pPyBGYWNldEJsb2NrIC0tIGR1cmluZ0FjdG9yCgogIEFzc2VydF
2016-07-11 16:06:07 +00:00
var g=ohm.grammars(contents).ES5;var semantics=g.semantics();semantics.addAttribute("modifiedSource",modifiedSourceActions);semantics.addAttribute("asES5",{_nonterminal:function(children){return isUndefined(this.modifiedSource)?this.interval.contents:this.modifiedSource}});module.exports={grammar:g,semantics:semantics,translateNonterminalCode:translateNonterminalCode}}).call(this,require("buffer").Buffer)},{buffer:4,"ohm-js":50,path:8}],3:[function(require,module,exports){"use strict";var compiler=require("./compiler.js");function getUrlContent(url){var req=new XMLHttpRequest;req.open("GET",url,false);try{req.send();if(req.status===0||req.status===200){return req.responseText}}catch(e){console.error("Error while loading "+url,e)}return false}function translateSyndicateScripts(){var scriptNodes=document.querySelectorAll('script[type="text/syndicate-js"]');var allSources=[];for(var i=0;i<scriptNodes.length;i++){var n=scriptNodes[i];var srcUrl=n.getAttribute("src");allSources.push(srcUrl?getUrlContent(srcUrl):n.innerHTML)}var allSourceText=allSources.join("\n;\n");var output=compiler.compileSyndicateSource(allSourceText);var f=new Function(output);f.call(window)}document.addEventListener("DOMContentLoaded",translateSyndicateScripts,false);module.exports=compiler},{"./compiler.js":1}],4:[function(require,module,exports){(function(global){"use strict";var base64=require("base64-js");var ieee754=require("ieee754");var isArray=require("isarray");exports.Buffer=Buffer;exports.SlowBuffer=SlowBuffer;exports.INSPECT_MAX_BYTES=50;Buffer.TYPED_ARRAY_SUPPORT=global.TYPED_ARRAY_SUPPORT!==undefined?global.TYPED_ARRAY_SUPPORT:typedArraySupport();exports.kMaxLength=kMaxLength();function typedArraySupport(){try{var arr=new Uint8Array(1);arr.foo=function(){return 42};return arr.foo()===42&&typeof arr.subarray==="function"&&arr.subarray(1,1).byteLength===0}catch(e){return false}}function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(that,length){if(kMaxLength()<length){throw new RangeError("Invalid typed array length")}if(Buffer.TYPED_ARRAY_SUPPORT){that=new Uint8Array(length);that.__proto__=Buffer.prototype}else{if(that===null){that=new Buffer(length)}that.length=length}return that}function Buffer(arg,encodingOrOffset,length){if(!Buffer.TYPED_ARRAY_SUPPORT&&!(this instanceof Buffer)){return new Buffer(arg,encodingOrOffset,length)}if(typeof arg==="number"){if(typeof encodingOrOffset==="string"){throw new Error("If encoding is specified then the first argument must be a string")}return allocUnsafe(this,arg)}return from(this,arg,encodingOrOffset,length)}Buffer.poolSize=8192;Buffer._augment=function(arr){arr.__proto__=Buffer.prototype;return arr};function from(that,value,encodingOrOffset,length){if(typeof value==="number"){throw new TypeError('"value" argument must not be a number')}if(typeof ArrayBuffer!=="undefined"&&value instanceof ArrayBuffer){return fromArrayBuffer(that,value,encodingOrOffset,length)}if(typeof value==="string"){return fromString(that,value,encodingOrOffset)}return fromObject(that,value)}Buffer.from=function(value,encodingOrOffset,length){return from(null,value,encodingOrOffset,length)};if(Buffer.TYPED_ARRAY_SUPPORT){Buffer.prototype.__proto__=Uint8Array.prototype;Buffer.__proto__=Uint8Array;if(typeof Symbol!=="undefined"&&Symbol.species&&Buffer[Symbol.species]===Buffer){Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:true})}}function assertSize(size){if(typeof size!=="number"){throw new TypeError('"size" argument must be a number')}}function alloc(that,size,fill,encoding){assertSize(size);if(size<=0){return createBuffer(that,size)}if(fill!==undefined){return typeof encoding==="string"?createBuffer(that,size).fill(fill,encoding):createBuffer(that,size).fill(fill)}return createBuffer(that,size)}Buffer.alloc=function(size,fill,encoding){return alloc(null,size,fill,encoding)};function allocUnsafe(that,size){assertSize(size);that=createBuffer(that,size<0?0:checked(size)|0);if(!Buffer.TYPED_ARRAY_SUPPORT){for(var i=0;i<size;i++){that[i]=0}}return that}Buffer.all
2016-08-08 02:03:35 +00:00
for(var i=0;i<length;i++){if(i+offset>=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function isnan(val){return val!==val}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"base64-js":5,ieee754:6,isarray:7}],5:[function(require,module,exports){"use strict";exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;var lookup=[];var revLookup=[];var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;function init(){var code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var i=0,len=code.length;i<len;++i){lookup[i]=code[i];revLookup[code.charCodeAt(i)]=i}revLookup["-".charCodeAt(0)]=62;revLookup["_".charCodeAt(0)]=63}init();function toByteArray(b64){var i,j,l,tmp,placeHolders,arr;var len=b64.length;if(len%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}placeHolders=b64[len-2]==="="?2:b64[len-1]==="="?1:0;arr=new Arr(len*3/4-placeHolders);l=placeHolders>0?len-4:len;var L=0;for(i=0,j=0;i<l;i+=4,j+=3){tmp=revLookup[b64.charCodeAt(i)]<<18|revLookup[b64.charCodeAt(i+1)]<<12|revLookup[b64.charCodeAt(i+2)]<<6|revLookup[b64.charCodeAt(i+3)];arr[L++]=tmp>>16&255;arr[L++]=tmp>>8&255;arr[L++]=tmp&255}if(placeHolders===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[L++]=tmp&255}else if(placeHolders===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[L++]=tmp>>8&255;arr[L++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;i<end;i+=3){tmp=(uint8[i]<<16)+(uint8[i+1]<<8)+uint8[i+2];output.push(tripletToBase64(tmp))}return output.join("")}function fromByteArray(uint8){var tmp;var len=uint8.length;var extraBytes=len%3;var output="";var parts=[];var maxChunkLength=16383;for(var i=0,len2=len-extraBytes;i<len2;i+=maxChunkLength){parts.push(encodeChunk(uint8,i,i+maxChunkLength>len2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];output+=lookup[tmp>>2];output+=lookup[tmp<<4&63];output+="=="}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];output+=lookup[tmp>>10];output+=lookup[tmp>>4&63];output+=lookup[tmp<<2&63];output+="="}parts.push(output);return parts.join("")}},{}],6:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m;var eLen=nBytes*8-mLen-1;var eMax=(1<<eLen)-1;var eBias=eMax>>1;var nBits=-7;var i=isLE?nBytes-1:0;var d=isLE?-1:1;var s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c;var eLen=nBytes*8-mLen-1;var eMax=(1<<eLen)-1;var eBias=eMax>>1;var rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0;var i=isLE?0:nBytes-1;var d=isLE?1:-1;var s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8){}e=e<<mLen|m;eLen+=mLen;for(;eLen>0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8){}buffer[offset+i-d]|=s*128}},{}],7:[function(require,module,exports){var toString={}.toString;module.exports=Array.isArray||function(arr){return toString.call(arr)=="[object Array]"}},{}],8:[function(require,module,exports){(function(process){function normalizeArray(parts,allowAboveRoot){var up=0;for(var i=parts.length-1;i>=0;i
2016-08-07 19:41:10 +00:00
})},{"..":50}],13:[function(require,module,exports){"use strict";module.exports={toAST:require("./semantics-toAST").helper,semanticsForToAST:require("./semantics-toAST").semantics}},{"./semantics-toAST":14}],14:[function(require,module,exports){"use strict";var pexprs=require("../src/pexprs");var MatchResult=require("../src/MatchResult");var Grammar=require("../src/Grammar");var extend=require("util-extend");var defaultOperation={_terminal:function(){return this.primitiveValue},_nonterminal:function(children){var ctorName=this._node.ctorName;var mapping=this.args.mapping;if(!mapping.hasOwnProperty(ctorName)){if(this._node instanceof pexprs.Alt||this._node instanceof pexprs.Apply){return children[0].toAST(mapping)}if(this.isLexical()){return this.interval.contents}var realChildren=children.filter(function(child){return!child.isTerminal()});if(realChildren.length===1){return realChildren[0].toAST(mapping)}}if(typeof mapping[ctorName]==="number"){return children[mapping[ctorName]].toAST(mapping)}var propMap=mapping[ctorName]||children;var node={type:ctorName};for(var prop in propMap){var mappedProp=mapping[ctorName]&&mapping[ctorName][prop];if(typeof mappedProp==="number"){node[prop]=children[mappedProp].toAST(mapping)}else if(typeof mappedProp==="string"||typeof mappedProp==="boolean"||mappedProp===null){node[prop]=mappedProp}else if(typeof mappedProp==="object"&&mappedProp instanceof Number){node[prop]=Number(mappedProp)}else if(typeof mappedProp==="function"){node[prop]=mappedProp.call(this,children)}else if(mappedProp===undefined){if(children[prop]&&!children[prop].isTerminal()){node[prop]=children[prop].toAST(mapping)}else{delete node[prop]}}}return node},_iter:function(children){if(this._node.isOptional()){if(this.numChildren===0){return null}else{return children[0].toAST(this.args.mapping)}}return children.map(function(child){return child.toAST(this.args.mapping)},this)},NonemptyListOf:function(first,sep,rest){return[first.toAST(this.args.mapping)].concat(rest.toAST(this.args.mapping))},EmptyListOf:function(){return[]}};function toAST(res,mapping){if(!(res instanceof MatchResult)||res.failed()){throw new Error("toAST() expects a succesfull MatchResult as first parameter")}mapping=extend({},mapping);var operation=extend({},defaultOperation);for(var termName in mapping){if(typeof mapping[termName]==="function"){operation[termName]=mapping[termName];delete mapping[termName]}}var g=res._cst.grammar;var s=g.semantics().addOperation("toAST(mapping)",operation);return s(res).toAST(mapping)}function semanticsForToAST(g){if(!(g instanceof Grammar)){throw new Error("semanticsToAST() expects a Grammar as parameter")}return g.semantics().addOperation("toAST(mapping)",defaultOperation)}module.exports={helper:toAST,semantics:semanticsForToAST}},{"../src/Grammar":38,"../src/MatchResult":42,"../src/pexprs":67,"util-extend":35}],15:[function(require,module,exports){"use strict";module.exports=require("./is-implemented")()?Symbol:require("./polyfill")},{"./is-implemented":16,"./polyfill":31}],16:[function(require,module,exports){"use strict";module.exports=function(){var symbol;if(typeof Symbol!=="function")return false;symbol=Symbol("test symbol");try{String(symbol)}catch(e){return false}if(typeof Symbol.iterator==="symbol")return true;if(typeof Symbol.isConcatSpreadable!=="object")return false;if(typeof Symbol.iterator!=="object")return false;if(typeof Symbol.toPrimitive!=="object")return false;if(typeof Symbol.toStringTag!=="object")return false;if(typeof Symbol.unscopables!=="object")return false;return true}},{}],17:[function(require,module,exports){"use strict";module.exports=function(x){return x&&(typeof x==="symbol"||x["@@toStringTag"]==="Symbol")||false}},{}],18:[function(require,module,exports){"use strict";var assign=require("es5-ext/object/assign"),normalizeOpts=require("es5-ext/object/normalize-options"),isCallable=require("es5-ext/object/is-callable"),contains=require("es5-ext/string/#/contains"),d;d=module.exports=function(dscr,value){var c,e,w,options,desc;if(arguments.length<2||typeof dscr!=="string"){options=value;v
2016-08-08 02:03:35 +00:00
writable:true,configurable:true}});return extend(ns,optProps)};Namespace.toString=function(ns){return Object.prototype.toString.call(ns)};module.exports=Namespace},{"util-extend":35}],44:[function(require,module,exports){"use strict";function PosInfo(state){this.state=state;this.applicationMemoKeyStack=[];this.memo={};this.currentLeftRecursion=undefined}PosInfo.prototype={isActive:function(application){return this.applicationMemoKeyStack.indexOf(application.toMemoKey())>=0},enter:function(application){this.state.enter(application);this.applicationMemoKeyStack.push(application.toMemoKey())},exit:function(){this.state.exit();this.applicationMemoKeyStack.pop()},startLeftRecursion:function(headApplication,memoRec){memoRec.isLeftRecursion=true;memoRec.headApplication=headApplication;memoRec.nextLeftRecursion=this.currentLeftRecursion;this.currentLeftRecursion=memoRec;var applicationMemoKeyStack=this.applicationMemoKeyStack;var indexOfFirstInvolvedRule=applicationMemoKeyStack.indexOf(headApplication.toMemoKey())+1;var involvedApplicationMemoKeys=applicationMemoKeyStack.slice(indexOfFirstInvolvedRule);memoRec.isInvolved=function(applicationMemoKey){return involvedApplicationMemoKeys.indexOf(applicationMemoKey)>=0};memoRec.updateInvolvedApplicationMemoKeys=function(){for(var idx=indexOfFirstInvolvedRule;idx<applicationMemoKeyStack.length;idx++){var applicationMemoKey=applicationMemoKeyStack[idx];if(!this.isInvolved(applicationMemoKey)){involvedApplicationMemoKeys.push(applicationMemoKey)}}}},endLeftRecursion:function(){this.currentLeftRecursion=this.currentLeftRecursion.nextLeftRecursion},shouldUseMemoizedResult:function(memoRec){if(!memoRec.isLeftRecursion){return true}var applicationMemoKeyStack=this.applicationMemoKeyStack;for(var idx=0;idx<applicationMemoKeyStack.length;idx++){var applicationMemoKey=applicationMemoKeyStack[idx];if(memoRec.isInvolved(applicationMemoKey)){return false}}return true}};module.exports=PosInfo},{}],45:[function(require,module,exports){"use strict";var Symbol=require("es6-symbol");var inherits=require("inherits");var MatchResult=require("./MatchResult");var IterationNode=require("./nodes").IterationNode;var common=require("./common");function Wrapper(){}Wrapper.prototype.toString=function(){return"[semantics wrapper for "+this._node.grammar.name+"]"};Wrapper.prototype._forgetMemoizedResultFor=function(attributeName){delete this._node[this._semantics.attributeKeys[attributeName]];this.children.forEach(function(child){child._forgetMemoizedResultFor(attributeName)})};Wrapper.prototype.child=function(idx){if(!(0<=idx&&idx<this._node.numChildren())){return undefined}var childWrapper=this._childWrappers[idx];if(!childWrapper){childWrapper=this._childWrappers[idx]=this._semantics.wrap(this._node.childAt(idx))}return childWrapper};Wrapper.prototype._children=function(){for(var idx=0;idx<this._node.numChildren();idx++){this.child(idx)}return this._childWrappers};Wrapper.prototype.isIteration=function(){return this._node.isIteration()};Wrapper.prototype.isTerminal=function(){return this._node.isTerminal()};Wrapper.prototype.isNonterminal=function(){return this._node.isNonterminal()};Wrapper.prototype.isSyntactic=function(){return this.isNonterminal()&&this._node.isSyntactic()};Wrapper.prototype.isLexical=function(){return this.isNonterminal()&&this._node.isLexical()};Wrapper.prototype.isOptional=function(){return this._node.isOptional()};Wrapper.prototype.iteration=function(optElements){var iter=new IterationNode(this._node.grammar,optElements||[],this.interval,false);return this._semantics.wrap(iter)};Object.defineProperties(Wrapper.prototype,{children:{get:function(){return this._children()}},ctorName:{get:function(){return this._node.ctorName}},interval:{get:function(){return this._node.interval}},numChildren:{get:function(){return this._node.numChildren()}},primitiveValue:{get:function(){if(this.isTerminal()){return this._node.primitiveValue}throw new TypeError("tried to access the 'primitiveValue' attribute of a non-terminal CST node")}}});function Semantics(grammar,superSemantics){var self=this;this.gr
duplicatePropertyNames:duplicatePropertyNames,duplicateRuleDeclaration:duplicateRuleDeclaration,inconsistentArity:inconsistentArity,intervalSourcesDontMatch:intervalSourcesDontMatch,invalidConstructorCall:invalidConstructorCall,invalidParameter:invalidParameter,grammarSyntaxError:grammarSyntaxError,kleeneExprHasNullableOperand:kleeneExprHasNullableOperand,undeclaredGrammar:undeclaredGrammar,undeclaredRule:undeclaredRule,wrongNumberOfArguments:wrongNumberOfArguments,wrongNumberOfParameters:wrongNumberOfParameters,throwErrors:function(errors){if(errors.length===1){throw errors[0]}if(errors.length>1){throw multipleErrors(errors)}}}},{"./Namespace":43}],50:[function(require,module,exports){"use strict";var Builder=require("./Builder");var Grammar=require("./Grammar");var Namespace=require("./Namespace");var common=require("./common");var errors=require("./errors");var pexprs=require("./pexprs");var util=require("./util");var isBuffer=require("is-buffer");var ohmGrammar;var documentInterface={querySelector:function(sel){return document.querySelector(sel)},querySelectorAll:function(sel){return document.querySelectorAll(sel)}};function isElement(obj){return!!(obj&&obj.nodeType===1)}function isUndefined(obj){return obj===void 0}var MAX_ARRAY_INDEX=Math.pow(2,53)-1;function isArrayLike(obj){if(obj==null){return false}var length=obj.length;return typeof length==="number"&&length>=0&&length<=MAX_ARRAY_INDEX}function load(url){var req=new XMLHttpRequest;req.open("GET",url,false);try{req.send();if(req.status===0||req.status===200){return req.responseText}}catch(e){}throw new Error("unable to load url "+url)}function buildGrammar(match,namespace,optOhmGrammarForTesting){var builder=new Builder;var decl;var currentRuleName;var currentRuleFormals;var overriding=false;var metaGrammar=optOhmGrammarForTesting||ohmGrammar;var helpers=metaGrammar.semantics().addOperation("visit",{Grammar:function(n,s,open,rs,close){var grammarName=n.visit();decl=builder.newGrammar(grammarName,namespace);s.visit();rs.visit();var g=decl.build();g.definitionInterval=this.interval.trimmed();if(grammarName in namespace){throw errors.duplicateGrammarDeclaration(g,namespace)}namespace[grammarName]=g;return g},SuperGrammar:function(_,n){var superGrammarName=n.visit();if(superGrammarName==="null"){decl.withSuperGrammar(null)}else{if(!namespace||!(superGrammarName in namespace)){throw errors.undeclaredGrammar(superGrammarName,namespace,n.interval)}decl.withSuperGrammar(namespace[superGrammarName])}},Rule_define:function(n,fs,d,_,b){currentRuleName=n.visit();currentRuleFormals=fs.visit()[0]||[];if(!decl.defaultStartRule&&decl.ensureSuperGrammar()!==Grammar.ProtoBuiltInRules){decl.withDefaultStartRule(currentRuleName)}var body=b.visit();body.definitionInterval=this.interval.trimmed();var description=d.visit()[0];return decl.define(currentRuleName,currentRuleFormals,body,description)},Rule_override:function(n,fs,_,b){currentRuleName=n.visit();currentRuleFormals=fs.visit()[0]||[];overriding=true;var body=b.visit();body.definitionInterval=this.interval.trimmed();var ans=decl.override(currentRuleName,currentRuleFormals,body);overriding=false;return ans},Rule_extend:function(n,fs,_,b){currentRuleName=n.visit();currentRuleFormals=fs.visit()[0]||[];var body=b.visit();var ans=decl.extend(currentRuleName,currentRuleFormals,body);decl.ruleBodies[currentRuleName].definitionInterval=this.interval.trimmed();return ans},RuleBody:function(_,term,_bars,terms){var args=[term.visit()].concat(terms.visit());return builder.alt.apply(builder,args).withInterval(this.interval)},Formals:function(opointy,fs,cpointy){return fs.visit()},Params:function(opointy,ps,cpointy){return ps.visit()},Alt:function(seq,_,seqs){var args=[seq.visit()].concat(seqs.visit());return builder.alt.apply(builder,args).withInterval(this.interval)},TopLevelTerm_inline:function(b,n){var inlineRuleName=currentRuleName+"_"+n.visit();var body=b.visit();body.definitionInterval=this.interval.trimmed();var isNewRuleDeclaration=!(decl.superGrammar&&decl.superGrammar.ruleBodies[inlineRuleName]);if(overriding&&!isNewRuleDeclarat
})};pexprs.Seq.prototype._isNullable=function(grammar,memo){return this.factors.every(function(factor){return factor._isNullable(grammar,memo)})};pexprs.Star.prototype._isNullable=pexprs.Opt.prototype._isNullable=pexprs.Not.prototype._isNullable=pexprs.Lookahead.prototype._isNullable=function(grammar,memo){return true};pexprs.Lex.prototype._isNullable=function(grammar,memo){return this.expr._isNullable(grammar,memo)};pexprs.Apply.prototype._isNullable=function(grammar,memo){var key=this.toMemoKey();if(!Object.prototype.hasOwnProperty.call(memo,key)){var body=grammar.ruleBodies[this.ruleName];var inlined=body.substituteParams(this.args);memo[key]=false;memo[key]=inlined._isNullable(grammar,memo)}return memo[key]}},{"./common":48,"./pexprs":67}],61:[function(require,module,exports){"use strict";var common=require("./common");var pexprs=require("./pexprs");function escapeString(str){var output=JSON.stringify(str);output=output.replace(/[\u2028\u2029]/g,function(char,pos,str){var hex=char.codePointAt(0).toString(16);return"\\u"+"0000".slice(hex.length)+hex});return output}function getIntervalInfo(expr,grammarInterval){if(expr.interval&&grammarInterval){var adjusted=expr.interval.relativeTo(grammarInterval);var start=adjusted.startIdx;var end=adjusted.endIdx;return".withInterval(decl.sourceInterval("+start+", "+end+"))"}return""}pexprs.PExpr.prototype.outputRecipe=common.abstract("outputRecipe");pexprs.any.outputRecipe=function(sb,formals,grammarInterval){throw new Error("should never output a recipe for `any` expression")};pexprs.end.outputRecipe=function(sb,formals,grammarInterval){throw new Error("should never output a recipe for `end` expression")};pexprs.Terminal.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.terminal(");sb.append(typeof this.obj==="string"?escapeString(this.obj):""+this.obj);sb.append(")"+getIntervalInfo(this,grammarInterval))};pexprs.Range.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.range(");sb.append(JSON.stringify(this.from));sb.append(", ");sb.append(JSON.stringify(this.to));sb.append(")"+getIntervalInfo(this,grammarInterval))};pexprs.Param.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.param("+this.index+")"+getIntervalInfo(this,grammarInterval))};pexprs.Alt.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.alt(");for(var idx=0;idx<this.terms.length;idx++){if(idx>0){sb.append(", ")}this.terms[idx].outputRecipe(sb,formals,grammarInterval)}sb.append(")"+getIntervalInfo(this,grammarInterval))};pexprs.Extend.prototype.outputRecipe=function(sb,formals,grammarInterval){var extension=this.terms[0];extension.outputRecipe(sb,formals,grammarInterval)};pexprs.Seq.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.seq(");for(var idx=0;idx<this.factors.length;idx++){if(idx>0){sb.append(", ")}this.factors[idx].outputRecipe(sb,formals,grammarInterval)}sb.append(")"+getIntervalInfo(this,grammarInterval))};pexprs.Star.prototype.outputRecipe=pexprs.Plus.prototype.outputRecipe=pexprs.Opt.prototype.outputRecipe=pexprs.Not.prototype.outputRecipe=pexprs.Lex.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this."+this.constructor.name.toLowerCase()+"(");this.expr.outputRecipe(sb,formals,grammarInterval);sb.append(")"+getIntervalInfo(this,grammarInterval))};pexprs.Lookahead.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.la(");this.expr.outputRecipe(sb,formals,grammarInterval);sb.append(")"+getIntervalInfo(this,grammarInterval))};pexprs.Apply.prototype.outputRecipe=function(sb,formals,grammarInterval){sb.append("this.app(");sb.append(JSON.stringify(this.ruleName));if(this.ruleName.indexOf("_")>=0&&formals.length>0){var apps=formals.map(function(_,idx){return"this.param("+idx+")"});sb.append(", ["+apps.join(", ")+"]")}else if(this.args.length>0){sb.append(", [");this.args.forEach(function(arg,idx){if(idx>0){sb.append(", ")}arg.outputRecipe(sb,formals,grammarInterval)});sb.append("]")}sb.append(")"+getIntervalInfo(this,grammarInterval)
2016-05-16 17:27:46 +00:00
Nl:/[\u2160-\u2182]|[\u3007-\u3007]|[\u3021-\u3029]/,Nd:/[\u0030-\u0039]|[\u0660-\u0669]|[\u06F0-\u06F9]|[\u0966-\u096F]|[\u09E6-\u09EF]|[\u0A66-\u0A6F]|[\u0AE6-\u0AEF]|[\u0B66-\u0B6F]|[\u0BE7-\u0BEF]|[\u0C66-\u0C6F]|[\u0CE6-\u0CEF]|[\u0D66-\u0D6F]|[\u0E50-\u0E59]|[\u0ED0-\u0ED9]|[\u0F20-\u0F29]|[\uFF10-\uFF19]/,Mn:/[\u0300-\u0345]|[\u0360-\u0361]|[\u0483-\u0486]|[\u0591-\u05A1]|[\u05A3-\u05B9]|[\u05BB-\u05BD]|[\u05BF-\u05BF]|[\u05C1-\u05C2]|[\u05C4-\u05C4]|[\u064B-\u0652]|[\u0670-\u0670]|[\u06D6-\u06DC]|[\u06DF-\u06E4]|[\u06E7-\u06E8]|[\u06EA-\u06ED]|[\u0901-\u0902]|[\u093C-\u093C]|[\u0941-\u0948]|[\u094D-\u094D]|[\u0951-\u0954]|[\u0962-\u0963]|[\u0981-\u0981]|[\u09BC-\u09BC]|[\u09C1-\u09C4]|[\u09CD-\u09CD]|[\u09E2-\u09E3]|[\u0A02-\u0A02]|[\u0A3C-\u0A3C]|[\u0A41-\u0A42]|[\u0A47-\u0A48]|[\u0A4B-\u0A4D]|[\u0A70-\u0A71]|[\u0A81-\u0A82]|[\u0ABC-\u0ABC]|[\u0AC1-\u0AC5]|[\u0AC7-\u0AC8]|[\u0ACD-\u0ACD]|[\u0B01-\u0B01]|[\u0B3C-\u0B3C]|[\u0B3F-\u0B3F]|[\u0B41-\u0B43]|[\u0B4D-\u0B4D]|[\u0B56-\u0B56]|[\u0B82-\u0B82]|[\u0BC0-\u0BC0]|[\u0BCD-\u0BCD]|[\u0C3E-\u0C40]|[\u0C46-\u0C48]|[\u0C4A-\u0C4D]|[\u0C55-\u0C56]|[\u0CBF-\u0CBF]|[\u0CC6-\u0CC6]|[\u0CCC-\u0CCD]|[\u0D41-\u0D43]|[\u0D4D-\u0D4D]|[\u0E31-\u0E31]|[\u0E34-\u0E3A]|[\u0E47-\u0E4E]|[\u0EB1-\u0EB1]|[\u0EB4-\u0EB9]|[\u0EBB-\u0EBC]|[\u0EC8-\u0ECD]|[\u0F18-\u0F19]|[\u0F35-\u0F35]|[\u0F37-\u0F37]|[\u0F39-\u0F39]|[\u0F71-\u0F7E]|[\u0F80-\u0F84]|[\u0F86-\u0F87]|[\u0F90-\u0F95]|[\u0F97-\u0F97]|[\u0F99-\u0FAD]|[\u0FB1-\u0FB7]|[\u0FB9-\u0FB9]|[\u20D0-\u20DC]|[\u20E1-\u20E1]|[\u302A-\u302F]|[\u3099-\u309A]|[\uFB1E-\uFB1E]|[\uFE20-\uFE23]/,Mc:/[\u0903-\u0903]|[\u093E-\u0940]|[\u0949-\u094C]|[\u0982-\u0983]|[\u09BE-\u09C0]|[\u09C7-\u09C8]|[\u09CB-\u09CC]|[\u09D7-\u09D7]|[\u0A3E-\u0A40]|[\u0A83-\u0A83]|[\u0ABE-\u0AC0]|[\u0AC9-\u0AC9]|[\u0ACB-\u0ACC]|[\u0B02-\u0B03]|[\u0B3E-\u0B3E]|[\u0B40-\u0B40]|[\u0B47-\u0B48]|[\u0B4B-\u0B4C]|[\u0B57-\u0B57]|[\u0B83-\u0B83]|[\u0BBE-\u0BBF]|[\u0BC1-\u0BC2]|[\u0BC6-\u0BC8]|[\u0BCA-\u0BCC]|[\u0BD7-\u0BD7]|[\u0C01-\u0C03]|[\u0C41-\u0C44]|[\u0C82-\u0C83]|[\u0CBE-\u0CBE]|[\u0CC0-\u0CC4]|[\u0CC7-\u0CC8]|[\u0CCA-\u0CCB]|[\u0CD5-\u0CD6]|[\u0D02-\u0D03]|[\u0D3E-\u0D40]|[\u0D46-\u0D48]|[\u0D4A-\u0D4C]|[\u0D57-\u0D57]|[\u0F3E-\u0F3F]|[\u0F7F-\u0F7F]/,Pc:/[\u005F-\u005F]|[\u203F-\u2040]|[\u30FB-\u30FB]|[\uFE33-\uFE34]|[\uFE4D-\uFE4F]|[\uFF3F-\uFF3F]|[\uFF65-\uFF65]/,Zs:/[\u2000-\u200B]|[\u3000-\u3000]/,L:/[\u0041-\u005A]|[\u00C0-\u00D6]|[\u00D8-\u00DE]|[\u0100-\u0100]|[\u0102-\u0102]|[\u0104-\u0104]|[\u0106-\u0106]|[\u0108-\u0108]|[\u010A-\u010A]|[\u010C-\u010C]|[\u010E-\u010E]|[\u0110-\u0110]|[\u0112-\u0112]|[\u0114-\u0114]|[\u0116-\u0116]|[\u0118-\u0118]|[\u011A-\u011A]|[\u011C-\u011C]|[\u011E-\u011E]|[\u0120-\u0120]|[\u0122-\u0122]|[\u0124-\u0124]|[\u0126-\u0126]|[\u0128-\u0128]|[\u012A-\u012A]|[\u012C-\u012C]|[\u012E-\u012E]|[\u0130-\u0130]|[\u0132-\u0132]|[\u0134-\u0134]|[\u0136-\u0136]|[\u0139-\u0139]|[\u013B-\u013B]|[\u013D-\u013D]|[\u013F-\u013F]|[\u0141-\u0141]|[\u0143-\u0143]|[\u0145-\u0145]|[\u0147-\u0147]|[\u014A-\u014A]|[\u014C-\u014C]|[\u014E-\u014E]|[\u0150-\u0150]|[\u0152-\u0152]|[\u0154-\u0154]|[\u0156-\u0156]|[\u0158-\u0158]|[\u015A-\u015A]|[\u015C-\u015C]|[\u015E-\u015E]|[\u0160-\u0160]|[\u0162-\u0162]|[\u0164-\u0164]|[\u0166-\u0166]|[\u0168-\u0168]|[\u016A-\u016A]|[\u016C-\u016C]|[\u016E-\u016E]|[\u0170-\u0170]|[\u0172-\u0172]|[\u0174-\u0174]|[\u0176-\u0176]|[\u0178-\u0179]|[\u017B-\u017B]|[\u017D-\u017D]|[\u0181-\u0182]|[\u0184-\u0184]|[\u0186-\u0187]|[\u0189-\u018B]|[\u018E-\u0191]|[\u0193-\u0194]|[\u0196-\u0198]|[\u019C-\u019D]|[\u019F-\u01A0]|[\u01A2-\u01A2]|[\u01A4-\u01A4]|[\u01A6-\u01A7]|[\u01A9-\u01A9]|[\u01AC-\u01AC]|[\u01AE-\u01AF]|[\u01B1-\u01B3]|[\u01B5-\u01B5]|[\u01B7-\u01B8]|[\u01BC-\u01BC]|[\u01C4-\u01C4]|[\u01C7-\u01C7]|[\u01CA-\u01CA]|[\u01CD-\u01CD]|[\u01CF-\u01CF]|[\u01D1-\u01D1]|[\u01D3-\u01D3]|[\u01D5-\u01D5]|[\u01D7-\u01D7]|[\u01D9-\u01D9]|[\u01DB-\u01DB]|[\u01DE-\u01DE]|[\u01E0-\u01E0]|[\u01E2-\u01E2]|[\u01E4-\u01E4]|[\u01E6-\u01E6]|[\u01E8-\u01E8]|[\u01EA-\u01EA]|[\u01EC-\u01EC]|[\u01EE-\u01EE]|[\u01F1-\u01F1]|[\u01F4-\u01F4