syndicate-2017/dist/syndicatecompiler.min.js

8 lines
260 KiB
JavaScript
Raw Normal View History

2017-02-20 22:19:56 +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("Ly8gLSotIGphdmFzY3JpcHQgLSotCi8vIFN5bnRhY3RpYyBleHRlbnNpb25zIHRvIEVTNSBmb3IgU3luZGljYXRlL2pzLiBTZWUgY29tcGlsZXIuanMgZm9yCi8vIHRoZSByZXN0IG9mIHRoZSB0cmFuc2xhdG9yLgoKU3luZGljYXRlIDw6IEVTNSB7CiAgLy8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICAvLyBFeHRlbnNpb25zIHRvIGV4cHJlc3Npb25zLgoKICBTdGF0ZW1lbnQKICAgICs9IEFjdG9yU3RhdGVtZW50CiAgICB8IERhdGFzcGFjZVN0YXRlbWVudAogICAgfCBBY3RvckZhY2V0U3RhdGVtZW50CiAgICB8IEFjdG9yRW5kcG9pbnRTdGF0ZW1lbnQKICAgIHwgQXNzZXJ0aW9uVHlw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AgIHwgb24gRmFjZXRFdmVudFBhdHRlcm4gRnVuY3Rpb25Cb2R5QmxvY2sgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLS0gZXZlbnQKICAgIHwgb24gZXZlbnQgaWRlbnRpZmllciBGdW5jdGlvbkJvZHlCbG9jayAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLS0gb25FdmVudAogICAgfCBzdG9wIG9uIEZhY2V0VHJhbnNpdGlvbkV2ZW50UGF0dGVybiBGdW5jdGlvbkJvZHlCbG9jayAgICAgICAgICAgICAgICAgICAtLSBzdG9wT25XaXRoQ29udAogICAgfCBzdG9wIG9uIEZhY2V0VHJhbnNpdGlvbkV2ZW50UGF0dGVybiAjKHNjKSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAtLSBzdG9wT25Ob0NvbnQKICAgIHwgZGF0YWZsb3cgRnVuY3Rpb25Cb2R5QmxvY2sgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLS0gZGF0YWZsb3cKICAgIHwgZHVyaW5nIEZhY2V0UGF0dGVybiBGdW5jdGlvbkJvZHlCbG9jayAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLS0gZHVyaW5nCiAgICB8IGR1cmluZyBGYWNldFBhdHRlcm4gc3Bhd24gKG5hbWVkIEV4cHJlc3Npb248d2l0aEluPik/IEZ1bmN0aW9uQm9keUJsb2NrIC0tIGR1cmluZ1NwYXduCgogIEFzc2VydFdoZW5DbGF1c2UgPSB3aGVuICIoIiBFeHByZXNzaW9uPHdpdGhJbj4gIikiCgogIEFzc2VydGlvblR5cGVEZWNsYXJhdGlvblN0YXRlbWVudAogICAgPSAoYXNzZXJ0aW9uIHwgbWVzc2FnZSkgdHlwZSBpZGVudGlmaWVyICIoIiBGb3JtYWxQYXJhbWV0ZXJMaXN0ICIpIiAoIj0iIHN0cmluZ0xpdGVyYWwpPyAjKHNjKQoKICBGaWVsZERlY2xhcmF0aW9uU3RhdGVtZW50ID0gZmllbGQgTWVtYmVyRXhwcmVzc2lvbiAoIj0iIEFzc2lnbm1lbnRFeHByZXNzaW9uPHdpdGhJbj4pPyAjKHNjKQogIE1lbWJlckV4cHJlc3Npb24gKz0gZmllbGQgTWVtYmVyRXhwcmVzc2lvbiAtLSBmaWVsZFJlZkV4cAogIFVuYXJ5RXhwcmVzc2lvbiArPSBkZWxldGUgZmllbGQgTWVtYmVyRXhwcmVzc2lvbiAtLSBmaWVsZERlbEV4cAoKICBTZW5kTWVzc2FnZVN0YXRlbWVudCA9ICI6OiIgRXhwcmVzc2lvbjx3aXRoSW4+ICMoc2MpCgogIEZhY2V0RXZlbn
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.__proto__={__proto__:Uint8Array.prototype,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')}else if(size<0){throw new RangeError('"size" argument must not be negative')}}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(
if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}codePoint=(leadSurrogate-55296<<10|codePoint-56320)+65536}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189)}leadSurrogate=null;if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i<str.length;++i){byteArray.push(str.charCodeAt(i)&255)}return byteArray}function utf16leToBytes(str,units){var c,hi,lo;var byteArray=[];for(var i=0;i<str.length;++i){if((units-=2)<0)break;c=str.charCodeAt(i);hi=c>>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length){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.byteLength=byteLength;exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;var lookup=[];var revLookup=[];var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;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;function placeHoldersCount(b64){var len=b64.length;if(len%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}return b64[len-2]==="="?2:b64[len-1]==="="?1:0}function byteLength(b64){return b64.length*3/4-placeHoldersCount(b64)}function toByteArray(b64){var i,j,l,tmp,placeHolders,arr;var len=b64.length;placeHolders=placeHoldersCount(b64);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+=
})},{"..":50}],12:[function(require,module,exports){var ohm=require("..");module.exports=ohm.makeRecipe(function(){var decl=this.newGrammar("OperationsAndAttributes").withSource('OperationsAndAttributes {\n\n AttributeSignature =\n name\n\n OperationSignature =\n name Formals?\n\n Formals\n = "(" ListOf<name, ","> ")"\n\n name (a name)\n = nameFirst nameRest*\n\n nameFirst\n = "_"\n | letter\n\n nameRest\n = "_"\n | alnum\n\n}').withDefaultStartRule("AttributeSignature");return decl.define("AttributeSignature",[],this.app("name").withInterval(decl.sourceInterval(54,58))).define("OperationSignature",[],this.seq(this.app("name").withInterval(decl.sourceInterval(87,91)),this.opt(this.app("Formals").withInterval(decl.sourceInterval(92,99))).withInterval(decl.sourceInterval(92,100))).withInterval(decl.sourceInterval(87,100))).define("Formals",[],this.seq(this.terminal("(").withInterval(decl.sourceInterval(118,121)),this.app("ListOf",[this.app("name").withInterval(decl.sourceInterval(129,133)),this.terminal(",").withInterval(decl.sourceInterval(135,138))]).withInterval(decl.sourceInterval(122,139)),this.terminal(")").withInterval(decl.sourceInterval(140,143))).withInterval(decl.sourceInterval(118,143))).define("name",[],this.seq(this.app("nameFirst").withInterval(decl.sourceInterval(168,177)),this.star(this.app("nameRest").withInterval(decl.sourceInterval(178,186))).withInterval(decl.sourceInterval(178,187))).withInterval(decl.sourceInterval(168,187)),"a name").define("nameFirst",[],this.alt(this.terminal("_").withInterval(decl.sourceInterval(207,210)),this.app("letter").withInterval(decl.sourceInterval(217,223))).withInterval(decl.sourceInterval(207,223))).define("nameRest",[],this.alt(this.terminal("_").withInterval(decl.sourceInterval(242,245)),this.app("alnum").withInterval(decl.sourceInterval(252,257))).withInterval(decl.sourceInterval(242,257))).build()})},{"..":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 succesfu
}var detail="expected "+this.getExpectedText();return getShortMatchErrorMessage(this.getRightmostFailurePosition(),this.state.inputStream.source,detail)})}inherits(MatchFailure,MatchResult);MatchFailure.prototype.toString=function(){return"[MatchFailure at position "+this.getRightmostFailurePosition()+"]"};MatchFailure.prototype.failed=function(){return true};MatchFailure.prototype.getRightmostFailurePosition=function(){return this.state.getRightmostFailurePosition()};MatchFailure.prototype.getRightmostFailures=function(){return this._failures};MatchFailure.prototype.getExpectedText=function(){var sb=new common.StringBuffer;var failures=this.getRightmostFailures();failures=failures.filter(function(failure){return!failure.isFluffy()});for(var idx=0;idx<failures.length;idx++){if(idx>0){if(idx===failures.length-1){sb.append(failures.length>2?", or ":" or ")}else{sb.append(", ")}}sb.append(failures[idx].toString())}return sb.contents()};MatchFailure.prototype.getInterval=function(){var pos=this.state.getRightmostFailurePosition();return new Interval(this.state.inputStream,pos,pos)};module.exports=MatchResult},{"./Interval":41,"./common":48,"./nodes":51,"./util":68,inherits:33}],43:[function(require,module,exports){"use strict";var extend=require("util-extend");function Namespace(){}Namespace.prototype=Object.create(null);Namespace.asNamespace=function(objOrNamespace){if(objOrNamespace instanceof Namespace){return objOrNamespace}return Namespace.createNamespace(objOrNamespace)};Namespace.createNamespace=function(optProps){return Namespace.extend(Namespace.prototype,optProps)};Namespace.extend=function(namespace,optProps){if(namespace!==Namespace.prototype&&!(namespace instanceof Namespace)){throw new TypeError("not a Namespace object: "+namespace)}var ns=Object.create(namespace,{constructor:{value:Namespace,enumerable:false,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=fun
}function duplicateParameterNames(ruleName,duplicates,body){return createError("Duplicate parameter names in rule "+ruleName+": "+duplicates.join(","),body.definitionInterval)}function invalidParameter(ruleName,expr){return createError("Invalid parameter to rule "+ruleName+": "+expr+" has arity "+expr.getArity()+", but parameter expressions "+"must have arity 1",expr.interval)}function applicationOfSyntacticRuleFromLexicalContext(ruleName,applyExpr){return createError("Cannot apply syntactic rule "+ruleName+" from here (inside a lexical context)",applyExpr.interval)}function kleeneExprHasNullableOperand(kleeneExpr){return createError("Nullable expression "+kleeneExpr.expr.interval.contents+" is not allowed inside '"+kleeneExpr.operator+"' (possible infinite loop)",kleeneExpr.expr.interval)}function inconsistentArity(ruleName,expected,actual,expr){return createError("Rule "+ruleName+" involves an alternation which has inconsistent arity "+"(expected "+expected+", got "+actual+")",expr.interval)}function duplicatePropertyNames(duplicates){return createError("Object pattern has duplicate property names: "+duplicates.join(", "))}function invalidConstructorCall(grammar,ctorName,children){return createError("Attempt to invoke constructor "+ctorName+" with invalid or unexpected arguments")}function multipleErrors(errors){var messages=errors.map(function(e){return e.message});return createError(["Errors:"].concat(messages).join("\n- "),errors[0].interval)}module.exports={applicationOfSyntacticRuleFromLexicalContext:applicationOfSyntacticRuleFromLexicalContext,cannotExtendUndeclaredRule:cannotExtendUndeclaredRule,cannotOverrideUndeclaredRule:cannotOverrideUndeclaredRule,duplicateGrammarDeclaration:duplicateGrammarDeclaration,duplicateParameterNames:duplicateParameterNames,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.with
};pexprs.Seq.prototype.introduceParams=function(formals){this.factors.forEach(function(factor,idx,factors){factors[idx]=factor.introduceParams(formals)});return this};pexprs.Iter.prototype.introduceParams=pexprs.Not.prototype.introduceParams=pexprs.Lookahead.prototype.introduceParams=pexprs.Lex.prototype.introduceParams=function(formals){this.expr=this.expr.introduceParams(formals);return this};pexprs.Apply.prototype.introduceParams=function(formals){var index=formals.indexOf(this.ruleName);if(index>=0){if(this.args.length>0){throw new Error("Parameterized rules cannot be passed as arguments to another rule.")}return new pexprs.Param(index)}else{this.args.forEach(function(arg,idx,args){args[idx]=arg.introduceParams(formals)});return this}}},{"./common":48,"./pexprs":67}],60:[function(require,module,exports){"use strict";var common=require("./common");var pexprs=require("./pexprs");pexprs.PExpr.prototype.isNullable=function(grammar){return this._isNullable(grammar,Object.create(null))};pexprs.PExpr.prototype._isNullable=common.abstract;pexprs.any._isNullable=pexprs.Range.prototype._isNullable=pexprs.Param.prototype._isNullable=pexprs.Plus.prototype._isNullable=pexprs.UnicodeChar.prototype._isNullable=function(grammar,memo){return false};pexprs.end._isNullable=function(grammar,memo){return true};pexprs.Terminal.prototype._isNullable=function(grammar,memo){if(typeof this.obj==="string"){return this.obj===""}else{return false}};pexprs.Alt.prototype._isNullable=function(grammar,memo){return this.terms.length===0||this.terms.some(function(term){return term._isNullable(grammar,memo)})};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;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,grammar
Lo:/[\u01AA-\u01AA]|[\u01BB-\u01BB]|[\u01BE-\u01C3]|[\u03F3-\u03F3]|[\u04C0-\u04C0]|[\u05D0-\u05EA]|[\u05F0-\u05F2]|[\u0621-\u063A]|[\u0641-\u064A]|[\u0671-\u06B7]|[\u06BA-\u06BE]|[\u06C0-\u06CE]|[\u06D0-\u06D3]|[\u06D5-\u06D5]|[\u0905-\u0939]|[\u093D-\u093D]|[\u0950-\u0950]|[\u0958-\u0961]|[\u0985-\u098C]|[\u098F-\u0990]|[\u0993-\u09A8]|[\u09AA-\u09B0]|[\u09B2-\u09B2]|[\u09B6-\u09B9]|[\u09DC-\u09DD]|[\u09DF-\u09E1]|[\u09F0-\u09F1]|[\u0A05-\u0A0A]|[\u0A0F-\u0A10]|[\u0A13-\u0A28]|[\u0A2A-\u0A30]|[\u0A32-\u0A33]|[\u0A35-\u0A36]|[\u0A38-\u0A39]|[\u0A59-\u0A5C]|[\u0A5E-\u0A5E]|[\u0A72-\u0A74]|[\u0A85-\u0A8B]|[\u0A8D-\u0A8D]|[\u0A8F-\u0A91]|[\u0A93-\u0AA8]|[\u0AAA-\u0AB0]|[\u0AB2-\u0AB3]|[\u0AB5-\u0AB9]|[\u0ABD-\u0ABD]|[\u0AD0-\u0AD0]|[\u0AE0-\u0AE0]|[\u0B05-\u0B0C]|[\u0B0F-\u0B10]|[\u0B13-\u0B28]|[\u0B2A-\u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uFB2A-\uFB36]|[\uFB38-\uFB3C]|[\uFB3E-\uFB3E]|[\uFB40-\uFB41]|[\uFB43-\uFB44]|[\uFB46-\uFBB1]|[\uFBD3-\uFD3D]|[\uFD50-\uFD8F]|[\uFD92-\uFDC7]|[\uFDF0-\uFDFB]|[\uFE70-\uFE72]|[\uFE74-\uFE74]|[\uFE76-\uFEFC]|[\uFF66-\uFF6F]|[\uFF71-\uFF9D]|[\uFFA0-\uFFBE]|[\uFFC2-\uFFC7]|[\uFFCA-\uFFCF]|[\uFFD2-\uFFD7]|[\uFFDA-\uFFDC]/,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-\u0A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