@gram-data/gram-format
Advanced tools
Comparing version 0.1.13 to 0.1.14
@@ -8,2 +8,3 @@ 'use strict'; | ||
var nearley = require('nearley'); | ||
var moo = _interopDefault(require('moo')); | ||
var Option = require('fp-ts/lib/Option'); | ||
@@ -626,4 +627,2 @@ var baseX = _interopDefault(require('base-x')); | ||
var moo = /*#__PURE__*/require('moo'); | ||
var lexer = /*#__PURE__*/moo.compile({ | ||
@@ -630,0 +629,0 @@ whitespace: { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("nearley"),n=require("fp-ts/lib/Option"),r=(e=require("base-x"))&&"object"==typeof e&&"default"in e?e.default:e,i=require("unist-util-visit"),o=function(e){var t={path:{count:0,identifiers:new Set,labels:new Set},node:{count:0,identifiers:new Set,labels:new Set},relationship:{count:0,identifiers:new Set,labels:new Set},properties:{}},n=function(e){for(var n=0,r=Object.entries(e);n<r.length;n++){var i=r[n],o=i[0],a=i[1],s=Array.isArray(a)?"Array<"+a[0].type+">":"type"in a&&"string"==typeof a.type?a.type:"record";t.properties[o]=s}};return i(e,(function(e){switch(e.type){case"gram":break;case"path":t.path.count++;break;case"node":t.node.count++,e.id&&t.node.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.node.labels.add(e)})),e.record&&n(e.record);break;case"edge":t.relationship.count++,e.id&&t.relationship.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.relationship.labels.add(e)})),e.record&&n(e.record)}})),t},a={reportError:function(e,t){var n=t.token;if(void 0===n)return t.message;var r=[],i=(n.type?n.type+" token: ":"")+JSON.stringify(void 0!==n.value?n.value:n);return r.push(e.lexer.formatError(n,"Syntax error")),r.push("Unexpected "+i+". Instead, I was expecting to see one of the following:\n"),e.table[e.table.length-2].states.filter((function(e){var t=e.rule.symbols[e.dot];return t&&"string"!=typeof t})).map((function(e){return function e(t,n){return-1!==n.indexOf(t)?[]:0===t.wantedBy.length?[[t]]:t.wantedBy.reduce((function(r,i){return r.concat(e(i,[t].concat(n)).map((function(e){return[t].concat(e)})))}),[])}(e,[])[0]}),this).forEach((function(t){var n=t[0],i=e.getSymbolDisplay(n.rule.symbols[n.dot]);r.push("A "+i)}),this),r.push(""),r.join("\n")}},s=function(e){return!!e.type&&"node"===e.type},c=function(e){return!!e.type&&!!e.value},l={__proto__:null,isGram:function(e){return!!e.type&&"gram"===e.type},isPath:function(e){return!!e.type&&"path"===e.type},isNode:s,isEdge:function(e){return!!e.type&&!!e.direction&&"edge"===e.type},isLiteral:c,isBooleanLiteral:function(e){return!!e.type&&!!e.value&&"boolean"===e.type},isStringLiteral:function(e){return!!e.type&&!!e.value&&"string"===e.type},isTaggedLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type},isIntegerLiteral:function(e){return!!e.type&&!!e.value&&"integer"===e.type},isUnitLiteral:function(e){return!!e.type&&!!e.value&&!!e.unit&&"unit"===e.type},isDecimalLiteral:function(e){return!!e.type&&!!e.value&&"decimal"===e.type},isHexadecimalLiteral:function(e){return!!e.type&&!!e.value&&"hexadecimal"===e.type},isOctalLiteral:function(e){return!!e.type&&!!e.value&&"octal"===e.type},isDateLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"date"===e.tag},isGeospatialLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"geo"===e.tag}},u=function(e){switch(e.type){case"integer":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";default:return"<ERROR, can't stringify literals of type "+e.type+">"}},p=function(e){return"{"+Object.entries(e).map((function(e,t){return(t>0?",":"")+e[0]+":"+(n=e[1],Array.isArray(n)?"["+n.map((function(e){return u(e)})).join(",")+"]":c(n)?u(n):p(n));var n})).join("")+"}"},f=function(e){var t=e.id||"",n=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",r=e.record&&0!==Object.keys(e.record).length?p(e.record):"";return""+t+n+(r.length>0?" ":"")+r},d=function(e){return"("+f(e)+")"},m=function e(t){var n="left"===t.direction?"<-":"-",r="right"===t.direction?"->":"-",i=d(t.children[0]),o="node"===t.children[1].type?d(t.children[1]):e(t.children[1]),a=f(t);return""+i+n+(a.length>0?"["+a+"]":"")+r+o},b=function e(t){switch(t.type){case"gram":return t.children.map(e).join("\n");case"path":return function(e){var t=f(e),n=e.children[0],r=n?""+("node"===n.type?d(n):m(n)):"";return t.length>0?"["+t+" "+r+"]":r}(t);case"node":return d(t);case"edge":return m(t);default:console.error("Impossible:",typeof t)}return[].join("")};function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function g(e){return Array.isArray(e)?e:e instanceof Function?g(e()):void 0===e?[]:[e]}var h=function(e){return e.toISOString().slice(0,10)},$=function(e,t,n){return y({type:"node"},e&&{id:e},t&&{labels:t},n&&{record:n})},v=function(e,t){return{type:"tagged",value:t,tag:e}},S={gram:function(e,t,n,r){return void 0===n&&(n=[]),y({type:"gram"},t&&{id:t},{labels:n},r&&{record:r},{children:g(e)})},path:function(e,t,n,r){return y({type:"path"},t&&{id:t},{labels:n},r&&{record:r},{children:e?[e]:[]})},node:$,edge:function(e,t,n,r,i){return void 0===t&&(t="right"),y({type:"edge"},n&&{id:n},r&&{labels:r},i&&{record:i},{direction:t,children:e})},record:function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},property:function(e,t){return{type:"property",name:e,value:t}},boolean:function(e){return{type:"boolean",value:e?"true":"false"}},string:function(e){return{type:"string",value:e}},tagged:v,integer:function(e){return{type:"integer",value:String(e)}},decimal:function(e){return{type:"decimal",value:String(e)}},hexadecimal:function(e){return{type:"hexadecimal",value:e}},octal:function(e){return{type:"octal",value:e}},unit:function(e,t){return{type:"unit",value:String(t),unit:e}},date:function(e){return v(e instanceof Date?h(e):e,"date")},time:function(e){return v(e instanceof Date?h(e):e,"time")},flatten:function(e,t){return void 0===t&&(t=1),e.flat(t)}},L={boolean:/true|false|TRUE|FALSE\b/,hexadecimal:/-?0x(?:[0-9a-fA-F]+)\b/,octal:/-?0(?:[0-7]+)\b/,unit:/-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?[a-zA-Z]+\b/,decimal:/-?(?:[0-9]|[1-9][0-9]+)\.[0-9]+(?:[eE][-+]?[0-9]+)?\b/,integer:/-?(?:[0-9]|[1-9][0-9]+)(?:[eE][-+]?[0-9]+)?\b/,taggedString:/[a-zA-Z][0-9a-zA-Z_@]*`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,doubleQuotedString:/"(?:\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/,singleQuotedString:/'(?:\\['bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^'\\])*'/,tickedString:/`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,identifier:/[a-zA-Z_][0-9a-zA-Z_]*/},x={RE:L};function E(e){return e[0]}var P=require("moo").compile({whitespace:{match:/\s+/,lineBreaks:!0},lineComment:{match:/\/\/.*?$/},hexadecimal:L.hexadecimal,octal:L.octal,unit:L.unit,decimal:L.decimal,integer:L.integer,taggedString:{match:L.taggedString},doubleQuotedString:{match:L.doubleQuotedString,value:function(e){return e.slice(1,-1)}},singleQuotedString:{match:L.singleQuotedString,value:function(e){return e.slice(1,-1)}},tickedString:{match:L.tickedString,value:function(e){return e.slice(1,-1)}},boolean:["true","TRUE","True","false","FALSE","False"],identifier:L.identifier,"--\x3e":"--\x3e","--":"--","<--":"<--","-[]->":"-[]->","-[]-":"-[]-","<-[]-":"<-[]-","<-[":"<-[","]->":"]->","-[":"-[","]-":"]-","{":"{","}":"}","[":"[","]":"]","(":"(",")":")",",":",",":":":","`":"`","'":"'"}),C=function(){return null},_={Lexer:P,ParserRules:[{name:"Gram$ebnf$1",symbols:["Block"]},{name:"Gram$ebnf$1",symbols:["Gram$ebnf$1","Block"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Gram",symbols:["Gram$ebnf$1"],postprocess:function(e){return S.gram(S.flatten(e))}},{name:"Block",symbols:["PathPattern","_"],postprocess:function(e){return e[0]}},{name:"Block",symbols:["Comment"],postprocess:C},{name:"PathPattern$ebnf$1",symbols:["EdgePattern"],postprocess:E},{name:"PathPattern$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"PathPattern",symbols:[{literal:"["},"_","ContentSpecification","_","PathPattern$ebnf$1",{literal:"]"}],postprocess:function(e){var t=e[2];return S.path(e[4]||[],t.id,t.labels,t.record)}},{name:"PathPattern",symbols:["EdgePattern"],postprocess:function(e){return S.path(e[0])}},{name:"NodePattern",symbols:[{literal:"("},"_","ContentSpecification",{literal:")"}],postprocess:function(e){var t=e[2];return S.node(t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern","EdgeSpecification","EdgePattern"],postprocess:function(e){var t=e[1];return S.edge([e[0],e[2]],t.direction,t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern"],postprocess:E},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]->"}],postprocess:function(e){return y({direction:"right"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return y({direction:"none"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"<-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return y({direction:"left"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-[]->"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"-[]-"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<-[]-"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:"--\x3e"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"--"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<--"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:","}],postprocess:function(){return{direction:"pair"}}},{name:"ContentSpecification$ebnf$1",symbols:["SymbolicName"],postprocess:E},{name:"ContentSpecification$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$2",symbols:["LabelList"],postprocess:E},{name:"ContentSpecification$ebnf$2",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$3",symbols:["Record"],postprocess:E},{name:"ContentSpecification$ebnf$3",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification",symbols:["ContentSpecification$ebnf$1","_","ContentSpecification$ebnf$2","_","ContentSpecification$ebnf$3"],postprocess:function(e){return{id:e[0],labels:e[2],record:e[4]}}},{name:"LabelList$ebnf$1",symbols:["Label"]},{name:"LabelList$ebnf$1",symbols:["LabelList$ebnf$1","Label"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"LabelList",symbols:["LabelList$ebnf$1"],postprocess:function(e){return e[0]}},{name:"Label",symbols:[{literal:":"},"SymbolicName"],postprocess:function(e){return e[1]}},{name:"SymbolicName",symbols:[P.has("identifier")?{type:"identifier"}:identifier],postprocess:function(e){return e[0].text}},{name:"SymbolicName",symbols:[P.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return e[0].text.slice(1,-1)}},{name:"Record",symbols:[{literal:"{"},"_",{literal:"}"}],postprocess:C},{name:"Record$ebnf$1",symbols:[]},{name:"Record$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Property"]},{name:"Record$ebnf$1",symbols:["Record$ebnf$1","Record$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Record",symbols:[{literal:"{"},"_","Property","Record$ebnf$1",{literal:"}"}],postprocess:function(e){return S.record([e[2]].concat(e[3].map((function(e){return e[3]}))))}},{name:"Property",symbols:["Key","_",{literal:":"},"_","Value"],postprocess:function(e){return S.property(e[0],e[4])}},{name:"Key",symbols:["SymbolicName"],postprocess:E},{name:"Value",symbols:["StringLiteral"],postprocess:E},{name:"Value",symbols:["NumericLiteral"],postprocess:E},{name:"Value",symbols:[P.has("boolean")?{type:"boolean"}:boolean],postprocess:function(e){return S.boolean(JSON.parse(e[0].value.toLowerCase()))}},{name:"Value$ebnf$1",symbols:[]},{name:"Value$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Value"]},{name:"Value$ebnf$1",symbols:["Value$ebnf$1","Value$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Value",symbols:[{literal:"["},"_","Value","Value$ebnf$1",{literal:"]"}],postprocess:function(e){return[e[2]].concat(e[3].map((function(e){return e[3]})))}},{name:"StringLiteral",symbols:[P.has("singleQuotedString")?{type:"singleQuotedString"}:singleQuotedString],postprocess:function(e){return S.string(e[0].value)}},{name:"StringLiteral",symbols:[P.has("doubleQuotedString")?{type:"doubleQuotedString"}:doubleQuotedString],postprocess:function(e){return S.string(e[0].value)}},{name:"StringLiteral",symbols:[P.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return S.string(e[0].value)}},{name:"StringLiteral",symbols:[P.has("taggedString")?{type:"taggedString"}:taggedString],postprocess:function(e){var t=function(e){var t=e.match(/([^`]+)`(.+)`$/);if(null==t)throw Error("Malformed tagged string: "+e);return{tag:t[1],value:t[2]}}(e[0].value);return S.tagged(t.tag,t.value)}},{name:"NumericLiteral",symbols:[P.has("integer")?{type:"integer"}:integer],postprocess:function(e){return S.integer(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("decimal")?{type:"decimal"}:decimal],postprocess:function(e){return S.decimal(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("hexadecimal")?{type:"hexadecimal"}:hexadecimal],postprocess:function(e){return S.hexadecimal(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("octal")?{type:"octal"}:octal],postprocess:function(e){return S.octal(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("unit")?{type:"unit"}:unit],postprocess:function(e){var t=function(e){var t=e.match(/(-?[0-9.]+)([a-zA-Z]+)/);if(null==t)throw Error("Malformed unit number: "+e);return{value:t[1],unit:t[2]}}(e[0].value);return S.unit(t.unit,t.value)}},{name:"_",symbols:[]},{name:"_",symbols:[P.has("whitespace")?{type:"whitespace"}:whitespace],postprocess:C},{name:"EOL$ebnf$1$subexpression$1",symbols:[P.has("lineComment")?{type:"lineComment"}:lineComment,/[\n]/]},{name:"EOL$ebnf$1",symbols:["EOL$ebnf$1$subexpression$1"],postprocess:E},{name:"EOL$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"EOL",symbols:["_","EOL$ebnf$1"],postprocess:C},{name:"Comment$ebnf$1",symbols:[/[\n]/],postprocess:E},{name:"Comment$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"Comment",symbols:[P.has("lineComment")?{type:"lineComment"}:lineComment,"Comment$ebnf$1"],postprocess:C}],ParserStart:"Gram"},w=function(e){return e.children[0]},k={leftNodeOf:w,rightNodeOf:function(e){var t=e.children[1];return s(t)?t:w(t)},propertyOf:function(e,t){return void 0===t[e]?n.none:n.some(t[e])}},A=require("shortid"),O={base2:"01",base8:"01234567",base10:"0123456789",base11:"0123456789a",base16:"0123456789abcdef",base32:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",zBase32:"ybndrfg8ejkmcpqxot1uwisza345h769",crock32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ",base32Hex:"0123456789ABCDEFGHIJKLMNOPQRSTUV",base36:"0123456789abcdefghijklmnopqrstuvwxyz",base58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",base62:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",base64:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@"};A.characters(O.base64);var N=new RegExp("^"+x.RE.identifier.source+"$"),R=N.test.bind(N),j=A.generate,V=function(e){return""+e.toString(36)},Q=function(e){return void 0===e?"":R(e)?e:e.replace(/[\s.,'"]/gi,"_").replace(/[^_0-9a-zA-Z]/gi,"@")},B={alphabets:O,isValidIdentifier:R,shortID:j,base36ID:V,idFunctionNamed:function(e){return"number"===e?function(e){return""+e}:"shortid"===e?function(e){return j()}:"base36"===e?V:function(e){return""}},idEncoder:Q,integerLiteralToBaseID:function(e,t){return"_"+r(e).encode(r(O.base10).decode(t))}},F=require("unist-util-visit"),G=function(e,t){return e.id=e.id||t(e),e.id},D={mergeNodes:function(e){var t=new Map;return F(e,"node",(function(e){var n,r,i=G(e,j),o=t.get(i)||$();t.set(i,(r=e,s(n=o)&&s(r)?$(r.id||n.id,[].concat(r.labels||[],n.labels||[]),Object.assign(n.record||{},r.record||{})):n))})),Array.from(t.values())},mergeEdges:function(e){var t=new Map;return F(e,"edge",(function(e){t.set(G(e,j),e)})),Array.from(t.values())},identify:G,reidentify:function(e,t){var r=new Map;return F(e,"node",(function(e){var i=e.id;if(i){var o=Q(r.get(i)||n.getOrElse((function(){return i}))(t(e)));r.set(i,o),Object.assign(e,{id:o})}})),e}},z=function(){return new t.Parser(t.Grammar.fromCompiled(_))},I=function(e){return z().feed(e).results[0]},q={ast:l,builder:S,tokens:x,find:k,makeParser:z,parse:I,stringify:b,profile:o,reporter:a,transform:D,identity:B};exports.ast=l,exports.builder=S,exports.default=q,exports.find=k,exports.identity=B,exports.makeParser=z,exports.parse=I,exports.profile=o,exports.reporter=a,exports.stringify=b,exports.tokens=x,exports.transform=D; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("nearley"),n=e(require("moo")),r=require("fp-ts/lib/Option"),i=e(require("base-x")),o=require("unist-util-visit"),a=function(e){var t={path:{count:0,identifiers:new Set,labels:new Set},node:{count:0,identifiers:new Set,labels:new Set},relationship:{count:0,identifiers:new Set,labels:new Set},properties:{}},n=function(e){for(var n=0,r=Object.entries(e);n<r.length;n++){var i=r[n],o=i[0],a=i[1],s=Array.isArray(a)?"Array<"+a[0].type+">":"type"in a&&"string"==typeof a.type?a.type:"record";t.properties[o]=s}};return o(e,(function(e){switch(e.type){case"gram":break;case"path":t.path.count++;break;case"node":t.node.count++,e.id&&t.node.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.node.labels.add(e)})),e.record&&n(e.record);break;case"edge":t.relationship.count++,e.id&&t.relationship.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.relationship.labels.add(e)})),e.record&&n(e.record)}})),t},s={reportError:function(e,t){var n=t.token;if(void 0===n)return t.message;var r=[],i=(n.type?n.type+" token: ":"")+JSON.stringify(void 0!==n.value?n.value:n);return r.push(e.lexer.formatError(n,"Syntax error")),r.push("Unexpected "+i+". Instead, I was expecting to see one of the following:\n"),e.table[e.table.length-2].states.filter((function(e){var t=e.rule.symbols[e.dot];return t&&"string"!=typeof t})).map((function(e){return function e(t,n){return-1!==n.indexOf(t)?[]:0===t.wantedBy.length?[[t]]:t.wantedBy.reduce((function(r,i){return r.concat(e(i,[t].concat(n)).map((function(e){return[t].concat(e)})))}),[])}(e,[])[0]}),this).forEach((function(t){var n=t[0],i=e.getSymbolDisplay(n.rule.symbols[n.dot]);r.push("A "+i)}),this),r.push(""),r.join("\n")}},c=function(e){return!!e.type&&"node"===e.type},l=function(e){return!!e.type&&!!e.value},u={__proto__:null,isGram:function(e){return!!e.type&&"gram"===e.type},isPath:function(e){return!!e.type&&"path"===e.type},isNode:c,isEdge:function(e){return!!e.type&&!!e.direction&&"edge"===e.type},isLiteral:l,isBooleanLiteral:function(e){return!!e.type&&!!e.value&&"boolean"===e.type},isStringLiteral:function(e){return!!e.type&&!!e.value&&"string"===e.type},isTaggedLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type},isIntegerLiteral:function(e){return!!e.type&&!!e.value&&"integer"===e.type},isUnitLiteral:function(e){return!!e.type&&!!e.value&&!!e.unit&&"unit"===e.type},isDecimalLiteral:function(e){return!!e.type&&!!e.value&&"decimal"===e.type},isHexadecimalLiteral:function(e){return!!e.type&&!!e.value&&"hexadecimal"===e.type},isOctalLiteral:function(e){return!!e.type&&!!e.value&&"octal"===e.type},isDateLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"date"===e.tag},isGeospatialLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"geo"===e.tag}},p=function(e){switch(e.type){case"integer":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";default:return"<ERROR, can't stringify literals of type "+e.type+">"}},f=function(e){return"{"+Object.entries(e).map((function(e,t){return(t>0?",":"")+e[0]+":"+(n=e[1],Array.isArray(n)?"["+n.map((function(e){return p(e)})).join(",")+"]":l(n)?p(n):f(n));var n})).join("")+"}"},d=function(e){var t=e.id||"",n=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",r=e.record&&0!==Object.keys(e.record).length?f(e.record):"";return""+t+n+(r.length>0?" ":"")+r},m=function(e){return"("+d(e)+")"},b=function e(t){var n="left"===t.direction?"<-":"-",r="right"===t.direction?"->":"-",i=m(t.children[0]),o="node"===t.children[1].type?m(t.children[1]):e(t.children[1]),a=d(t);return""+i+n+(a.length>0?"["+a+"]":"")+r+o},y=function e(t){switch(t.type){case"gram":return t.children.map(e).join("\n");case"path":return function(e){var t=d(e),n=e.children[0],r=n?""+("node"===n.type?m(n):b(n)):"";return t.length>0?"["+t+" "+r+"]":r}(t);case"node":return m(t);case"edge":return b(t);default:console.error("Impossible:",typeof t)}return[].join("")};function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function h(e){return Array.isArray(e)?e:e instanceof Function?h(e()):void 0===e?[]:[e]}var $=function(e){return e.toISOString().slice(0,10)},v=function(e,t,n){return g({type:"node"},e&&{id:e},t&&{labels:t},n&&{record:n})},S=function(e,t){return{type:"tagged",value:t,tag:e}},L={gram:function(e,t,n,r){return void 0===n&&(n=[]),g({type:"gram"},t&&{id:t},{labels:n},r&&{record:r},{children:h(e)})},path:function(e,t,n,r){return g({type:"path"},t&&{id:t},{labels:n},r&&{record:r},{children:e?[e]:[]})},node:v,edge:function(e,t,n,r,i){return void 0===t&&(t="right"),g({type:"edge"},n&&{id:n},r&&{labels:r},i&&{record:i},{direction:t,children:e})},record:function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},property:function(e,t){return{type:"property",name:e,value:t}},boolean:function(e){return{type:"boolean",value:e?"true":"false"}},string:function(e){return{type:"string",value:e}},tagged:S,integer:function(e){return{type:"integer",value:String(e)}},decimal:function(e){return{type:"decimal",value:String(e)}},hexadecimal:function(e){return{type:"hexadecimal",value:e}},octal:function(e){return{type:"octal",value:e}},unit:function(e,t){return{type:"unit",value:String(t),unit:e}},date:function(e){return S(e instanceof Date?$(e):e,"date")},time:function(e){return S(e instanceof Date?$(e):e,"time")},flatten:function(e,t){return void 0===t&&(t=1),e.flat(t)}},x={boolean:/true|false|TRUE|FALSE\b/,hexadecimal:/-?0x(?:[0-9a-fA-F]+)\b/,octal:/-?0(?:[0-7]+)\b/,unit:/-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?[a-zA-Z]+\b/,decimal:/-?(?:[0-9]|[1-9][0-9]+)\.[0-9]+(?:[eE][-+]?[0-9]+)?\b/,integer:/-?(?:[0-9]|[1-9][0-9]+)(?:[eE][-+]?[0-9]+)?\b/,taggedString:/[a-zA-Z][0-9a-zA-Z_@]*`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,doubleQuotedString:/"(?:\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/,singleQuotedString:/'(?:\\['bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^'\\])*'/,tickedString:/`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,identifier:/[a-zA-Z_][0-9a-zA-Z_]*/},E={RE:x};function P(e){return e[0]}var C=n.compile({whitespace:{match:/\s+/,lineBreaks:!0},lineComment:{match:/\/\/.*?$/},hexadecimal:x.hexadecimal,octal:x.octal,unit:x.unit,decimal:x.decimal,integer:x.integer,taggedString:{match:x.taggedString},doubleQuotedString:{match:x.doubleQuotedString,value:function(e){return e.slice(1,-1)}},singleQuotedString:{match:x.singleQuotedString,value:function(e){return e.slice(1,-1)}},tickedString:{match:x.tickedString,value:function(e){return e.slice(1,-1)}},boolean:["true","TRUE","True","false","FALSE","False"],identifier:x.identifier,"--\x3e":"--\x3e","--":"--","<--":"<--","-[]->":"-[]->","-[]-":"-[]-","<-[]-":"<-[]-","<-[":"<-[","]->":"]->","-[":"-[","]-":"]-","{":"{","}":"}","[":"[","]":"]","(":"(",")":")",",":",",":":":","`":"`","'":"'"}),_=function(){return null},w={Lexer:C,ParserRules:[{name:"Gram$ebnf$1",symbols:["Block"]},{name:"Gram$ebnf$1",symbols:["Gram$ebnf$1","Block"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Gram",symbols:["Gram$ebnf$1"],postprocess:function(e){return L.gram(L.flatten(e))}},{name:"Block",symbols:["PathPattern","_"],postprocess:function(e){return e[0]}},{name:"Block",symbols:["Comment"],postprocess:_},{name:"PathPattern$ebnf$1",symbols:["EdgePattern"],postprocess:P},{name:"PathPattern$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"PathPattern",symbols:[{literal:"["},"_","ContentSpecification","_","PathPattern$ebnf$1",{literal:"]"}],postprocess:function(e){var t=e[2];return L.path(e[4]||[],t.id,t.labels,t.record)}},{name:"PathPattern",symbols:["EdgePattern"],postprocess:function(e){return L.path(e[0])}},{name:"NodePattern",symbols:[{literal:"("},"_","ContentSpecification",{literal:")"}],postprocess:function(e){var t=e[2];return L.node(t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern","EdgeSpecification","EdgePattern"],postprocess:function(e){var t=e[1];return L.edge([e[0],e[2]],t.direction,t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern"],postprocess:P},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]->"}],postprocess:function(e){return g({direction:"right"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return g({direction:"none"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"<-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return g({direction:"left"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-[]->"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"-[]-"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<-[]-"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:"--\x3e"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"--"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<--"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:","}],postprocess:function(){return{direction:"pair"}}},{name:"ContentSpecification$ebnf$1",symbols:["SymbolicName"],postprocess:P},{name:"ContentSpecification$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$2",symbols:["LabelList"],postprocess:P},{name:"ContentSpecification$ebnf$2",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$3",symbols:["Record"],postprocess:P},{name:"ContentSpecification$ebnf$3",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification",symbols:["ContentSpecification$ebnf$1","_","ContentSpecification$ebnf$2","_","ContentSpecification$ebnf$3"],postprocess:function(e){return{id:e[0],labels:e[2],record:e[4]}}},{name:"LabelList$ebnf$1",symbols:["Label"]},{name:"LabelList$ebnf$1",symbols:["LabelList$ebnf$1","Label"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"LabelList",symbols:["LabelList$ebnf$1"],postprocess:function(e){return e[0]}},{name:"Label",symbols:[{literal:":"},"SymbolicName"],postprocess:function(e){return e[1]}},{name:"SymbolicName",symbols:[C.has("identifier")?{type:"identifier"}:identifier],postprocess:function(e){return e[0].text}},{name:"SymbolicName",symbols:[C.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return e[0].text.slice(1,-1)}},{name:"Record",symbols:[{literal:"{"},"_",{literal:"}"}],postprocess:_},{name:"Record$ebnf$1",symbols:[]},{name:"Record$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Property"]},{name:"Record$ebnf$1",symbols:["Record$ebnf$1","Record$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Record",symbols:[{literal:"{"},"_","Property","Record$ebnf$1",{literal:"}"}],postprocess:function(e){return L.record([e[2]].concat(e[3].map((function(e){return e[3]}))))}},{name:"Property",symbols:["Key","_",{literal:":"},"_","Value"],postprocess:function(e){return L.property(e[0],e[4])}},{name:"Key",symbols:["SymbolicName"],postprocess:P},{name:"Value",symbols:["StringLiteral"],postprocess:P},{name:"Value",symbols:["NumericLiteral"],postprocess:P},{name:"Value",symbols:[C.has("boolean")?{type:"boolean"}:boolean],postprocess:function(e){return L.boolean(JSON.parse(e[0].value.toLowerCase()))}},{name:"Value$ebnf$1",symbols:[]},{name:"Value$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Value"]},{name:"Value$ebnf$1",symbols:["Value$ebnf$1","Value$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Value",symbols:[{literal:"["},"_","Value","Value$ebnf$1",{literal:"]"}],postprocess:function(e){return[e[2]].concat(e[3].map((function(e){return e[3]})))}},{name:"StringLiteral",symbols:[C.has("singleQuotedString")?{type:"singleQuotedString"}:singleQuotedString],postprocess:function(e){return L.string(e[0].value)}},{name:"StringLiteral",symbols:[C.has("doubleQuotedString")?{type:"doubleQuotedString"}:doubleQuotedString],postprocess:function(e){return L.string(e[0].value)}},{name:"StringLiteral",symbols:[C.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return L.string(e[0].value)}},{name:"StringLiteral",symbols:[C.has("taggedString")?{type:"taggedString"}:taggedString],postprocess:function(e){var t=function(e){var t=e.match(/([^`]+)`(.+)`$/);if(null==t)throw Error("Malformed tagged string: "+e);return{tag:t[1],value:t[2]}}(e[0].value);return L.tagged(t.tag,t.value)}},{name:"NumericLiteral",symbols:[C.has("integer")?{type:"integer"}:integer],postprocess:function(e){return L.integer(e[0].value)}},{name:"NumericLiteral",symbols:[C.has("decimal")?{type:"decimal"}:decimal],postprocess:function(e){return L.decimal(e[0].value)}},{name:"NumericLiteral",symbols:[C.has("hexadecimal")?{type:"hexadecimal"}:hexadecimal],postprocess:function(e){return L.hexadecimal(e[0].value)}},{name:"NumericLiteral",symbols:[C.has("octal")?{type:"octal"}:octal],postprocess:function(e){return L.octal(e[0].value)}},{name:"NumericLiteral",symbols:[C.has("unit")?{type:"unit"}:unit],postprocess:function(e){var t=function(e){var t=e.match(/(-?[0-9.]+)([a-zA-Z]+)/);if(null==t)throw Error("Malformed unit number: "+e);return{value:t[1],unit:t[2]}}(e[0].value);return L.unit(t.unit,t.value)}},{name:"_",symbols:[]},{name:"_",symbols:[C.has("whitespace")?{type:"whitespace"}:whitespace],postprocess:_},{name:"EOL$ebnf$1$subexpression$1",symbols:[C.has("lineComment")?{type:"lineComment"}:lineComment,/[\n]/]},{name:"EOL$ebnf$1",symbols:["EOL$ebnf$1$subexpression$1"],postprocess:P},{name:"EOL$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"EOL",symbols:["_","EOL$ebnf$1"],postprocess:_},{name:"Comment$ebnf$1",symbols:[/[\n]/],postprocess:P},{name:"Comment$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"Comment",symbols:[C.has("lineComment")?{type:"lineComment"}:lineComment,"Comment$ebnf$1"],postprocess:_}],ParserStart:"Gram"},k=function(e){return e.children[0]},A={leftNodeOf:k,rightNodeOf:function(e){var t=e.children[1];return c(t)?t:k(t)},propertyOf:function(e,t){return void 0===t[e]?r.none:r.some(t[e])}},O=require("shortid"),N={base2:"01",base8:"01234567",base10:"0123456789",base11:"0123456789a",base16:"0123456789abcdef",base32:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",zBase32:"ybndrfg8ejkmcpqxot1uwisza345h769",crock32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ",base32Hex:"0123456789ABCDEFGHIJKLMNOPQRSTUV",base36:"0123456789abcdefghijklmnopqrstuvwxyz",base58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",base62:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",base64:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@"};O.characters(N.base64);var R=new RegExp("^"+E.RE.identifier.source+"$"),j=R.test.bind(R),V=O.generate,Q=function(e){return""+e.toString(36)},B=function(e){return void 0===e?"":j(e)?e:e.replace(/[\s.,'"]/gi,"_").replace(/[^_0-9a-zA-Z]/gi,"@")},F={alphabets:N,isValidIdentifier:j,shortID:V,base36ID:Q,idFunctionNamed:function(e){return"number"===e?function(e){return""+e}:"shortid"===e?function(e){return V()}:"base36"===e?Q:function(e){return""}},idEncoder:B,integerLiteralToBaseID:function(e,t){return"_"+i(e).encode(i(N.base10).decode(t))}},G=require("unist-util-visit"),D=function(e,t){return e.id=e.id||t(e),e.id},z={mergeNodes:function(e){var t=new Map;return G(e,"node",(function(e){var n,r,i=D(e,V),o=t.get(i)||v();t.set(i,(r=e,c(n=o)&&c(r)?v(r.id||n.id,[].concat(r.labels||[],n.labels||[]),Object.assign(n.record||{},r.record||{})):n))})),Array.from(t.values())},mergeEdges:function(e){var t=new Map;return G(e,"edge",(function(e){t.set(D(e,V),e)})),Array.from(t.values())},identify:D,reidentify:function(e,t){var n=new Map;return G(e,"node",(function(e){var i=e.id;if(i){var o=B(n.get(i)||r.getOrElse((function(){return i}))(t(e)));n.set(i,o),Object.assign(e,{id:o})}})),e}},I=function(){return new t.Parser(t.Grammar.fromCompiled(w))},q=function(e){return I().feed(e).results[0]},M={ast:u,builder:L,tokens:E,find:A,makeParser:I,parse:q,stringify:y,profile:a,reporter:s,transform:z,identity:F};exports.ast=u,exports.builder=L,exports.default=M,exports.find=A,exports.identity=F,exports.makeParser=I,exports.parse=q,exports.profile=a,exports.reporter=s,exports.stringify=y,exports.tokens=E,exports.transform=z; | ||
//# sourceMappingURL=gram-format.cjs.production.min.js.map |
import { Parser, Grammar } from 'nearley'; | ||
import moo from 'moo'; | ||
import { none, some, getOrElse } from 'fp-ts/lib/Option'; | ||
@@ -619,4 +620,2 @@ import baseX from 'base-x'; | ||
var moo = /*#__PURE__*/require('moo'); | ||
var lexer = /*#__PURE__*/moo.compile({ | ||
@@ -623,0 +622,0 @@ whitespace: { |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('nearley'), require('fp-ts/lib/Option'), require('base-x')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'nearley', 'fp-ts/lib/Option', 'base-x'], factory) : | ||
(global = global || self, factory(global['@gram-data/gram-format'] = {}, global.nearley, global.Option, global.baseX)); | ||
}(this, (function (exports, nearley, Option, baseX) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('nearley'), require('moo'), require('fp-ts/lib/Option'), require('base-x')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'nearley', 'moo', 'fp-ts/lib/Option', 'base-x'], factory) : | ||
(global = global || self, factory(global['@gram-data/gram-format'] = {}, global.nearley, global.moo, global.Option, global.baseX)); | ||
}(this, (function (exports, nearley, moo, Option, baseX) { 'use strict'; | ||
moo = moo && Object.prototype.hasOwnProperty.call(moo, 'default') ? moo['default'] : moo; | ||
baseX = baseX && Object.prototype.hasOwnProperty.call(baseX, 'default') ? baseX['default'] : baseX; | ||
@@ -623,4 +624,2 @@ | ||
var moo = /*#__PURE__*/require('moo'); | ||
var lexer = /*#__PURE__*/moo.compile({ | ||
@@ -627,0 +626,0 @@ whitespace: { |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("nearley"),require("fp-ts/lib/Option"),require("base-x")):"function"==typeof define&&define.amd?define(["exports","nearley","fp-ts/lib/Option","base-x"],t):t((e=e||self)["@gram-data/gram-format"]={},e.nearley,e.Option,e.baseX)}(this,(function(e,t,n,r){"use strict";r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;var i=require("unist-util-visit"),o=function(e){var t={path:{count:0,identifiers:new Set,labels:new Set},node:{count:0,identifiers:new Set,labels:new Set},relationship:{count:0,identifiers:new Set,labels:new Set},properties:{}},n=function(e){for(var n=0,r=Object.entries(e);n<r.length;n++){var i=r[n],o=i[0],a=i[1],s=Array.isArray(a)?"Array<"+a[0].type+">":"type"in a&&"string"==typeof a.type?a.type:"record";t.properties[o]=s}};return i(e,(function(e){switch(e.type){case"gram":break;case"path":t.path.count++;break;case"node":t.node.count++,e.id&&t.node.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.node.labels.add(e)})),e.record&&n(e.record);break;case"edge":t.relationship.count++,e.id&&t.relationship.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.relationship.labels.add(e)})),e.record&&n(e.record)}})),t},a={reportError:function(e,t){var n=t.token;if(void 0===n)return t.message;var r=[],i=(n.type?n.type+" token: ":"")+JSON.stringify(void 0!==n.value?n.value:n);return r.push(e.lexer.formatError(n,"Syntax error")),r.push("Unexpected "+i+". Instead, I was expecting to see one of the following:\n"),e.table[e.table.length-2].states.filter((function(e){var t=e.rule.symbols[e.dot];return t&&"string"!=typeof t})).map((function(e){return function e(t,n){return-1!==n.indexOf(t)?[]:0===t.wantedBy.length?[[t]]:t.wantedBy.reduce((function(r,i){return r.concat(e(i,[t].concat(n)).map((function(e){return[t].concat(e)})))}),[])}(e,[])[0]}),this).forEach((function(t){var n=t[0],i=e.getSymbolDisplay(n.rule.symbols[n.dot]);r.push("A "+i)}),this),r.push(""),r.join("\n")}},s=function(e){return!!e.type&&"node"===e.type},c=function(e){return!!e.type&&!!e.value},l={__proto__:null,isGram:function(e){return!!e.type&&"gram"===e.type},isPath:function(e){return!!e.type&&"path"===e.type},isNode:s,isEdge:function(e){return!!e.type&&!!e.direction&&"edge"===e.type},isLiteral:c,isBooleanLiteral:function(e){return!!e.type&&!!e.value&&"boolean"===e.type},isStringLiteral:function(e){return!!e.type&&!!e.value&&"string"===e.type},isTaggedLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type},isIntegerLiteral:function(e){return!!e.type&&!!e.value&&"integer"===e.type},isUnitLiteral:function(e){return!!e.type&&!!e.value&&!!e.unit&&"unit"===e.type},isDecimalLiteral:function(e){return!!e.type&&!!e.value&&"decimal"===e.type},isHexadecimalLiteral:function(e){return!!e.type&&!!e.value&&"hexadecimal"===e.type},isOctalLiteral:function(e){return!!e.type&&!!e.value&&"octal"===e.type},isDateLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"date"===e.tag},isGeospatialLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"geo"===e.tag}},u=function(e){switch(e.type){case"integer":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";default:return"<ERROR, can't stringify literals of type "+e.type+">"}},p=function(e){return"{"+Object.entries(e).map((function(e,t){return(t>0?",":"")+e[0]+":"+(n=e[1],Array.isArray(n)?"["+n.map((function(e){return u(e)})).join(",")+"]":c(n)?u(n):p(n));var n})).join("")+"}"},f=function(e){var t=e.id||"",n=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",r=e.record&&0!==Object.keys(e.record).length?p(e.record):"";return""+t+n+(r.length>0?" ":"")+r},d=function(e){return"("+f(e)+")"},m=function e(t){var n="left"===t.direction?"<-":"-",r="right"===t.direction?"->":"-",i=d(t.children[0]),o="node"===t.children[1].type?d(t.children[1]):e(t.children[1]),a=f(t);return""+i+n+(a.length>0?"["+a+"]":"")+r+o},b=function e(t){switch(t.type){case"gram":return t.children.map(e).join("\n");case"path":return function(e){var t=f(e),n=e.children[0],r=n?""+("node"===n.type?d(n):m(n)):"";return t.length>0?"["+t+" "+r+"]":r}(t);case"node":return d(t);case"edge":return m(t);default:console.error("Impossible:",typeof t)}return[].join("")};function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function g(e){return Array.isArray(e)?e:e instanceof Function?g(e()):void 0===e?[]:[e]}var h=function(e){return e.toISOString().slice(0,10)},$=function(e,t,n){return y({type:"node"},e&&{id:e},t&&{labels:t},n&&{record:n})},v=function(e,t){return{type:"tagged",value:t,tag:e}},S={gram:function(e,t,n,r){return void 0===n&&(n=[]),y({type:"gram"},t&&{id:t},{labels:n},r&&{record:r},{children:g(e)})},path:function(e,t,n,r){return y({type:"path"},t&&{id:t},{labels:n},r&&{record:r},{children:e?[e]:[]})},node:$,edge:function(e,t,n,r,i){return void 0===t&&(t="right"),y({type:"edge"},n&&{id:n},r&&{labels:r},i&&{record:i},{direction:t,children:e})},record:function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},property:function(e,t){return{type:"property",name:e,value:t}},boolean:function(e){return{type:"boolean",value:e?"true":"false"}},string:function(e){return{type:"string",value:e}},tagged:v,integer:function(e){return{type:"integer",value:String(e)}},decimal:function(e){return{type:"decimal",value:String(e)}},hexadecimal:function(e){return{type:"hexadecimal",value:e}},octal:function(e){return{type:"octal",value:e}},unit:function(e,t){return{type:"unit",value:String(t),unit:e}},date:function(e){return v(e instanceof Date?h(e):e,"date")},time:function(e){return v(e instanceof Date?h(e):e,"time")},flatten:function(e,t){return void 0===t&&(t=1),e.flat(t)}},L={boolean:/true|false|TRUE|FALSE\b/,hexadecimal:/-?0x(?:[0-9a-fA-F]+)\b/,octal:/-?0(?:[0-7]+)\b/,unit:/-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?[a-zA-Z]+\b/,decimal:/-?(?:[0-9]|[1-9][0-9]+)\.[0-9]+(?:[eE][-+]?[0-9]+)?\b/,integer:/-?(?:[0-9]|[1-9][0-9]+)(?:[eE][-+]?[0-9]+)?\b/,taggedString:/[a-zA-Z][0-9a-zA-Z_@]*`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,doubleQuotedString:/"(?:\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/,singleQuotedString:/'(?:\\['bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^'\\])*'/,tickedString:/`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,identifier:/[a-zA-Z_][0-9a-zA-Z_]*/},E={RE:L};function x(e){return e[0]}var P=require("moo").compile({whitespace:{match:/\s+/,lineBreaks:!0},lineComment:{match:/\/\/.*?$/},hexadecimal:L.hexadecimal,octal:L.octal,unit:L.unit,decimal:L.decimal,integer:L.integer,taggedString:{match:L.taggedString},doubleQuotedString:{match:L.doubleQuotedString,value:function(e){return e.slice(1,-1)}},singleQuotedString:{match:L.singleQuotedString,value:function(e){return e.slice(1,-1)}},tickedString:{match:L.tickedString,value:function(e){return e.slice(1,-1)}},boolean:["true","TRUE","True","false","FALSE","False"],identifier:L.identifier,"--\x3e":"--\x3e","--":"--","<--":"<--","-[]->":"-[]->","-[]-":"-[]-","<-[]-":"<-[]-","<-[":"<-[","]->":"]->","-[":"-[","]-":"]-","{":"{","}":"}","[":"[","]":"]","(":"(",")":")",",":",",":":":","`":"`","'":"'"}),C=function(){return null},O={Lexer:P,ParserRules:[{name:"Gram$ebnf$1",symbols:["Block"]},{name:"Gram$ebnf$1",symbols:["Gram$ebnf$1","Block"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Gram",symbols:["Gram$ebnf$1"],postprocess:function(e){return S.gram(S.flatten(e))}},{name:"Block",symbols:["PathPattern","_"],postprocess:function(e){return e[0]}},{name:"Block",symbols:["Comment"],postprocess:C},{name:"PathPattern$ebnf$1",symbols:["EdgePattern"],postprocess:x},{name:"PathPattern$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"PathPattern",symbols:[{literal:"["},"_","ContentSpecification","_","PathPattern$ebnf$1",{literal:"]"}],postprocess:function(e){var t=e[2];return S.path(e[4]||[],t.id,t.labels,t.record)}},{name:"PathPattern",symbols:["EdgePattern"],postprocess:function(e){return S.path(e[0])}},{name:"NodePattern",symbols:[{literal:"("},"_","ContentSpecification",{literal:")"}],postprocess:function(e){var t=e[2];return S.node(t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern","EdgeSpecification","EdgePattern"],postprocess:function(e){var t=e[1];return S.edge([e[0],e[2]],t.direction,t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern"],postprocess:x},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]->"}],postprocess:function(e){return y({direction:"right"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return y({direction:"none"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"<-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return y({direction:"left"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-[]->"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"-[]-"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<-[]-"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:"--\x3e"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"--"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<--"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:","}],postprocess:function(){return{direction:"pair"}}},{name:"ContentSpecification$ebnf$1",symbols:["SymbolicName"],postprocess:x},{name:"ContentSpecification$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$2",symbols:["LabelList"],postprocess:x},{name:"ContentSpecification$ebnf$2",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$3",symbols:["Record"],postprocess:x},{name:"ContentSpecification$ebnf$3",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification",symbols:["ContentSpecification$ebnf$1","_","ContentSpecification$ebnf$2","_","ContentSpecification$ebnf$3"],postprocess:function(e){return{id:e[0],labels:e[2],record:e[4]}}},{name:"LabelList$ebnf$1",symbols:["Label"]},{name:"LabelList$ebnf$1",symbols:["LabelList$ebnf$1","Label"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"LabelList",symbols:["LabelList$ebnf$1"],postprocess:function(e){return e[0]}},{name:"Label",symbols:[{literal:":"},"SymbolicName"],postprocess:function(e){return e[1]}},{name:"SymbolicName",symbols:[P.has("identifier")?{type:"identifier"}:identifier],postprocess:function(e){return e[0].text}},{name:"SymbolicName",symbols:[P.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return e[0].text.slice(1,-1)}},{name:"Record",symbols:[{literal:"{"},"_",{literal:"}"}],postprocess:C},{name:"Record$ebnf$1",symbols:[]},{name:"Record$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Property"]},{name:"Record$ebnf$1",symbols:["Record$ebnf$1","Record$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Record",symbols:[{literal:"{"},"_","Property","Record$ebnf$1",{literal:"}"}],postprocess:function(e){return S.record([e[2]].concat(e[3].map((function(e){return e[3]}))))}},{name:"Property",symbols:["Key","_",{literal:":"},"_","Value"],postprocess:function(e){return S.property(e[0],e[4])}},{name:"Key",symbols:["SymbolicName"],postprocess:x},{name:"Value",symbols:["StringLiteral"],postprocess:x},{name:"Value",symbols:["NumericLiteral"],postprocess:x},{name:"Value",symbols:[P.has("boolean")?{type:"boolean"}:boolean],postprocess:function(e){return S.boolean(JSON.parse(e[0].value.toLowerCase()))}},{name:"Value$ebnf$1",symbols:[]},{name:"Value$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Value"]},{name:"Value$ebnf$1",symbols:["Value$ebnf$1","Value$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Value",symbols:[{literal:"["},"_","Value","Value$ebnf$1",{literal:"]"}],postprocess:function(e){return[e[2]].concat(e[3].map((function(e){return e[3]})))}},{name:"StringLiteral",symbols:[P.has("singleQuotedString")?{type:"singleQuotedString"}:singleQuotedString],postprocess:function(e){return S.string(e[0].value)}},{name:"StringLiteral",symbols:[P.has("doubleQuotedString")?{type:"doubleQuotedString"}:doubleQuotedString],postprocess:function(e){return S.string(e[0].value)}},{name:"StringLiteral",symbols:[P.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return S.string(e[0].value)}},{name:"StringLiteral",symbols:[P.has("taggedString")?{type:"taggedString"}:taggedString],postprocess:function(e){var t=function(e){var t=e.match(/([^`]+)`(.+)`$/);if(null==t)throw Error("Malformed tagged string: "+e);return{tag:t[1],value:t[2]}}(e[0].value);return S.tagged(t.tag,t.value)}},{name:"NumericLiteral",symbols:[P.has("integer")?{type:"integer"}:integer],postprocess:function(e){return S.integer(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("decimal")?{type:"decimal"}:decimal],postprocess:function(e){return S.decimal(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("hexadecimal")?{type:"hexadecimal"}:hexadecimal],postprocess:function(e){return S.hexadecimal(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("octal")?{type:"octal"}:octal],postprocess:function(e){return S.octal(e[0].value)}},{name:"NumericLiteral",symbols:[P.has("unit")?{type:"unit"}:unit],postprocess:function(e){var t=function(e){var t=e.match(/(-?[0-9.]+)([a-zA-Z]+)/);if(null==t)throw Error("Malformed unit number: "+e);return{value:t[1],unit:t[2]}}(e[0].value);return S.unit(t.unit,t.value)}},{name:"_",symbols:[]},{name:"_",symbols:[P.has("whitespace")?{type:"whitespace"}:whitespace],postprocess:C},{name:"EOL$ebnf$1$subexpression$1",symbols:[P.has("lineComment")?{type:"lineComment"}:lineComment,/[\n]/]},{name:"EOL$ebnf$1",symbols:["EOL$ebnf$1$subexpression$1"],postprocess:x},{name:"EOL$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"EOL",symbols:["_","EOL$ebnf$1"],postprocess:C},{name:"Comment$ebnf$1",symbols:[/[\n]/],postprocess:x},{name:"Comment$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"Comment",symbols:[P.has("lineComment")?{type:"lineComment"}:lineComment,"Comment$ebnf$1"],postprocess:C}],ParserStart:"Gram"},_=function(e){return e.children[0]},w={leftNodeOf:_,rightNodeOf:function(e){var t=e.children[1];return s(t)?t:_(t)},propertyOf:function(e,t){return void 0===t[e]?n.none:n.some(t[e])}},k=require("shortid"),A={base2:"01",base8:"01234567",base10:"0123456789",base11:"0123456789a",base16:"0123456789abcdef",base32:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",zBase32:"ybndrfg8ejkmcpqxot1uwisza345h769",crock32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ",base32Hex:"0123456789ABCDEFGHIJKLMNOPQRSTUV",base36:"0123456789abcdefghijklmnopqrstuvwxyz",base58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",base62:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",base64:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@"};k.characters(A.base64);var N=new RegExp("^"+E.RE.identifier.source+"$"),R=N.test.bind(N),j=k.generate,V=function(e){return""+e.toString(36)},Q=function(e){return void 0===e?"":R(e)?e:e.replace(/[\s.,'"]/gi,"_").replace(/[^_0-9a-zA-Z]/gi,"@")},B={alphabets:A,isValidIdentifier:R,shortID:j,base36ID:V,idFunctionNamed:function(e){return"number"===e?function(e){return""+e}:"shortid"===e?function(e){return j()}:"base36"===e?V:function(e){return""}},idEncoder:Q,integerLiteralToBaseID:function(e,t){return"_"+r(e).encode(r(A.base10).decode(t))}},F=require("unist-util-visit"),G=function(e,t){return e.id=e.id||t(e),e.id},D={mergeNodes:function(e){var t=new Map;return F(e,"node",(function(e){var n,r,i=G(e,j),o=t.get(i)||$();t.set(i,(r=e,s(n=o)&&s(r)?$(r.id||n.id,[].concat(r.labels||[],n.labels||[]),Object.assign(n.record||{},r.record||{})):n))})),Array.from(t.values())},mergeEdges:function(e){var t=new Map;return F(e,"edge",(function(e){t.set(G(e,j),e)})),Array.from(t.values())},identify:G,reidentify:function(e,t){var r=new Map;return F(e,"node",(function(e){var i=e.id;if(i){var o=Q(r.get(i)||n.getOrElse((function(){return i}))(t(e)));r.set(i,o),Object.assign(e,{id:o})}})),e}},z=function(){return new t.Parser(t.Grammar.fromCompiled(O))},I=function(e){return z().feed(e).results[0]},q={ast:l,builder:S,tokens:E,find:w,makeParser:z,parse:I,stringify:b,profile:o,reporter:a,transform:D,identity:B};e.ast=l,e.builder=S,e.default=q,e.find=w,e.identity=B,e.makeParser=z,e.parse=I,e.profile=o,e.reporter=a,e.stringify=b,e.tokens=E,e.transform=D,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("nearley"),require("moo"),require("fp-ts/lib/Option"),require("base-x")):"function"==typeof define&&define.amd?define(["exports","nearley","moo","fp-ts/lib/Option","base-x"],t):t((e=e||self)["@gram-data/gram-format"]={},e.nearley,e.moo,e.Option,e.baseX)}(this,(function(e,t,n,r,i){"use strict";n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;var o=require("unist-util-visit"),a=function(e){var t={path:{count:0,identifiers:new Set,labels:new Set},node:{count:0,identifiers:new Set,labels:new Set},relationship:{count:0,identifiers:new Set,labels:new Set},properties:{}},n=function(e){for(var n=0,r=Object.entries(e);n<r.length;n++){var i=r[n],o=i[0],a=i[1],s=Array.isArray(a)?"Array<"+a[0].type+">":"type"in a&&"string"==typeof a.type?a.type:"record";t.properties[o]=s}};return o(e,(function(e){switch(e.type){case"gram":break;case"path":t.path.count++;break;case"node":t.node.count++,e.id&&t.node.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.node.labels.add(e)})),e.record&&n(e.record);break;case"edge":t.relationship.count++,e.id&&t.relationship.identifiers.add(e.id),e.labels&&e.labels.forEach((function(e){return t.relationship.labels.add(e)})),e.record&&n(e.record)}})),t},s={reportError:function(e,t){var n=t.token;if(void 0===n)return t.message;var r=[],i=(n.type?n.type+" token: ":"")+JSON.stringify(void 0!==n.value?n.value:n);return r.push(e.lexer.formatError(n,"Syntax error")),r.push("Unexpected "+i+". Instead, I was expecting to see one of the following:\n"),e.table[e.table.length-2].states.filter((function(e){var t=e.rule.symbols[e.dot];return t&&"string"!=typeof t})).map((function(e){return function e(t,n){return-1!==n.indexOf(t)?[]:0===t.wantedBy.length?[[t]]:t.wantedBy.reduce((function(r,i){return r.concat(e(i,[t].concat(n)).map((function(e){return[t].concat(e)})))}),[])}(e,[])[0]}),this).forEach((function(t){var n=t[0],i=e.getSymbolDisplay(n.rule.symbols[n.dot]);r.push("A "+i)}),this),r.push(""),r.join("\n")}},c=function(e){return!!e.type&&"node"===e.type},l=function(e){return!!e.type&&!!e.value},u={__proto__:null,isGram:function(e){return!!e.type&&"gram"===e.type},isPath:function(e){return!!e.type&&"path"===e.type},isNode:c,isEdge:function(e){return!!e.type&&!!e.direction&&"edge"===e.type},isLiteral:l,isBooleanLiteral:function(e){return!!e.type&&!!e.value&&"boolean"===e.type},isStringLiteral:function(e){return!!e.type&&!!e.value&&"string"===e.type},isTaggedLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type},isIntegerLiteral:function(e){return!!e.type&&!!e.value&&"integer"===e.type},isUnitLiteral:function(e){return!!e.type&&!!e.value&&!!e.unit&&"unit"===e.type},isDecimalLiteral:function(e){return!!e.type&&!!e.value&&"decimal"===e.type},isHexadecimalLiteral:function(e){return!!e.type&&!!e.value&&"hexadecimal"===e.type},isOctalLiteral:function(e){return!!e.type&&!!e.value&&"octal"===e.type},isDateLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"date"===e.tag},isGeospatialLiteral:function(e){return!!e.type&&!!e.value&&!!e.tag&&"tagged"===e.type&&"geo"===e.tag}},p=function(e){switch(e.type){case"integer":return e.value;case"string":return"`"+e.value+"`";case"tagged":return e.tag+"`"+e.value+"`";default:return"<ERROR, can't stringify literals of type "+e.type+">"}},f=function(e){return"{"+Object.entries(e).map((function(e,t){return(t>0?",":"")+e[0]+":"+(n=e[1],Array.isArray(n)?"["+n.map((function(e){return p(e)})).join(",")+"]":l(n)?p(n):f(n));var n})).join("")+"}"},d=function(e){var t=e.id||"",n=e.labels&&e.labels.length>0?":"+e.labels.join(":"):"",r=e.record&&0!==Object.keys(e.record).length?f(e.record):"";return""+t+n+(r.length>0?" ":"")+r},m=function(e){return"("+d(e)+")"},b=function e(t){var n="left"===t.direction?"<-":"-",r="right"===t.direction?"->":"-",i=m(t.children[0]),o="node"===t.children[1].type?m(t.children[1]):e(t.children[1]),a=d(t);return""+i+n+(a.length>0?"["+a+"]":"")+r+o},y=function e(t){switch(t.type){case"gram":return t.children.map(e).join("\n");case"path":return function(e){var t=d(e),n=e.children[0],r=n?""+("node"===n.type?m(n):b(n)):"";return t.length>0?"["+t+" "+r+"]":r}(t);case"node":return m(t);case"edge":return b(t);default:console.error("Impossible:",typeof t)}return[].join("")};function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function h(e){return Array.isArray(e)?e:e instanceof Function?h(e()):void 0===e?[]:[e]}var $=function(e){return e.toISOString().slice(0,10)},v=function(e,t,n){return g({type:"node"},e&&{id:e},t&&{labels:t},n&&{record:n})},S=function(e,t){return{type:"tagged",value:t,tag:e}},L={gram:function(e,t,n,r){return void 0===n&&(n=[]),g({type:"gram"},t&&{id:t},{labels:n},r&&{record:r},{children:h(e)})},path:function(e,t,n,r){return g({type:"path"},t&&{id:t},{labels:n},r&&{record:r},{children:e?[e]:[]})},node:v,edge:function(e,t,n,r,i){return void 0===t&&(t="right"),g({type:"edge"},n&&{id:n},r&&{labels:r},i&&{record:i},{direction:t,children:e})},record:function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},property:function(e,t){return{type:"property",name:e,value:t}},boolean:function(e){return{type:"boolean",value:e?"true":"false"}},string:function(e){return{type:"string",value:e}},tagged:S,integer:function(e){return{type:"integer",value:String(e)}},decimal:function(e){return{type:"decimal",value:String(e)}},hexadecimal:function(e){return{type:"hexadecimal",value:e}},octal:function(e){return{type:"octal",value:e}},unit:function(e,t){return{type:"unit",value:String(t),unit:e}},date:function(e){return S(e instanceof Date?$(e):e,"date")},time:function(e){return S(e instanceof Date?$(e):e,"time")},flatten:function(e,t){return void 0===t&&(t=1),e.flat(t)}},E={boolean:/true|false|TRUE|FALSE\b/,hexadecimal:/-?0x(?:[0-9a-fA-F]+)\b/,octal:/-?0(?:[0-7]+)\b/,unit:/-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?[a-zA-Z]+\b/,decimal:/-?(?:[0-9]|[1-9][0-9]+)\.[0-9]+(?:[eE][-+]?[0-9]+)?\b/,integer:/-?(?:[0-9]|[1-9][0-9]+)(?:[eE][-+]?[0-9]+)?\b/,taggedString:/[a-zA-Z][0-9a-zA-Z_@]*`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,doubleQuotedString:/"(?:\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/,singleQuotedString:/'(?:\\['bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^'\\])*'/,tickedString:/`(?:\\[`bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^`\\])*`/,identifier:/[a-zA-Z_][0-9a-zA-Z_]*/},x={RE:E};function P(e){return e[0]}var O=n.compile({whitespace:{match:/\s+/,lineBreaks:!0},lineComment:{match:/\/\/.*?$/},hexadecimal:E.hexadecimal,octal:E.octal,unit:E.unit,decimal:E.decimal,integer:E.integer,taggedString:{match:E.taggedString},doubleQuotedString:{match:E.doubleQuotedString,value:function(e){return e.slice(1,-1)}},singleQuotedString:{match:E.singleQuotedString,value:function(e){return e.slice(1,-1)}},tickedString:{match:E.tickedString,value:function(e){return e.slice(1,-1)}},boolean:["true","TRUE","True","false","FALSE","False"],identifier:E.identifier,"--\x3e":"--\x3e","--":"--","<--":"<--","-[]->":"-[]->","-[]-":"-[]-","<-[]-":"<-[]-","<-[":"<-[","]->":"]->","-[":"-[","]-":"]-","{":"{","}":"}","[":"[","]":"]","(":"(",")":")",",":",",":":":","`":"`","'":"'"}),C=function(){return null},_={Lexer:O,ParserRules:[{name:"Gram$ebnf$1",symbols:["Block"]},{name:"Gram$ebnf$1",symbols:["Gram$ebnf$1","Block"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Gram",symbols:["Gram$ebnf$1"],postprocess:function(e){return L.gram(L.flatten(e))}},{name:"Block",symbols:["PathPattern","_"],postprocess:function(e){return e[0]}},{name:"Block",symbols:["Comment"],postprocess:C},{name:"PathPattern$ebnf$1",symbols:["EdgePattern"],postprocess:P},{name:"PathPattern$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"PathPattern",symbols:[{literal:"["},"_","ContentSpecification","_","PathPattern$ebnf$1",{literal:"]"}],postprocess:function(e){var t=e[2];return L.path(e[4]||[],t.id,t.labels,t.record)}},{name:"PathPattern",symbols:["EdgePattern"],postprocess:function(e){return L.path(e[0])}},{name:"NodePattern",symbols:[{literal:"("},"_","ContentSpecification",{literal:")"}],postprocess:function(e){var t=e[2];return L.node(t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern","EdgeSpecification","EdgePattern"],postprocess:function(e){var t=e[1];return L.edge([e[0],e[2]],t.direction,t.id,t.labels,t.record)}},{name:"EdgePattern",symbols:["NodePattern"],postprocess:P},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]->"}],postprocess:function(e){return g({direction:"right"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return g({direction:"none"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"<-["},"_","ContentSpecification",{literal:"]-"}],postprocess:function(e){return g({direction:"left"},e[2])}},{name:"EdgeSpecification",symbols:[{literal:"-[]->"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"-[]-"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<-[]-"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:"--\x3e"}],postprocess:function(){return{direction:"right"}}},{name:"EdgeSpecification",symbols:[{literal:"--"}],postprocess:function(){return{direction:"none"}}},{name:"EdgeSpecification",symbols:[{literal:"<--"}],postprocess:function(){return{direction:"left"}}},{name:"EdgeSpecification",symbols:[{literal:","}],postprocess:function(){return{direction:"pair"}}},{name:"ContentSpecification$ebnf$1",symbols:["SymbolicName"],postprocess:P},{name:"ContentSpecification$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$2",symbols:["LabelList"],postprocess:P},{name:"ContentSpecification$ebnf$2",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification$ebnf$3",symbols:["Record"],postprocess:P},{name:"ContentSpecification$ebnf$3",symbols:[],postprocess:function(){return null}},{name:"ContentSpecification",symbols:["ContentSpecification$ebnf$1","_","ContentSpecification$ebnf$2","_","ContentSpecification$ebnf$3"],postprocess:function(e){return{id:e[0],labels:e[2],record:e[4]}}},{name:"LabelList$ebnf$1",symbols:["Label"]},{name:"LabelList$ebnf$1",symbols:["LabelList$ebnf$1","Label"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"LabelList",symbols:["LabelList$ebnf$1"],postprocess:function(e){return e[0]}},{name:"Label",symbols:[{literal:":"},"SymbolicName"],postprocess:function(e){return e[1]}},{name:"SymbolicName",symbols:[O.has("identifier")?{type:"identifier"}:identifier],postprocess:function(e){return e[0].text}},{name:"SymbolicName",symbols:[O.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return e[0].text.slice(1,-1)}},{name:"Record",symbols:[{literal:"{"},"_",{literal:"}"}],postprocess:C},{name:"Record$ebnf$1",symbols:[]},{name:"Record$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Property"]},{name:"Record$ebnf$1",symbols:["Record$ebnf$1","Record$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Record",symbols:[{literal:"{"},"_","Property","Record$ebnf$1",{literal:"}"}],postprocess:function(e){return L.record([e[2]].concat(e[3].map((function(e){return e[3]}))))}},{name:"Property",symbols:["Key","_",{literal:":"},"_","Value"],postprocess:function(e){return L.property(e[0],e[4])}},{name:"Key",symbols:["SymbolicName"],postprocess:P},{name:"Value",symbols:["StringLiteral"],postprocess:P},{name:"Value",symbols:["NumericLiteral"],postprocess:P},{name:"Value",symbols:[O.has("boolean")?{type:"boolean"}:boolean],postprocess:function(e){return L.boolean(JSON.parse(e[0].value.toLowerCase()))}},{name:"Value$ebnf$1",symbols:[]},{name:"Value$ebnf$1$subexpression$1",symbols:["_",{literal:","},"_","Value"]},{name:"Value$ebnf$1",symbols:["Value$ebnf$1","Value$ebnf$1$subexpression$1"],postprocess:function(e){return e[0].concat([e[1]])}},{name:"Value",symbols:[{literal:"["},"_","Value","Value$ebnf$1",{literal:"]"}],postprocess:function(e){return[e[2]].concat(e[3].map((function(e){return e[3]})))}},{name:"StringLiteral",symbols:[O.has("singleQuotedString")?{type:"singleQuotedString"}:singleQuotedString],postprocess:function(e){return L.string(e[0].value)}},{name:"StringLiteral",symbols:[O.has("doubleQuotedString")?{type:"doubleQuotedString"}:doubleQuotedString],postprocess:function(e){return L.string(e[0].value)}},{name:"StringLiteral",symbols:[O.has("tickedString")?{type:"tickedString"}:tickedString],postprocess:function(e){return L.string(e[0].value)}},{name:"StringLiteral",symbols:[O.has("taggedString")?{type:"taggedString"}:taggedString],postprocess:function(e){var t=function(e){var t=e.match(/([^`]+)`(.+)`$/);if(null==t)throw Error("Malformed tagged string: "+e);return{tag:t[1],value:t[2]}}(e[0].value);return L.tagged(t.tag,t.value)}},{name:"NumericLiteral",symbols:[O.has("integer")?{type:"integer"}:integer],postprocess:function(e){return L.integer(e[0].value)}},{name:"NumericLiteral",symbols:[O.has("decimal")?{type:"decimal"}:decimal],postprocess:function(e){return L.decimal(e[0].value)}},{name:"NumericLiteral",symbols:[O.has("hexadecimal")?{type:"hexadecimal"}:hexadecimal],postprocess:function(e){return L.hexadecimal(e[0].value)}},{name:"NumericLiteral",symbols:[O.has("octal")?{type:"octal"}:octal],postprocess:function(e){return L.octal(e[0].value)}},{name:"NumericLiteral",symbols:[O.has("unit")?{type:"unit"}:unit],postprocess:function(e){var t=function(e){var t=e.match(/(-?[0-9.]+)([a-zA-Z]+)/);if(null==t)throw Error("Malformed unit number: "+e);return{value:t[1],unit:t[2]}}(e[0].value);return L.unit(t.unit,t.value)}},{name:"_",symbols:[]},{name:"_",symbols:[O.has("whitespace")?{type:"whitespace"}:whitespace],postprocess:C},{name:"EOL$ebnf$1$subexpression$1",symbols:[O.has("lineComment")?{type:"lineComment"}:lineComment,/[\n]/]},{name:"EOL$ebnf$1",symbols:["EOL$ebnf$1$subexpression$1"],postprocess:P},{name:"EOL$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"EOL",symbols:["_","EOL$ebnf$1"],postprocess:C},{name:"Comment$ebnf$1",symbols:[/[\n]/],postprocess:P},{name:"Comment$ebnf$1",symbols:[],postprocess:function(){return null}},{name:"Comment",symbols:[O.has("lineComment")?{type:"lineComment"}:lineComment,"Comment$ebnf$1"],postprocess:C}],ParserStart:"Gram"},w=function(e){return e.children[0]},k={leftNodeOf:w,rightNodeOf:function(e){var t=e.children[1];return c(t)?t:w(t)},propertyOf:function(e,t){return void 0===t[e]?r.none:r.some(t[e])}},A=require("shortid"),N={base2:"01",base8:"01234567",base10:"0123456789",base11:"0123456789a",base16:"0123456789abcdef",base32:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",zBase32:"ybndrfg8ejkmcpqxot1uwisza345h769",crock32:"0123456789ABCDEFGHJKMNPQRSTVWXYZ",base32Hex:"0123456789ABCDEFGHIJKLMNOPQRSTUV",base36:"0123456789abcdefghijklmnopqrstuvwxyz",base58:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ",base62:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",base64:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@"};A.characters(N.base64);var R=new RegExp("^"+x.RE.identifier.source+"$"),j=R.test.bind(R),V=A.generate,Q=function(e){return""+e.toString(36)},B=function(e){return void 0===e?"":j(e)?e:e.replace(/[\s.,'"]/gi,"_").replace(/[^_0-9a-zA-Z]/gi,"@")},F={alphabets:N,isValidIdentifier:j,shortID:V,base36ID:Q,idFunctionNamed:function(e){return"number"===e?function(e){return""+e}:"shortid"===e?function(e){return V()}:"base36"===e?Q:function(e){return""}},idEncoder:B,integerLiteralToBaseID:function(e,t){return"_"+i(e).encode(i(N.base10).decode(t))}},G=require("unist-util-visit"),D=function(e,t){return e.id=e.id||t(e),e.id},z={mergeNodes:function(e){var t=new Map;return G(e,"node",(function(e){var n,r,i=D(e,V),o=t.get(i)||v();t.set(i,(r=e,c(n=o)&&c(r)?v(r.id||n.id,[].concat(r.labels||[],n.labels||[]),Object.assign(n.record||{},r.record||{})):n))})),Array.from(t.values())},mergeEdges:function(e){var t=new Map;return G(e,"edge",(function(e){t.set(D(e,V),e)})),Array.from(t.values())},identify:D,reidentify:function(e,t){var n=new Map;return G(e,"node",(function(e){var i=e.id;if(i){var o=B(n.get(i)||r.getOrElse((function(){return i}))(t(e)));n.set(i,o),Object.assign(e,{id:o})}})),e}},I=function(){return new t.Parser(t.Grammar.fromCompiled(_))},q=function(e){return I().feed(e).results[0]},M={ast:u,builder:L,tokens:x,find:k,makeParser:I,parse:q,stringify:y,profile:a,reporter:s,transform:z,identity:F};e.ast=u,e.builder=L,e.default=M,e.find=k,e.identity=F,e.makeParser=I,e.parse=q,e.profile=a,e.reporter=s,e.stringify=y,e.tokens=x,e.transform=z,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=gram-format.umd.production.min.js.map |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "0.1.13", | ||
"version": "0.1.14", | ||
"license": "Apache-2.0", | ||
@@ -15,0 +15,0 @@ "author": "Andreas Kollegger", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
526173