diff --git a/dist/syndicatecompiler.js b/dist/syndicatecompiler.js index 8413e32..a4cec80 100644 --- a/dist/syndicatecompiler.js +++ b/dist/syndicatecompiler.js @@ -10,7 +10,7 @@ var path = require('path'); var ohm = require('ohm-js'); var ES5 = require('./es5.js'); -var grammarSource = Buffer("Ly8gLSotIGphdmFzY3JpcHQgLSotCi8vIFN5bnRhY3RpYyBleHRlbnNpb25zIHRvIEVTNSBmb3IgU3luZGljYXRlL2pzLiBTZWUgY29tcGlsZXIuanMgZm9yCi8vIHRoZSByZXN0IG9mIHRoZSB0cmFuc2xhdG9yLgoKU3luZGljYXRlIDw6IEVTNSB7CiAgLy8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KICAvLyBFeHRlbnNpb25zIHRvIGV4cHJlc3Npb25zLgoKICBTdGF0ZW1lbnQKICAgICs9IEFjdG9yU3RhdGVtZW50CiAgICB8IERhdGFzcGFjZVN0YXRlbWVudAogICAgfCBBY3RvckZhY2V0U3RhdGVtZW50CiAgICB8IEFzc2VydGlvblR5cGVEZWNsYXJhdGlvblN0YXRlbWVudAogICAgfCBTZW5kTWVzc2FnZVN0YXRlbWVudAoKICBBY3RvclN0YXRlbWVudAogICAgPSBhY3RvciBDYWxsRXhwcmVzc2lvbiBCbG9jayAtLSB3aXRoQ29uc3RydWN0b3IKICAgIHwgYWN0b3IgQmxvY2sgICAgICAgICAgICAgICAgLS0gbm9Db25zdHJ1Y3RvcgoKICBEYXRhc3BhY2VTdGF0ZW1lbnQKICAgID0gZ3JvdW5kIGRhdGFzcGFjZSBpZGVudGlmaWVyPyBCbG9jayAtLSBncm91bmQKICAgIHwgZGF0YXNwYWNlIEJsb2NrICAgICAgICAgICAgICAgICAgICAtLSBub3JtYWwKCiAgQWN0b3JGYWNldFN0YXRlbWVudAogICAgPSBzdGF0ZSBGYWNldEJsb2NrIHVudGlsI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FydAogIGRhdGFzcGFjZSA9ICJkYXRhc3BhY2UiIH5pZGVudGlmaWVyUGFydAogIGRvbmUgPSAiZG9uZSIgfmlkZW50aWZpZXJQYXJ0CiAgZHVyaW5nID0gImR1cmluZyIgfmlkZW50aWZpZXJQYXJ0CiAgZm9yZXZlciA9ICJmb3JldmVyIiB+aWRlbnRpZmllclBhcnQKICBncm91bmQgPSAiZ3JvdW5kIiB+aWRlbnRpZmllclBhcnQKICBpbml0ID0gImluaXQiIH5pZGVudGlmaWVyUGFydAogIG1lc3NhZ2UgPSAibWVzc2FnZSIgfmlkZW50aWZpZXJQYXJ0CiAgbWV0YWxldmVsID0gIm1ldGFsZXZlbCIgfmlkZW50aWZpZXJQYXJ0CiAgb24gPSAib24iIH5pZGVudGlmaWVyUGFydAogIHJldHJhY3RlZCA9ICJyZXRyYWN0ZWQiIH5pZGVudGlmaWVyUGFydAogIHN0YXRlID0gInN0YXRlIiB+aWRlbnRpZmllclBhcnQKICB0eXBlID0gInR5cGUiIH5pZGVudGlmaWVyUGFydAogIHVudGlsID0gInVudGlsIiB+aWRlbnRpZmllclBhcnQKICB3aGVuID0gIndoZW4iIH5pZGVudGlmaWVyUGFydAp9Cg==","base64").toString(); var grammar = ohm.grammar(grammarSource, { ES5: ES5.grammar }); var semantics = grammar.extendSemantics(ES5.semantics); @@ -146,8 +146,8 @@ var modifiedSourceActions = { return '\n.addDoneBlock((function() ' + block.asES5 + '))'; }, - FacetSituation_assert: function(_assert, expr, _sc) { - return '\n.addAssertion(' + buildSubscription([expr], 'assert', 'pattern') + ')'; + FacetSituation_assert: function(_assert, expr, whenClause, _sc) { + return '\n.addAssertion(' + buildSubscription([expr], 'assert', 'pattern', whenClause) + ')'; }, FacetSituation_event: function(_on, eventPattern, block) { return buildOnEvent(false, @@ -174,6 +174,10 @@ var modifiedSourceActions = { '.completeBuild(); }'); }, + AssertWhenClause: function(_when, _lparen, expr, _rparen) { + return expr.asES5; + }, + FacetStateTransition_withContinuation: function(_case, eventPattern, block) { return buildCaseEvent(eventPattern, block.asES5); }, @@ -202,9 +206,13 @@ semantics.addAttribute('eventType', { FacetTransitionEventPattern_risingEdge: function (_lp, expr, _rp) { return 'risingEdge'; } }); -function buildSubscription(children, patchMethod, mode) { +function buildSubscription(children, patchMethod, mode, whenClause) { var fragments = []; + var hasWhenClause = (whenClause && (whenClause.numChildren === 1)); fragments.push('(function() { var _ = Syndicate.__; return '); + if (hasWhenClause) { + fragments.push('(' + whenClause.asES5 + ') ? '); + } if (patchMethod) { fragments.push('Syndicate.Patch.' + patchMethod + '('); } else { @@ -222,31 +230,34 @@ function buildSubscription(children, patchMethod, mode) { } else { fragments.push(' }'); } + if (hasWhenClause) { + fragments.push(' : Syndicate.Patch.emptyPatch'); + } fragments.push('; })'); return fragments.join(''); } semantics.addAttribute('subscription', { _default: function(children) { - return buildSubscription(children, 'sub', 'pattern'); + return buildSubscription(children, 'sub', 'pattern', null); } }); semantics.addAttribute('instantiatedSubscription', { _default: function(children) { - return buildSubscription(children, 'sub', 'instantiated'); + return buildSubscription(children, 'sub', 'instantiated', null); } }); semantics.addAttribute('instantiatedProjection', { _default: function(children) { - return buildSubscription(children, null, 'instantiated'); + return buildSubscription(children, null, 'instantiated', null); } }); semantics.addAttribute('projection', { _default: function(children) { - return buildSubscription(children, null, 'projection'); + return buildSubscription(children, null, 'projection', null); } }); diff --git a/dist/syndicatecompiler.min.js b/dist/syndicatecompiler.min.js index a59294a..c63d52d 100644 --- a/dist/syndicatecompiler.min.js +++ b/dist/syndicatecompiler.min.js @@ -1,4 +1,4 @@ -(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=kMaxLength()){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+kMaxLength().toString(16)+" bytes")}return length|0}function SlowBuffer(length){if(+length!=length){length=0}return Buffer.alloc(+length)}Buffer.isBuffer=function isBuffer(b){return!!(b!=null&&b._isBuffer)};Buffer.compare=function compare(a,b){if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b)){throw new TypeError("Arguments must be Buffers")}if(a===b)return 0;var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i>>1;case"base64":return base64ToBytes(string).length;default:if(loweredCase)return utf8ToBytes(string).length;encoding=(""+encoding).toLowerCase();loweredCase=true}}}Buffer.byteLength=byteLength;function slowToString(encoding,start,end){var loweredCase=false;if(start===undefined||start<0){start=0}if(start>this.length){return""}if(end===undefined||end>this.length){end=this.length}if(end<=0){return""}end>>>=0;start>>>=0;if(end<=start){return""}if(!encoding)encoding="utf8";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"binary":return binarySlice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}}Buffer.prototype._isBuffer=true;function swap(b,n,m){var i=b[n];b[n]=b[m];b[m]=i}Buffer.prototype.swap16=function swap16(){var len=this.length;if(len%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var i=0;i0){str=this.toString("hex",0,max).match(/.{2}/g).join(" ");if(this.length>max)str+=" ... "}return""};Buffer.prototype.compare=function compare(target,start,end,thisStart,thisEnd){if(!Buffer.isBuffer(target)){throw new TypeError("Argument must be a Buffer")}if(start===undefined){start=0}if(end===undefined){end=target?target.length:0}if(thisStart===undefined){thisStart=0}if(thisEnd===undefined){thisEnd=this.length}if(start<0||end>target.length||thisStart<0||thisEnd>this.length){throw new RangeError("out of range index")}if(thisStart>=thisEnd&&start>=end){return 0}if(thisStart>=thisEnd){return-1}if(start>=end){return 1}start>>>=0;end>>>=0;thisStart>>>=0;thisEnd>>>=0;if(this===target)return 0;var x=thisEnd-thisStart;var y=end-start;var len=Math.min(x,y);var thisCopy=this.slice(thisStart,thisEnd);var targetCopy=target.slice(start,end);for(var i=0;i2147483647){byteOffset=2147483647}else if(byteOffset<-2147483648){byteOffset=-2147483648}byteOffset>>=0;if(this.length===0)return-1;if(byteOffset>=this.length)return-1;if(byteOffset<0)byteOffset=Math.max(this.length+byteOffset,0);if(typeof val==="string"){val=Buffer.from(val,encoding)}if(Buffer.isBuffer(val)){if(val.length===0){return-1}return arrayIndexOf(this,val,byteOffset,encoding)}if(typeof val==="number"){if(Buffer.TYPED_ARRAY_SUPPORT&&Uint8Array.prototype.indexOf==="function"){return Uint8Array.prototype.indexOf.call(this,val,byteOffset)}return arrayIndexOf(this,[val],byteOffset,encoding)}throw new TypeError("val must be string, number or Buffer")};Buffer.prototype.includes=function includes(val,byteOffset,encoding){return this.indexOf(val,byteOffset,encoding)!==-1};function hexWrite(buf,string,offset,length){offset=Number(offset)||0;var remaining=buf.length-offset;if(!length){length=remaining}else{length=Number(length);if(length>remaining){length=remaining}}var strLen=string.length;if(strLen%2!==0)throw new Error("Invalid hex string");if(length>strLen/2){length=strLen/2}for(var i=0;iremaining)length=remaining;if(string.length>0&&(length<0||offset<0)||offset>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!encoding)encoding="utf8";var loweredCase=false;for(;;){switch(encoding){case"hex":return hexWrite(this,string,offset,length);case"utf8":case"utf-8":return utf8Write(this,string,offset,length);case"ascii":return asciiWrite(this,string,offset,length);case"binary":return binaryWrite(this,string,offset,length);case"base64":return base64Write(this,string,offset,length);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,string,offset,length);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(""+encoding).toLowerCase();loweredCase=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){end=Math.min(buf.length,end);var res=[];var i=start;while(i239?4:firstByte>223?3:firstByte>191?2:1;if(i+bytesPerSequence<=end){var secondByte,thirdByte,fourthByte,tempCodePoint;switch(bytesPerSequence){case 1:if(firstByte<128){codePoint=firstByte}break;case 2:secondByte=buf[i+1];if((secondByte&192)===128){tempCodePoint=(firstByte&31)<<6|secondByte&63;if(tempCodePoint>127){codePoint=tempCodePoint}}break;case 3:secondByte=buf[i+1];thirdByte=buf[i+2];if((secondByte&192)===128&&(thirdByte&192)===128){tempCodePoint=(firstByte&15)<<12|(secondByte&63)<<6|thirdByte&63;if(tempCodePoint>2047&&(tempCodePoint<55296||tempCodePoint>57343)){codePoint=tempCodePoint}}break;case 4:secondByte=buf[i+1];thirdByte=buf[i+2];fourthByte=buf[i+3];if((secondByte&192)===128&&(thirdByte&192)===128&&(fourthByte&192)===128){tempCodePoint=(firstByte&15)<<18|(secondByte&63)<<12|(thirdByte&63)<<6|fourthByte&63;if(tempCodePoint>65535&&tempCodePoint<1114112){codePoint=tempCodePoint}}}}if(codePoint===null){codePoint=65533;bytesPerSequence=1}else if(codePoint>65535){codePoint-=65536;res.push(codePoint>>>10&1023|55296);codePoint=56320|codePoint&1023}res.push(codePoint);i+=bytesPerSequence}return decodeCodePointsArray(res)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(codePoints){var len=codePoints.length;if(len<=MAX_ARGUMENTS_LENGTH){return String.fromCharCode.apply(String,codePoints)}var res="";var i=0;while(ilen)end=len;var out="";for(var i=start;ilen){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(endlength)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(offset,byteLength,noAssert){offset=offset|0;byteLength=byteLength|0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i0&&(mul*=256)){val+=this[offset+--byteLength]*mul}return val};Buffer.prototype.readUInt8=function readUInt8(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function readUInt16LE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function readIntLE(offset,byteLength,noAssert){offset=offset|0;byteLength=byteLength|0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function readIntBE(offset,byteLength,noAssert){offset=offset|0;byteLength=byteLength|0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256)){val+=this[offset+--i]*mul}mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function readInt8(offset,noAssert){if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function readInt16BE(offset,noAssert){if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function readInt32LE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function readFloatLE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(offset,noAssert){if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(offset,noAssert){if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError('"buffer" argument must be a Buffer instance');if(value>max||valuebuf.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset|0;byteLength=byteLength|0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var mul=1;var i=0;this[offset]=value&255;while(++i=0&&(mul*=256)){this[offset+i]=value/mul&255}return offset+byteLength};Buffer.prototype.writeUInt8=function writeUInt8(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,1,255,0);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);this[offset]=value&255;return offset+1};function objectWriteUInt16(buf,value,offset,littleEndian){if(value<0)value=65535+value+1;for(var i=0,j=Math.min(buf.length-offset,2);i>>(littleEndian?i:1-i)*8}}Buffer.prototype.writeUInt16LE=function writeUInt16LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value&255;this[offset+1]=value>>>8}else{objectWriteUInt16(this,value,offset,true)}return offset+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,65535,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value&255}else{objectWriteUInt16(this,value,offset,false)}return offset+2};function objectWriteUInt32(buf,value,offset,littleEndian){if(value<0)value=4294967295+value+1;for(var i=0,j=Math.min(buf.length-offset,4);i>>(littleEndian?i:3-i)*8&255}}Buffer.prototype.writeUInt32LE=function writeUInt32LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value&255}else{objectWriteUInt32(this,value,offset,true)}return offset+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255}else{objectWriteUInt32(this,value,offset,false)}return offset+4};Buffer.prototype.writeIntLE=function writeIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset|0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=0;var mul=1;var sub=0;this[offset]=value&255;while(++i>0)-sub&255}return offset+byteLength};Buffer.prototype.writeIntBE=function writeIntBE(value,offset,byteLength,noAssert){value=+value;offset=offset|0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=byteLength-1;var mul=1;var sub=0;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){if(value<0&&sub===0&&this[offset+i+1]!==0){sub=1}this[offset+i]=(value/mul>>0)-sub&255}return offset+byteLength};Buffer.prototype.writeInt8=function writeInt8(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(!Buffer.TYPED_ARRAY_SUPPORT)value=Math.floor(value);if(value<0)value=255+value+1;this[offset]=value&255;return offset+1};Buffer.prototype.writeInt16LE=function writeInt16LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value&255;this[offset+1]=value>>>8}else{objectWriteUInt16(this,value,offset,true)}return offset+2};Buffer.prototype.writeInt16BE=function writeInt16BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>8;this[offset+1]=value&255}else{objectWriteUInt16(this,value,offset,false)}return offset+2};Buffer.prototype.writeInt32LE=function writeInt32LE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value&255;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24}else{objectWriteUInt32(this,value,offset,true)}return offset+4};Buffer.prototype.writeInt32BE=function writeInt32BE(value,offset,noAssert){value=+value;offset=offset|0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;if(Buffer.TYPED_ARRAY_SUPPORT){this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255}else{objectWriteUInt32(this,value,offset,false)}return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(offset+ext>buf.length)throw new RangeError("Index out of range");if(offset<0)throw new RangeError("Index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){if(!noAssert){checkIEEE754(buf,value,offset,4,3.4028234663852886e38,-3.4028234663852886e38)}ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function writeFloatLE(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function writeFloatBE(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){if(!noAssert){checkIEEE754(buf,value,offset,8,1.7976931348623157e308,-1.7976931348623157e308)}ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function copy(target,targetStart,start,end){if(!start)start=0;if(!end&&end!==0)end=this.length;if(targetStart>=target.length)targetStart=target.length;if(!targetStart)targetStart=0;if(end>0&&end=this.length)throw new RangeError("sourceStart out of bounds");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-targetStart=0;i--){target[i+targetStart]=this[i+start]}}else if(len<1e3||!Buffer.TYPED_ARRAY_SUPPORT){for(i=0;i>>0;end=end===undefined?this.length:end>>>0;if(!val)val=0;var i;if(typeof val==="number"){for(i=start;i55295&&codePoint<57344){if(!leadSurrogate){if(codePoint>56319){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>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=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;i0){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>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;ilen2?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<>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<>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<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--){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=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;i1){for(var i=1;i\n = NonemptyListOf\n | EmptyListOf\n\n NonemptyListOf\n = elem (sep elem)*\n\n EmptyListOf\n = /* nothing */\n\n listOf\n = nonemptyListOf\n | emptyListOf\n\n nonemptyListOf\n = elem (sep elem)*\n\n emptyListOf\n = /* nothing */\n\n}');return decl.define("alnum",[],this.alt(this.app("letter").withInterval(decl.sourceInterval(60,66)),this.app("digit").withInterval(decl.sourceInterval(73,78))).withInterval(decl.sourceInterval(60,78)),"an alpha-numeric character").define("letter",[],this.alt(this.app("lower").withInterval(decl.sourceInterval(107,112)),this.app("upper").withInterval(decl.sourceInterval(119,124)),this.app("unicodeLtmo").withInterval(decl.sourceInterval(131,142))).withInterval(decl.sourceInterval(107,142)),"a letter").define("digit",[],this.range("0","9").withInterval(decl.sourceInterval(169,177)),"a digit").define("hexDigit",[],this.alt(this.app("digit").withInterval(decl.sourceInterval(219,224)),this.range("a","f").withInterval(decl.sourceInterval(231,239)),this.range("A","F").withInterval(decl.sourceInterval(246,254))).withInterval(decl.sourceInterval(219,254)),"a hexadecimal digit").define("ListOf",["elem","sep"],this.alt(this.app("NonemptyListOf",[this.param(0),this.param(1)]).withInterval(decl.sourceInterval(282,307)),this.app("EmptyListOf",[this.param(0),this.param(1)]).withInterval(decl.sourceInterval(314,336))).withInterval(decl.sourceInterval(282,336))).define("NonemptyListOf",["elem","sep"],this.seq(this.param(0),this.star(this.seq(this.param(1),this.param(0)).withInterval(decl.sourceInterval(378,386))).withInterval(decl.sourceInterval(377,388))).withInterval(decl.sourceInterval(372,388))).define("EmptyListOf",["elem","sep"],this.seq().withInterval(decl.sourceInterval(438,438))).define("listOf",["elem","sep"],this.alt(this.app("nonemptyListOf",[this.param(0),this.param(1)]).withInterval(decl.sourceInterval(462,487)),this.app("emptyListOf",[this.param(0),this.param(1)]).withInterval(decl.sourceInterval(494,516))).withInterval(decl.sourceInterval(462,516))).define("nonemptyListOf",["elem","sep"],this.seq(this.param(0),this.star(this.seq(this.param(1),this.param(0)).withInterval(decl.sourceInterval(558,566))).withInterval(decl.sourceInterval(557,568))).withInterval(decl.sourceInterval(552,568))).define("emptyListOf",["elem","sep"],this.seq().withInterval(decl.sourceInterval(616,616))).build()})},{"..":50}],11:[function(require,module,exports){var ohm=require("..");module.exports=ohm.makeRecipe(function(){var decl=this.newGrammar("Ohm").withSource('Ohm {\n\n Grammars\n = Grammar*\n\n Grammar\n = ident SuperGrammar? "{" Rule* "}"\n\n SuperGrammar\n = "<:" ident\n\n Rule\n = ident Formals? ruleDescr? "=" "|"? Alt -- define\n | ident Formals? ":=" "|"? Alt -- override\n | ident Formals? "+=" "|"? Alt -- extend\n\n Formals\n = "<" ListOf ">"\n\n Params\n = "<" ListOf ">"\n\n Alt\n = Term ("|" Term)*\n\n Term\n = Seq caseName -- inline\n | Seq\n\n Seq\n = Iter*\n\n Iter\n = Pred "*" -- star\n | Pred "+" -- plus\n | Pred "?" -- opt\n | Pred\n\n Pred\n = "~" Modifier -- not\n | "&" Modifier -- lookahead\n | Modifier\n\n Modifier\n = "#" Base -- lex\n | "$" Base -- val\n | Base\n\n Base\n = ident Params? ~(ruleDescr? "=" | ":=" | "+=") -- application\n | Prim ".." Prim -- range\n | Prim -- prim\n | "(" Alt ")" -- paren\n | "[" Alt "]" -- arr\n | "{" "..."? "}" -- obj\n | "{" Props ("," "...")? "}" -- objWithProps\n\n Prim\n = keyword\n | string\n | number\n\n Props\n = Prop ("," Prop)*\n\n Prop\n = (name | string) ":" Alt\n\n ruleDescr (a rule description)\n = "(" ruleDescrText ")"\n\n ruleDescrText\n = (~")" any)*\n\n caseName\n = "--" (~"\\n" space)* name (~"\\n" space)* ("\\n" | &"}")\n\n name (a name)\n = nameFirst nameRest*\n\n nameFirst\n = "_"\n | letter\n\n nameRest\n = "_"\n | alnum\n\n ident (an identifier)\n = ~keyword name\n\n keyword\n = "null" ~nameRest -- null\n | "true" ~nameRest -- true\n | "false" ~nameRest -- false\n\n string\n = "\\"" strChar* "\\""\n\n strChar\n = escapeChar\n | ~"\\\\" ~"\\"" ~"\\n" any\n\n escapeChar (an escape sequence)\n = "\\\\\\\\" -- backslash\n | "\\\\\\"" -- doubleQuote\n | "\\\\\\\'" -- singleQuote\n | "\\\\b" -- backspace\n | "\\\\n" -- lineFeed\n | "\\\\r" -- carriageReturn\n | "\\\\t" -- tab\n | "\\\\u" hexDigit hexDigit hexDigit hexDigit -- unicodeEscape\n | "\\\\x" hexDigit hexDigit -- hexEscape\n\n number (a number)\n = "-"? digit+\n\n space\n += comment\n\n comment\n = "//" (~"\\n" any)* "\\n" -- singleLine\n | "/*" (~"*/" any)* "*/" -- multiLine\n\n tokens = token*\n\n token = caseName | comment | ident | keyword | number | operator | punctuation | string | any\n\n operator = "<:" | "=" | ":=" | "+=" | "*" | "+" | "?" | "~" | "&"\n\n punctuation = "<" | ">" | "," | "--"\n}').withDefaultStartRule("Grammars");return decl.define("Grammars",[],this.star(this.app("Grammar").withInterval(decl.sourceInterval(24,31))).withInterval(decl.sourceInterval(24,32))).define("Grammar",[],this.seq(this.app("ident").withInterval(decl.sourceInterval(50,55)),this.opt(this.app("SuperGrammar").withInterval(decl.sourceInterval(56,68))).withInterval(decl.sourceInterval(56,69)),this.prim("{").withInterval(decl.sourceInterval(70,73)),this.star(this.app("Rule").withInterval(decl.sourceInterval(74,78))).withInterval(decl.sourceInterval(74,79)),this.prim("}").withInterval(decl.sourceInterval(80,83))).withInterval(decl.sourceInterval(50,83))).define("SuperGrammar",[],this.seq(this.prim("<:").withInterval(decl.sourceInterval(106,110)),this.app("ident").withInterval(decl.sourceInterval(111,116))).withInterval(decl.sourceInterval(106,116))).define("Rule_define",[],this.seq(this.app("ident").withInterval(decl.sourceInterval(131,136)),this.opt(this.app("Formals").withInterval(decl.sourceInterval(137,144))).withInterval(decl.sourceInterval(137,145)),this.opt(this.app("ruleDescr").withInterval(decl.sourceInterval(146,155))).withInterval(decl.sourceInterval(146,156)),this.prim("=").withInterval(decl.sourceInterval(157,160)),this.opt(this.prim("|").withInterval(decl.sourceInterval(162,165))).withInterval(decl.sourceInterval(162,166)),this.app("Alt").withInterval(decl.sourceInterval(167,170))).withInterval(decl.sourceInterval(131,170))).define("Rule_override",[],this.seq(this.app("ident").withInterval(decl.sourceInterval(188,193)),this.opt(this.app("Formals").withInterval(decl.sourceInterval(194,201))).withInterval(decl.sourceInterval(194,202)),this.prim(":=").withInterval(decl.sourceInterval(214,218)),this.opt(this.prim("|").withInterval(decl.sourceInterval(219,222))).withInterval(decl.sourceInterval(219,223)),this.app("Alt").withInterval(decl.sourceInterval(224,227))).withInterval(decl.sourceInterval(188,227))).define("Rule_extend",[],this.seq(this.app("ident").withInterval(decl.sourceInterval(247,252)),this.opt(this.app("Formals").withInterval(decl.sourceInterval(253,260))).withInterval(decl.sourceInterval(253,261)),this.prim("+=").withInterval(decl.sourceInterval(273,277)),this.opt(this.prim("|").withInterval(decl.sourceInterval(278,281))).withInterval(decl.sourceInterval(278,282)),this.app("Alt").withInterval(decl.sourceInterval(283,286))).withInterval(decl.sourceInterval(247,286))).define("Rule",[],this.alt(this.app("Rule_define").withInterval(decl.sourceInterval(131,170)),this.app("Rule_override").withInterval(decl.sourceInterval(188,227)),this.app("Rule_extend").withInterval(decl.sourceInterval(247,286))).withInterval(decl.sourceInterval(131,297))).define("Formals",[],this.seq(this.prim("<").withInterval(decl.sourceInterval(315,318)),this.app("ListOf",[this.app("ident").withInterval(decl.sourceInterval(326,331)),this.prim(",").withInterval(decl.sourceInterval(333,336))]).withInterval(decl.sourceInterval(319,337)),this.prim(">").withInterval(decl.sourceInterval(338,341))).withInterval(decl.sourceInterval(315,341))).define("Params",[],this.seq(this.prim("<").withInterval(decl.sourceInterval(358,361)),this.app("ListOf",[this.app("Seq").withInterval(decl.sourceInterval(369,372)),this.prim(",").withInterval(decl.sourceInterval(374,377))]).withInterval(decl.sourceInterval(362,378)),this.prim(">").withInterval(decl.sourceInterval(379,382))).withInterval(decl.sourceInterval(358,382))).define("Alt",[],this.seq(this.app("Term").withInterval(decl.sourceInterval(396,400)),this.star(this.seq(this.prim("|").withInterval(decl.sourceInterval(402,405)),this.app("Term").withInterval(decl.sourceInterval(406,410))).withInterval(decl.sourceInterval(402,410))).withInterval(decl.sourceInterval(401,412))).withInterval(decl.sourceInterval(396,412))).define("Term_inline",[],this.seq(this.app("Seq").withInterval(decl.sourceInterval(427,430)),this.app("caseName").withInterval(decl.sourceInterval(431,439))).withInterval(decl.sourceInterval(427,439))).define("Term",[],this.alt(this.app("Term_inline").withInterval(decl.sourceInterval(427,439)),this.app("Seq").withInterval(decl.sourceInterval(456,459))).withInterval(decl.sourceInterval(427,459))).define("Seq",[],this.star(this.app("Iter").withInterval(decl.sourceInterval(473,477))).withInterval(decl.sourceInterval(473,478))).define("Iter_star",[],this.seq(this.app("Pred").withInterval(decl.sourceInterval(493,497)),this.prim("*").withInterval(decl.sourceInterval(498,501))).withInterval(decl.sourceInterval(493,501))).define("Iter_plus",[],this.seq(this.app("Pred").withInterval(decl.sourceInterval(517,521)),this.prim("+").withInterval(decl.sourceInterval(522,525))).withInterval(decl.sourceInterval(517,525))).define("Iter_opt",[],this.seq(this.app("Pred").withInterval(decl.sourceInterval(541,545)),this.prim("?").withInterval(decl.sourceInterval(546,549))).withInterval(decl.sourceInterval(541,549))).define("Iter",[],this.alt(this.app("Iter_star").withInterval(decl.sourceInterval(493,501)),this.app("Iter_plus").withInterval(decl.sourceInterval(517,525)),this.app("Iter_opt").withInterval(decl.sourceInterval(541,549)),this.app("Pred").withInterval(decl.sourceInterval(564,568))).withInterval(decl.sourceInterval(493,568))).define("Pred_not",[],this.seq(this.prim("~").withInterval(decl.sourceInterval(583,586)),this.app("Modifier").withInterval(decl.sourceInterval(587,595))).withInterval(decl.sourceInterval(583,595))).define("Pred_lookahead",[],this.seq(this.prim("&").withInterval(decl.sourceInterval(610,613)),this.app("Modifier").withInterval(decl.sourceInterval(614,622))).withInterval(decl.sourceInterval(610,622))).define("Pred",[],this.alt(this.app("Pred_not").withInterval(decl.sourceInterval(583,595)),this.app("Pred_lookahead").withInterval(decl.sourceInterval(610,622)),this.app("Modifier").withInterval(decl.sourceInterval(643,651))).withInterval(decl.sourceInterval(583,651))).define("Modifier_lex",[],this.seq(this.prim("#").withInterval(decl.sourceInterval(670,673)),this.app("Base").withInterval(decl.sourceInterval(674,678))).withInterval(decl.sourceInterval(670,678))).define("Modifier_val",[],this.seq(this.prim("$").withInterval(decl.sourceInterval(693,696)),this.app("Base").withInterval(decl.sourceInterval(697,701))).withInterval(decl.sourceInterval(693,701))).define("Modifier",[],this.alt(this.app("Modifier_lex").withInterval(decl.sourceInterval(670,678)),this.app("Modifier_val").withInterval(decl.sourceInterval(693,701)),this.app("Base").withInterval(decl.sourceInterval(716,720))).withInterval(decl.sourceInterval(670,720))).define("Base_application",[],this.seq(this.app("ident").withInterval(decl.sourceInterval(735,740)),this.opt(this.app("Params").withInterval(decl.sourceInterval(741,747))).withInterval(decl.sourceInterval(741,748)),this.not(this.alt(this.seq(this.opt(this.app("ruleDescr").withInterval(decl.sourceInterval(751,760))).withInterval(decl.sourceInterval(751,761)),this.prim("=").withInterval(decl.sourceInterval(762,765))).withInterval(decl.sourceInterval(751,765)),this.prim(":=").withInterval(decl.sourceInterval(768,772)),this.prim("+=").withInterval(decl.sourceInterval(775,779))).withInterval(decl.sourceInterval(751,779))).withInterval(decl.sourceInterval(749,780))).withInterval(decl.sourceInterval(735,780))).define("Base_range",[],this.seq(this.app("Prim").withInterval(decl.sourceInterval(803,807)),this.prim("..").withInterval(decl.sourceInterval(808,812)),this.app("Prim").withInterval(decl.sourceInterval(813,817))).withInterval(decl.sourceInterval(803,817))).define("Base_prim",[],this.app("Prim").withInterval(decl.sourceInterval(865,869))).define("Base_paren",[],this.seq(this.prim("(").withInterval(decl.sourceInterval(926,929)),this.app("Alt").withInterval(decl.sourceInterval(930,933)),this.prim(")").withInterval(decl.sourceInterval(934,937))).withInterval(decl.sourceInterval(926,937))).define("Base_arr",[],this.seq(this.prim("[").withInterval(decl.sourceInterval(988,991)),this.app("Alt").withInterval(decl.sourceInterval(992,995)),this.prim("]").withInterval(decl.sourceInterval(996,999))).withInterval(decl.sourceInterval(988,999))).define("Base_obj",[],this.seq(this.prim("{").withInterval(decl.sourceInterval(1048,1051)),this.opt(this.prim("...").withInterval(decl.sourceInterval(1052,1057))).withInterval(decl.sourceInterval(1052,1058)),this.prim("}").withInterval(decl.sourceInterval(1059,1062))).withInterval(decl.sourceInterval(1048,1062))).define("Base_objWithProps",[],this.seq(this.prim("{").withInterval(decl.sourceInterval(1108,1111)),this.app("Props").withInterval(decl.sourceInterval(1112,1117)),this.opt(this.seq(this.prim(",").withInterval(decl.sourceInterval(1119,1122)),this.prim("...").withInterval(decl.sourceInterval(1123,1128))).withInterval(decl.sourceInterval(1119,1128))).withInterval(decl.sourceInterval(1118,1130)),this.prim("}").withInterval(decl.sourceInterval(1131,1134))).withInterval(decl.sourceInterval(1108,1134))).define("Base",[],this.alt(this.app("Base_application").withInterval(decl.sourceInterval(735,780)),this.app("Base_range").withInterval(decl.sourceInterval(803,817)),this.app("Base_prim").withInterval(decl.sourceInterval(865,869)),this.app("Base_paren").withInterval(decl.sourceInterval(926,937)),this.app("Base_arr").withInterval(decl.sourceInterval(988,999)),this.app("Base_obj").withInterval(decl.sourceInterval(1048,1062)),this.app("Base_objWithProps").withInterval(decl.sourceInterval(1108,1134))).withInterval(decl.sourceInterval(735,1170))).define("Prim",[],this.alt(this.app("keyword").withInterval(decl.sourceInterval(1185,1192)),this.app("string").withInterval(decl.sourceInterval(1199,1205)),this.app("number").withInterval(decl.sourceInterval(1212,1218))).withInterval(decl.sourceInterval(1185,1218))).define("Props",[],this.seq(this.app("Prop").withInterval(decl.sourceInterval(1234,1238)),this.star(this.seq(this.prim(",").withInterval(decl.sourceInterval(1240,1243)),this.app("Prop").withInterval(decl.sourceInterval(1244,1248))).withInterval(decl.sourceInterval(1240,1248))).withInterval(decl.sourceInterval(1239,1250))).withInterval(decl.sourceInterval(1234,1250))).define("Prop",[],this.seq(this.alt(this.app("name").withInterval(decl.sourceInterval(1266,1270)),this.app("string").withInterval(decl.sourceInterval(1273,1279))).withInterval(decl.sourceInterval(1266,1279)),this.prim(":").withInterval(decl.sourceInterval(1281,1284)),this.app("Alt").withInterval(decl.sourceInterval(1285,1288))).withInterval(decl.sourceInterval(1265,1288))).define("ruleDescr",[],this.seq(this.prim("(").withInterval(decl.sourceInterval(1330,1333)),this.app("ruleDescrText").withInterval(decl.sourceInterval(1334,1347)),this.prim(")").withInterval(decl.sourceInterval(1348,1351))).withInterval(decl.sourceInterval(1330,1351)),"a rule description").define("ruleDescrText",[],this.star(this.seq(this.not(this.prim(")").withInterval(decl.sourceInterval(1377,1380))).withInterval(decl.sourceInterval(1376,1380)),this.app("any").withInterval(decl.sourceInterval(1381,1384))).withInterval(decl.sourceInterval(1376,1384))).withInterval(decl.sourceInterval(1375,1386))).define("caseName",[],this.seq(this.prim("--").withInterval(decl.sourceInterval(1405,1409)),this.star(this.seq(this.not(this.prim("\n").withInterval(decl.sourceInterval(1412,1416))).withInterval(decl.sourceInterval(1411,1416)),this.app("space").withInterval(decl.sourceInterval(1417,1422))).withInterval(decl.sourceInterval(1411,1422))).withInterval(decl.sourceInterval(1410,1424)),this.app("name").withInterval(decl.sourceInterval(1425,1429)),this.star(this.seq(this.not(this.prim("\n").withInterval(decl.sourceInterval(1432,1436))).withInterval(decl.sourceInterval(1431,1436)),this.app("space").withInterval(decl.sourceInterval(1437,1442))).withInterval(decl.sourceInterval(1431,1442))).withInterval(decl.sourceInterval(1430,1444)),this.alt(this.prim("\n").withInterval(decl.sourceInterval(1446,1450)),this.la(this.prim("}").withInterval(decl.sourceInterval(1454,1457))).withInterval(decl.sourceInterval(1453,1457))).withInterval(decl.sourceInterval(1446,1457))).withInterval(decl.sourceInterval(1405,1458))).define("name",[],this.seq(this.app("nameFirst").withInterval(decl.sourceInterval(1483,1492)),this.star(this.app("nameRest").withInterval(decl.sourceInterval(1493,1501))).withInterval(decl.sourceInterval(1493,1502))).withInterval(decl.sourceInterval(1483,1502)),"a name").define("nameFirst",[],this.alt(this.prim("_").withInterval(decl.sourceInterval(1522,1525)),this.app("letter").withInterval(decl.sourceInterval(1532,1538))).withInterval(decl.sourceInterval(1522,1538))).define("nameRest",[],this.alt(this.prim("_").withInterval(decl.sourceInterval(1557,1560)),this.app("alnum").withInterval(decl.sourceInterval(1567,1572))).withInterval(decl.sourceInterval(1557,1572))).define("ident",[],this.seq(this.not(this.app("keyword").withInterval(decl.sourceInterval(1606,1613))).withInterval(decl.sourceInterval(1605,1613)),this.app("name").withInterval(decl.sourceInterval(1614,1618))).withInterval(decl.sourceInterval(1605,1618)),"an identifier").define("keyword_null",[],this.seq(this.prim("null").withInterval(decl.sourceInterval(1636,1642)),this.not(this.app("nameRest").withInterval(decl.sourceInterval(1644,1652))).withInterval(decl.sourceInterval(1643,1652))).withInterval(decl.sourceInterval(1636,1652))).define("keyword_true",[],this.seq(this.prim("true").withInterval(decl.sourceInterval(1669,1675)),this.not(this.app("nameRest").withInterval(decl.sourceInterval(1677,1685))).withInterval(decl.sourceInterval(1676,1685))).withInterval(decl.sourceInterval(1669,1685))).define("keyword_false",[],this.seq(this.prim("false").withInterval(decl.sourceInterval(1702,1709)),this.not(this.app("nameRest").withInterval(decl.sourceInterval(1711,1719))).withInterval(decl.sourceInterval(1710,1719))).withInterval(decl.sourceInterval(1702,1719))).define("keyword",[],this.alt(this.app("keyword_null").withInterval(decl.sourceInterval(1636,1652)),this.app("keyword_true").withInterval(decl.sourceInterval(1669,1685)),this.app("keyword_false").withInterval(decl.sourceInterval(1702,1719))).withInterval(decl.sourceInterval(1636,1729))).define("string",[],this.seq(this.prim('"').withInterval(decl.sourceInterval(1746,1750)),this.star(this.app("strChar").withInterval(decl.sourceInterval(1751,1758))).withInterval(decl.sourceInterval(1751,1759)),this.prim('"').withInterval(decl.sourceInterval(1760,1764))).withInterval(decl.sourceInterval(1746,1764))).define("strChar",[],this.alt(this.app("escapeChar").withInterval(decl.sourceInterval(1782,1792)),this.seq(this.not(this.prim("\\").withInterval(decl.sourceInterval(1800,1804))).withInterval(decl.sourceInterval(1799,1804)),this.not(this.prim('"').withInterval(decl.sourceInterval(1806,1810))).withInterval(decl.sourceInterval(1805,1810)),this.not(this.prim("\n").withInterval(decl.sourceInterval(1812,1816))).withInterval(decl.sourceInterval(1811,1816)),this.app("any").withInterval(decl.sourceInterval(1817,1820))).withInterval(decl.sourceInterval(1799,1820))).withInterval(decl.sourceInterval(1782,1820))).define("escapeChar_backslash",[],this.prim("\\\\").withInterval(decl.sourceInterval(1863,1869))).define("escapeChar_doubleQuote",[],this.prim('\\"').withInterval(decl.sourceInterval(1925,1931))).define("escapeChar_singleQuote",[],this.prim("\\'").withInterval(decl.sourceInterval(1989,1995))).define("escapeChar_backspace",[],this.prim("\\b").withInterval(decl.sourceInterval(2053,2058))).define("escapeChar_lineFeed",[],this.prim("\\n").withInterval(decl.sourceInterval(2115,2120))).define("escapeChar_carriageReturn",[],this.prim("\\r").withInterval(decl.sourceInterval(2176,2181))).define("escapeChar_tab",[],this.prim("\\t").withInterval(decl.sourceInterval(2243,2248))).define("escapeChar_unicodeEscape",[],this.seq(this.prim("\\u").withInterval(decl.sourceInterval(2299,2304)),this.app("hexDigit").withInterval(decl.sourceInterval(2305,2313)),this.app("hexDigit").withInterval(decl.sourceInterval(2314,2322)),this.app("hexDigit").withInterval(decl.sourceInterval(2323,2331)),this.app("hexDigit").withInterval(decl.sourceInterval(2332,2340))).withInterval(decl.sourceInterval(2299,2340))).define("escapeChar_hexEscape",[],this.seq(this.prim("\\x").withInterval(decl.sourceInterval(2365,2370)),this.app("hexDigit").withInterval(decl.sourceInterval(2371,2379)),this.app("hexDigit").withInterval(decl.sourceInterval(2380,2388))).withInterval(decl.sourceInterval(2365,2388))).define("escapeChar",[],this.alt(this.app("escapeChar_backslash").withInterval(decl.sourceInterval(1863,1869)),this.app("escapeChar_doubleQuote").withInterval(decl.sourceInterval(1925,1931)),this.app("escapeChar_singleQuote").withInterval(decl.sourceInterval(1989,1995)),this.app("escapeChar_backspace").withInterval(decl.sourceInterval(2053,2058)),this.app("escapeChar_lineFeed").withInterval(decl.sourceInterval(2115,2120)),this.app("escapeChar_carriageReturn").withInterval(decl.sourceInterval(2176,2181)),this.app("escapeChar_tab").withInterval(decl.sourceInterval(2243,2248)),this.app("escapeChar_unicodeEscape").withInterval(decl.sourceInterval(2299,2340)),this.app("escapeChar_hexEscape").withInterval(decl.sourceInterval(2365,2388))).withInterval(decl.sourceInterval(1863,2420)),"an escape sequence").define("number",[],this.seq(this.opt(this.prim("-").withInterval(decl.sourceInterval(2449,2452))).withInterval(decl.sourceInterval(2449,2453)),this.plus(this.app("digit").withInterval(decl.sourceInterval(2454,2459))).withInterval(decl.sourceInterval(2454,2460))).withInterval(decl.sourceInterval(2449,2460)),"a number").extend("space",[],this.app("comment").withInterval(decl.sourceInterval(2476,2483))).define("comment_singleLine",[],this.seq(this.prim("//").withInterval(decl.sourceInterval(2501,2505)),this.star(this.seq(this.not(this.prim("\n").withInterval(decl.sourceInterval(2508,2512))).withInterval(decl.sourceInterval(2507,2512)),this.app("any").withInterval(decl.sourceInterval(2513,2516))).withInterval(decl.sourceInterval(2507,2516))).withInterval(decl.sourceInterval(2506,2518)),this.prim("\n").withInterval(decl.sourceInterval(2519,2523))).withInterval(decl.sourceInterval(2501,2523))).define("comment_multiLine",[],this.seq(this.prim("/*").withInterval(decl.sourceInterval(2545,2549)),this.star(this.seq(this.not(this.prim("*/").withInterval(decl.sourceInterval(2552,2556))).withInterval(decl.sourceInterval(2551,2556)),this.app("any").withInterval(decl.sourceInterval(2557,2560))).withInterval(decl.sourceInterval(2551,2560))).withInterval(decl.sourceInterval(2550,2562)),this.prim("*/").withInterval(decl.sourceInterval(2563,2567))).withInterval(decl.sourceInterval(2545,2567))).define("comment",[],this.alt(this.app("comment_singleLine").withInterval(decl.sourceInterval(2501,2523)),this.app("comment_multiLine").withInterval(decl.sourceInterval(2545,2567))).withInterval(decl.sourceInterval(2501,2581))).define("tokens",[],this.star(this.app("token").withInterval(decl.sourceInterval(2594,2599))).withInterval(decl.sourceInterval(2594,2600))).define("token",[],this.alt(this.app("caseName").withInterval(decl.sourceInterval(2612,2620)),this.app("comment").withInterval(decl.sourceInterval(2623,2630)),this.app("ident").withInterval(decl.sourceInterval(2633,2638)),this.app("keyword").withInterval(decl.sourceInterval(2641,2648)),this.app("number").withInterval(decl.sourceInterval(2651,2657)),this.app("operator").withInterval(decl.sourceInterval(2660,2668)),this.app("punctuation").withInterval(decl.sourceInterval(2671,2682)),this.app("string").withInterval(decl.sourceInterval(2685,2691)),this.app("any").withInterval(decl.sourceInterval(2694,2697))).withInterval(decl.sourceInterval(2612,2697))).define("operator",[],this.alt(this.prim("<:").withInterval(decl.sourceInterval(2712,2716)),this.prim("=").withInterval(decl.sourceInterval(2719,2722)),this.prim(":=").withInterval(decl.sourceInterval(2725,2729)),this.prim("+=").withInterval(decl.sourceInterval(2732,2736)),this.prim("*").withInterval(decl.sourceInterval(2739,2742)),this.prim("+").withInterval(decl.sourceInterval(2745,2748)),this.prim("?").withInterval(decl.sourceInterval(2751,2754)),this.prim("~").withInterval(decl.sourceInterval(2757,2760)),this.prim("&").withInterval(decl.sourceInterval(2763,2766))).withInterval(decl.sourceInterval(2712,2766))).define("punctuation",[],this.alt(this.prim("<").withInterval(decl.sourceInterval(2784,2787)),this.prim(">").withInterval(decl.sourceInterval(2790,2793)),this.prim(",").withInterval(decl.sourceInterval(2796,2799)),this.prim("--").withInterval(decl.sourceInterval(2802,2806))).withInterval(decl.sourceInterval(2784,2806))).build(); })},{"..":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 ")"\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.prim("(").withInterval(decl.sourceInterval(118,121)),this.app("ListOf",[this.app("name").withInterval(decl.sourceInterval(129,133)),this.prim(",").withInterval(decl.sourceInterval(135,138))]).withInterval(decl.sourceInterval(122,139)),this.prim(")").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.prim("_").withInterval(decl.sourceInterval(207,210)),this.app("letter").withInterval(decl.sourceInterval(217,223))).withInterval(decl.sourceInterval(207,223))).define("nameRest",[],this.alt(this.prim("_").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 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":69,"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;value=dscr;dscr=null}else{options=arguments[2]}if(dscr==null){c=w=true;e=false}else{c=contains.call(dscr,"c");e=contains.call(dscr,"e");w=contains.call(dscr,"w")}desc={value:value,configurable:c,enumerable:e,writable:w};return!options?desc:assign(normalizeOpts(options),desc)};d.gs=function(dscr,get,set){var c,e,options,desc;if(typeof dscr!=="string"){options=set;set=get;get=dscr;dscr=null}else{options=arguments[3]}if(get==null){get=undefined}else if(!isCallable(get)){options=get;get=set=undefined}else if(set==null){set=undefined}else if(!isCallable(set)){options=set;set=undefined}if(dscr==null){c=true;e=false}else{c=contains.call(dscr,"c");e=contains.call(dscr,"e")}desc={get:get,set:set,configurable:c,enumerable:e};return!options?desc:assign(normalizeOpts(options),desc)}},{"es5-ext/object/assign":19,"es5-ext/object/is-callable":22,"es5-ext/object/normalize-options":26,"es5-ext/string/#/contains":28}],19:[function(require,module,exports){"use strict";module.exports=require("./is-implemented")()?Object.assign:require("./shim")},{"./is-implemented":20,"./shim":21}],20:[function(require,module,exports){"use strict";module.exports=function(){var assign=Object.assign,obj;if(typeof assign!=="function")return false;obj={foo:"raz"};assign(obj,{bar:"dwa"},{trzy:"trzy"});return obj.foo+obj.bar+obj.trzy==="razdwatrzy"}},{}],21:[function(require,module,exports){"use strict";var keys=require("../keys"),value=require("../valid-value"),max=Math.max;module.exports=function(dest,src){var error,i,l=max(arguments.length,2),assign;dest=Object(value(dest));assign=function(key){try{dest[key]=src[key]}catch(e){if(!error)error=e}};for(i=1;i-1}},{}],31:[function(require,module,exports){"use strict";var d=require("d"),validateSymbol=require("./validate-symbol"),create=Object.create,defineProperties=Object.defineProperties,defineProperty=Object.defineProperty,objPrototype=Object.prototype,Symbol,HiddenSymbol,globalSymbols=create(null);var generateName=function(){var created=create(null);return function(desc){var postfix=0,name;while(created[desc+(postfix||"")])++postfix;desc+=postfix||"";created[desc]=true;name="@@"+desc;defineProperty(objPrototype,name,d.gs(null,function(value){defineProperty(this,name,d(value))}));return name}}();HiddenSymbol=function Symbol(description){if(this instanceof HiddenSymbol)throw new TypeError("TypeError: Symbol is not a constructor");return Symbol(description)};module.exports=Symbol=function Symbol(description){var symbol;if(this instanceof Symbol)throw new TypeError("TypeError: Symbol is not a constructor");symbol=create(HiddenSymbol.prototype);description=description===undefined?"":String(description);return defineProperties(symbol,{__description__:d("",description),__name__:d("",generateName(description))})};defineProperties(Symbol,{"for":d(function(key){if(globalSymbols[key])return globalSymbols[key];return globalSymbols[key]=Symbol(String(key))}),keyFor:d(function(s){var key;validateSymbol(s);for(key in globalSymbols)if(globalSymbols[key]===s)return key}),hasInstance:d("",Symbol("hasInstance")),isConcatSpreadable:d("",Symbol("isConcatSpreadable")),iterator:d("",Symbol("iterator")),match:d("",Symbol("match")),replace:d("",Symbol("replace")),search:d("",Symbol("search")),species:d("",Symbol("species")),split:d("",Symbol("split")),toPrimitive:d("",Symbol("toPrimitive")),toStringTag:d("",Symbol("toStringTag")),unscopables:d("",Symbol("unscopables"))});defineProperties(HiddenSymbol.prototype,{constructor:d(Symbol),toString:d("",function(){return this.__name__})});defineProperties(Symbol.prototype,{toString:d(function(){return"Symbol ("+validateSymbol(this).__description__+")"}),valueOf:d(function(){return validateSymbol(this)})});defineProperty(Symbol.prototype,Symbol.toPrimitive,d("",function(){return validateSymbol(this)}));defineProperty(Symbol.prototype,Symbol.toStringTag,d("c","Symbol"));defineProperty(HiddenSymbol.prototype,Symbol.toPrimitive,d("c",Symbol.prototype[Symbol.toPrimitive]));defineProperty(HiddenSymbol.prototype,Symbol.toStringTag,d("c",Symbol.prototype[Symbol.toStringTag]))},{"./validate-symbol":32,d:18}],32:[function(require,module,exports){"use strict";var isSymbol=require("./is-symbol");module.exports=function(value){if(!isSymbol(value))throw new TypeError(value+" is not a symbol");return value}},{"./is-symbol":17}],33:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],34:[function(require,module,exports){module.exports=function(obj){return!!(obj!=null&&obj.constructor&&typeof obj.constructor.isBuffer==="function"&&obj.constructor.isBuffer(obj))}},{}],35:[function(require,module,exports){module.exports=extend;function extend(origin,add){if(!add||typeof add!=="object")return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin}},{}],36:[function(require,module,exports){"use strict";var GrammarDecl=require("./GrammarDecl");var pexprs=require("./pexprs");function Builder(){}Builder.prototype={newGrammar:function(name){return new GrammarDecl(name)},prim:function(x){return new pexprs.Prim(x)},range:function(from,to){return new pexprs.Range(from,to)},param:function(index){return new pexprs.Param(index)},alt:function(){var terms=[];for(var idx=0;idx0){return state.bindings[0]}return null},createConstructors:function(){var self=this;var constructors={};function makeConstructor(ruleName){return function(){return self.construct(ruleName,Array.prototype.slice.call(arguments))}}for(var ruleName in this.ruleBodies){constructors[ruleName]=makeConstructor(ruleName)}return constructors},isBuiltIn:function(){return this===Grammar.ProtoBuiltInRules||this===Grammar.BuiltInRules},_match:function(values,opts){var state=new State(this,values,opts);state.evalFromStart();return state},match:function(obj,optStartApplication){var state=this._match([obj],{startApplication:optStartApplication});return MatchResult.newFor(state)},trace:function(obj,optStartApplication){var state=this._match([obj],{startApplication:optStartApplication,trace:true});var rootTrace=state.trace[state.trace.length-1];rootTrace.state=state;rootTrace.result=MatchResult.newFor(state);return rootTrace},semantics:function(){return Semantics.createSemantics(this)},extendSemantics:function(superSemantics){return Semantics.createSemantics(this,superSemantics._getSemantics())},_checkTopDownActionDict:function(what,name,actionDict){function isSpecialAction(a){return a==="_iter"||a==="_terminal"||a==="_nonterminal"||a==="_default"}var problems=[];for(var k in actionDict){var v=actionDict[k];if(!isSpecialAction(k)&&!(k in this.ruleBodies)){problems.push("'"+k+"' is not a valid semantic action for '"+this.name+"'")}else if(typeof v!=="function"){problems.push("'"+k+"' must be a function in an action dictionary for '"+this.name+"'")}else{var actual=v.length;var expected=this._topDownActionArity(k);if(actual!==expected){problems.push("Semantic action '"+k+"' has the wrong arity: "+"expected "+expected+", got "+actual)}}}if(problems.length>0){var prettyProblems=problems.map(function(problem){return"- "+problem});var error=new Error("Found errors in the action dictionary of the '"+name+"' "+what+":\n"+prettyProblems.join("\n"));error.problems=problems;throw error}},_topDownActionArity:function(actionName){if(actionName==="_iter"||actionName==="_nonterminal"||actionName==="_default"){return 1}else if(actionName==="_terminal"){return 0}return this.ruleBodies[actionName].getArity()},_inheritsFrom:function(grammar){var g=this.superGrammar;while(g){if(g===grammar){return true}g=g.superGrammar}return false},toRecipe:function(optVarName){if(this.isBuiltIn()){throw new Error("Why would anyone want to generate a recipe for the "+this.name+" grammar?!?!")}var sb=new common.StringBuffer;if(optVarName){sb.append("var "+optVarName+" = ")}sb.append("(function() {\n");var superGrammarDecl="";if(!this.superGrammar.isBuiltIn()){sb.append(this.superGrammar.toRecipe("buildSuperGrammar"));superGrammarDecl=" .withSuperGrammar(buildSuperGrammar.call(this))\n"}sb.append(" var decl = this.newGrammar("+JSON.stringify(this.name)+")\n");if(this.definitionInterval){sb.append(" .withSource("+JSON.stringify(this.definitionInterval.contents)+")\n")}sb.append(superGrammarDecl);if(this.defaultStartRule){sb.append(' .withDefaultStartRule("'+this.defaultStartRule+'")\n')}sb.append(" return decl\n");var self=this;Object.keys(this.ruleBodies).forEach(function(ruleName){var body=self.ruleBodies[ruleName];sb.append(" .");if(self.superGrammar.ruleBodies[ruleName]){sb.append(body instanceof pexprs.Extend?"extend":"override")}else{sb.append("define")}var formals=self.ruleFormals[ruleName];var formalsString="["+formals.map(JSON.stringify).join(", ")+"]";sb.append("("+JSON.stringify(ruleName)+", "+formalsString+", ");body.outputRecipe(sb,formals,self.definitionInterval);if(!self.superGrammar.ruleBodies[ruleName]&&self.ruleDescriptions[ruleName]){sb.append(", "+JSON.stringify(self.ruleDescriptions[ruleName]))}sb.append(")\n")});sb.append(" .build();\n});\n");return sb.contents()},toOperationActionDictionaryTemplate:function(){return this._toOperationOrAttributeActionDictionaryTemplate()},toAttributeActionDictionaryTemplate:function(){return this._toOperationOrAttributeActionDictionaryTemplate()},_toOperationOrAttributeActionDictionaryTemplate:function(){var sb=new common.StringBuffer;sb.append("{");var first=true;for(var ruleName in this.ruleBodies){var body=this.ruleBodies[ruleName];if(first){first=false}else{sb.append(",")}sb.append("\n");sb.append(" ");this.addSemanticActionTemplate(ruleName,body,sb)}sb.append("\n}");return sb.contents()},addSemanticActionTemplate:function(ruleName,body,sb){sb.append(ruleName);sb.append(": function(");var arity=this._topDownActionArity(ruleName);sb.append(common.repeat("_",arity).join(", "));sb.append(") {\n");sb.append(" }")},parseApplication:function(str){var app;if(str.indexOf("<")===-1){app=new pexprs.Apply(str)}else{var cst=ohmGrammar.match(str,"Base_application");app=buildGrammar(cst,{})}if(!(app.ruleName in this.ruleBodies)){throw errors.undeclaredRule(app.ruleName,this.name)}else if(this.ruleFormals[app.ruleName].length!==app.args.length){throw errors.wrongNumberOfParameters(app.ruleName,this.ruleFormals[app.ruleName].length,app.args.length)}return app}};Grammar.ProtoBuiltInRules=new Grammar("ProtoBuiltInRules",undefined,{any:pexprs.any,end:pexprs.end,spaces:new pexprs.Star(new pexprs.Apply("space")),space:new pexprs.Range("\x00"," "),lower:new pexprs.UnicodeChar("Ll"),upper:new pexprs.UnicodeChar("Lu"),unicodeLtmo:new pexprs.UnicodeChar("Ltmo")},{any:[],end:[],spaces:[],space:[],lower:[],upper:[],unicodeLtmo:[]},{any:"any object",end:"end of input",space:"a space",lower:"a lowercase letter",upper:"an uppercase letter"});module.exports=Grammar},{"./MatchResult":42,"./Semantics":45,"./State":46,"./common":48,"./errors":49,"./pexprs":69}],39:[function(require,module,exports){"use strict";var Grammar=require("./Grammar");var InputStream=require("./InputStream");var common=require("./common");var errors=require("./errors");var pexprs=require("./pexprs");function GrammarDecl(name){this.name=name}GrammarDecl.prototype.sourceInterval=function(startIdx,endIdx){var inputStream=this.interval.inputStream;return inputStream.interval(startIdx,endIdx)};GrammarDecl.prototype.ensureSuperGrammar=function(){if(!this.superGrammar){this.withSuperGrammar(this.name==="BuiltInRules"?Grammar.ProtoBuiltInRules:Grammar.BuiltInRules)}return this.superGrammar};GrammarDecl.prototype.installOverriddenOrExtendedRule=function(name,formals,body){var duplicateParameterNames=common.getDuplicates(formals);if(duplicateParameterNames.length>0){throw errors.duplicateParameterNames(name,duplicateParameterNames,body)}var expectedFormals=this.ensureSuperGrammar().ruleFormals[name];var expectedNumFormals=expectedFormals?expectedFormals.length:0;if(formals.length!==expectedNumFormals){throw errors.wrongNumberOfParameters(name,expectedNumFormals,formals.length,body)}return this.install(name,formals,body)};GrammarDecl.prototype.install=function(name,formals,body,optDescription){body=body.introduceParams(formals);this.ruleFormals[name]=formals;if(optDescription){this.ruleDescriptions[name]=optDescription}this.ruleBodies[name]=body;return this};GrammarDecl.prototype.withSuperGrammar=function(superGrammar){if(this.superGrammar){throw new Error("the super grammar of a GrammarDecl cannot be set more than once")}this.superGrammar=superGrammar;this.ruleBodies=Object.create(superGrammar.ruleBodies);this.ruleFormals=Object.create(superGrammar.ruleFormals);this.ruleDescriptions=Object.create(superGrammar.ruleDescriptions);if(!superGrammar.isBuiltIn()){this.defaultStartRule=superGrammar.defaultStartRule}return this};GrammarDecl.prototype.withDefaultStartRule=function(ruleName){this.defaultStartRule=ruleName;return this};GrammarDecl.prototype.withSource=function(source){this.interval=InputStream.newFor(source).interval(0,source.length);return this};GrammarDecl.prototype.build=function(){var grammar=new Grammar(this.name,this.ensureSuperGrammar(),this.ruleBodies,this.ruleFormals,this.ruleDescriptions,this.defaultStartRule);var grammarErrors=[];var grammarHasInvalidApplications=false;Object.keys(grammar.ruleBodies).forEach(function(ruleName){var body=grammar.ruleBodies[ruleName];try{body.assertChoicesHaveUniformArity(ruleName)}catch(e){grammarErrors.push(e)}try{body.assertAllApplicationsAreValid(ruleName,grammar)}catch(e){grammarErrors.push(e);grammarHasInvalidApplications=true}});if(!grammarHasInvalidApplications){Object.keys(grammar.ruleBodies).forEach(function(ruleName){var body=grammar.ruleBodies[ruleName];try{body.assertIteratedExprsAreNotNullable(grammar,ruleName)}catch(e){grammarErrors.push(e)}if(grammar.ruleFormals[ruleName].length===0){try{body.assertValuesAndStringsAreNotMixed(grammar,ruleName)}catch(e){grammarErrors.push(e)}}})}if(grammarErrors.length>0){errors.throwErrors(grammarErrors)}if(this.interval){grammar.definitionInterval=this.interval}return grammar};GrammarDecl.prototype.define=function(name,formals,body,optDescr){this.ensureSuperGrammar();if(this.superGrammar.ruleBodies[name]){throw errors.duplicateRuleDeclaration(name,this.name,this.superGrammar.name,body)}else if(this.ruleBodies[name]){throw errors.duplicateRuleDeclaration(name,this.name,this.name,body)}var duplicateParameterNames=common.getDuplicates(formals);if(duplicateParameterNames.length>0){throw errors.duplicateParameterNames(name,duplicateParameterNames,body)}return this.install(name,formals,body,optDescr)};GrammarDecl.prototype.override=function(name,formals,body){var baseRule=this.ensureSuperGrammar().ruleBodies[name];if(!baseRule){throw errors.cannotOverrideUndeclaredRule(name,this.superGrammar.name,body)}this.installOverriddenOrExtendedRule(name,formals,body);return this};GrammarDecl.prototype.extend=function(name,formals,fragment){var baseRule=this.ensureSuperGrammar().ruleBodies[name];if(!baseRule){throw errors.cannotExtendUndeclaredRule(name,this.superGrammar.name,fragment)}var body=new pexprs.Extend(this.superGrammar,name,fragment);body.interval=fragment.interval;this.installOverriddenOrExtendedRule(name,formals,body);return this};module.exports=GrammarDecl},{"./Grammar":38,"./InputStream":40,"./common":48,"./errors":49,"./pexprs":69}],40:[function(require,module,exports){"use strict";var inherits=require("inherits");var common=require("./common");var Interval=require("./Interval");function InputStream(){throw new Error("InputStream cannot be instantiated -- it's abstract")}InputStream.newFor=function(arrOrStr){return Array.isArray(arrOrStr)?new ListInputStream(arrOrStr):new StringInputStream(arrOrStr)};InputStream.prototype={init:function(source){this.source=source;this.pos=0;this.posInfos=[]},atEnd:function(){return this.pos===this.source.length},next:function(){if(this.atEnd()){return common.fail}else{return this.source[this.pos++]}},matchExactly:function(x){return this.next()===x?true:common.fail},sourceSlice:function(startIdx,endIdx){return this.source.slice(startIdx,endIdx)},interval:function(startIdx,optEndIdx){return new Interval(this,startIdx,optEndIdx?optEndIdx:this.pos)}};function StringInputStream(source){this.init(source)}inherits(StringInputStream,InputStream);StringInputStream.prototype.matchString=function(s){for(var idx=0;idx=that.startIdx&&this.endIdx<=that.endIdx,"other interval does not cover this one");return new Interval(newInputStream,this.startIdx-that.startIdx,this.endIdx-that.startIdx)},trimmed:function(){var contents=this.contents;var startIdx=this.startIdx+contents.match(/^\s*/)[0].length;var endIdx=this.endIdx-contents.match(/\s*$/)[0].length;return new Interval(this.inputStream,startIdx,endIdx)}};Object.defineProperties(Interval.prototype,{contents:{get:function(){if(this._contents===undefined){this._contents=this.inputStream.sourceSlice(this.startIdx,this.endIdx)}return this._contents},enumerable:true}});module.exports=Interval},{"./common":48,"./errors":49,"./util":70}],42:[function(require,module,exports){"use strict";var inherits=require("inherits");var common=require("./common");var nodes=require("./nodes");var util=require("./util");var Interval=require("./Interval");function getShortMatchErrorMessage(pos,source,detail){var errorInfo=util.getLineAndColumn(source,pos);return"Line "+errorInfo.lineNum+", col "+errorInfo.colNum+": "+detail}function MatchResult(state){this.state=state;this._cst=state.bindings[0]}MatchResult.newFor=function(state){var succeeded=state.bindings.length>0;return succeeded?new MatchResult(state):new MatchFailure(state)};MatchResult.prototype.failed=function(){return false};MatchResult.prototype.succeeded=function(){return!this.failed()};MatchResult.prototype.getDiscardedSpaces=function(){if(this.failed()){ diff --git a/examples/iot/index.html b/examples/iot/index.html index 0397cc5..3a862a8 100644 --- a/examples/iot/index.html +++ b/examples/iot/index.html @@ -19,7 +19,7 @@

TV

-  
+  
    diff --git a/examples/iot/index.js b/examples/iot/index.js index b6d56de..d1ddf1c 100644 --- a/examples/iot/index.js +++ b/examples/iot/index.js @@ -14,28 +14,9 @@ var jQueryEvent = Syndicate.JQuery.jQueryEvent; function spawnTV() { actor { - this.alerts = []; - this.alertFragment = ["ul"]; - - this.computeDisplay = function () { - var self = this; // omg javascript - this.alertFragment = ["ul"]; - this.alerts.forEach(function (t) { - self.alertFragment.push(["li", t]); - }); - }; - forever { - assert DOM('#tv', 'alerts', Syndicate.seal(this.alertFragment)); - - on asserted tvAlert($text) { - this.alerts.push(text); - this.computeDisplay(); - } - - on retracted tvAlert($text) { - this.alerts = this.alerts.filter(function (t) { return t !== text; }); - this.computeDisplay(); + during tvAlert($text) { + assert DOM('#tv', 'alert', Syndicate.seal(["li", text])); } } } @@ -140,7 +121,6 @@ function spawnClock() { } function spawnTimeoutListener() { - var message = tvAlert('Stove on too long?'); actor { this.mostRecentTime = 0; this.powerOnTime = null; @@ -151,12 +131,9 @@ function spawnTimeoutListener() { } on message time($now) { this.mostRecentTime = now; - if (this.powerOnTime !== null && this.mostRecentTime - this.powerOnTime > 3000) { - Syndicate.Dataspace.stateChange(Syndicate.assert(message)); - } else { - Syndicate.Dataspace.stateChange(Syndicate.retract(message)); - } } + assert tvAlert('Stove on too long?') + when (this.powerOnTime !== null && this.mostRecentTime - this.powerOnTime > 3000); } } } @@ -165,17 +142,14 @@ function spawnTimeoutListener() { // Failure monitor function spawnFailureMonitor() { - function messageFor(who) { - return tvAlert('FAILURE: ' + who); - } - actor { forever { - on asserted componentPresent($who) { - Syndicate.Dataspace.stateChange(Syndicate.retract(messageFor(who))); - } on retracted componentPresent($who) { - Syndicate.Dataspace.stateChange(Syndicate.assert(messageFor(who))); + state { + assert tvAlert('FAILURE: ' + who); + } until { + case asserted componentPresent(who); + } } } }