Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bavary/core

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bavary/core - npm Package Compare versions

Comparing version 0.0.18 to 0.0.19

lib/types/ast/internal.d.ts

4

lib/bavary.js

@@ -1,3 +0,3 @@

/*! Bavary 0.0.18 MIT | https://github.com/Simonwep/bavary */
var e,t;e=(()=>"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:Function("return this")())(),t=function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=25)}([function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(6);t.optional=(e,t,n,...o)=>r.check(e,t,n,...o)?e.next(t):null},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.maybe=e=>t=>{t.stash();const n=e(t);return null!==n?(t.recycle(),n):(t.pop(),null)}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(0);t.expect=(e,t,n,...o)=>{const s=r.optional(e,t,n,...o);if(null!==s)return s;const l=e.next(t);null!==l?e.throwError(`Expected ${o.join(", ")} (${n}) but got ${l.value} (${l.type})`):e.throwError("Unxpected end of input.")}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1);e.exports=r.maybe(e=>{let t="";for(;e.hasNext(!0);){const{type:n,value:r}=e.peek(!0);if("ws"===n)break;if(!("punc"===n&&"-"===r&&t.length||"num"===n||"kw"===n))break;t+=r,e.next(!0)}return t.endsWith("-")&&e.throwError("Identifier cannot end with a hyphen"),t.length?{type:"identifier",value:t}:null})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(6),o=n(10),s=n(2),l=n(1),u=n(0);e.exports=l.maybe(e=>{const t=n(32),l=n(33),i=n(34),c=n(13),a=n(19),p=n(14),f=n(4),d=n(40);if(!u.optional(e,!1,"punc","["))return null;const h=[],y=o.combine(d,f,a,l,i,p);let v=null;for(;!r.check(e,!1,"punc","]");){const n=y(e),r=t(e);if(n||e.throwError("Expected a type, group or raw string / character-range."),r){if(v){if(r===v.sign)v.value.push(n);else{const e={type:"combinator",value:[n],sign:r};v.value.push(e),v=e}continue}v={type:"combinator",value:[n],sign:r},h.push(v)}else v?(v.value.push(n),v=null):h.push(n)}return v&&e.throwError("Combinator is missing a value!"),s.expect(e,!1,"punc","]"),{type:"group",multiplier:c(e),value:h}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(20),o=n(15);e.exports=o.maybeMultiplier(({config:e,stream:t,decl:o,scope:s,result:l={obj:{},str:"",pure:!0}})=>{const u=n(21);t.stash();const i=l.str,c=o.value;for(let n=0;n<c.length;n++)if(!u({config:e,stream:t,decl:c[n],scope:s,result:l}))return t.pop(),r.serializeParsingResult(c,l,!0),l.str=i,null;return r.serializeParsingResult(c,l),t.recycle(),l.pure?l.str:l.obj})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.check=(e,t,n,...r)=>{const o=e.peek(t);return!(!o||o.type!==n)&&(!r.length||r.includes(o.value))}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.skipWhitespace=e=>{var t;"ws"===(null===(t=e.peek(!0))||void 0===t?void 0:t.type)&&e.next(!0)}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.isPunctuation=e=>e<"0"||e>"z"||e>"9"&&e<"A"||e>"Z"&&e<"a",t.isNonWhitespace=e=>e>="a"&&e<="z"||e>="A"&&e<="Z"||"_"===e,t.isWhiteSpace=e=>"\t"===e||"\n"===e||"\r"===e||" "===e,t.isNumeric=e=>e>="0"&&e<="9"},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(29);t.Streamable=class{constructor(e,t=null){this.vals=e,this.length=e.length,this.source=t,this.index=0,this.stashed=[]}stash(){this.stashed.push(this.index)}pop(){this.index=this.stashed.pop()}next(){return this.hasNext()?this.vals[this.index++]:null}peek(){return this.hasNext()?this.vals[this.index]:null}hasNext(){return this.index<this.vals.length}recycle(){this.stashed.pop()}throwError(e){const{index:t,source:n}=this;if(n){if(this.hasNext()){const t=this.peek();throw new r.ParsingError(n,e,t.start,t.end)}throw new r.ParsingError(n,e,t,t)}throw new r.ParsingError(e)}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.combine=(...e)=>t=>{for(const n of e){const e=n(t);if(null!==e)return e}return null}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(10),o=n(2),s=n(1),l=n(0),u=s.maybe(e=>{if(!l.optional(e,!0,"punc","."))return null;const t=n(3)(e);return t||e.throwError("Expected identifier."),t.value}),i=s.maybe(e=>{if(!l.optional(e,!0,"punc","["))return null;const t=o.expect(e,!1,"num");return o.expect(e,!0,"punc","]"),t.value});e.exports=s.maybe(e=>{const t=n(3)(e),o=t?[t.value]:[],s=r.combine(u,i);for(let t=null;null!==(t=s(e));)o.push(t);return o.length?{type:"value-accessor",value:o}:null})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0);e.exports=r.maybe(e=>{if(!o.optional(e,!1,"punc","#"))return null;const t=n(3)(e);return t||e.throwError("Expected tag-identifier"),{type:"tag",value:t.value}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(2),o=n(1),s=n(0),l={"*":"zero-infinity","+":"one-infinity","?":"optional"};e.exports=o.maybe(e=>{var t;const n=s.optional(e,!1,"punc","*","+","?","{");if(n&&"{"===n.value){const n=r.expect(e,!1,"num");r.expect(e,!1,"punc",",");const o=s.optional(e,!1,"num");return o&&o.value-n.value<0&&e.throwError("The difference between start and end-value cannot be negative or zero."),r.expect(e,!1,"punc","}"),{type:"range",value:{start:n.value,end:(null===(t=o)||void 0===t?void 0:t.value)||-1}}}return n?{type:l[n.value],value:n.value}:null})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0);e.exports=r.maybe(e=>{const t=o.optional(e,!1,"str");return t&&!t.value.length&&e.throwError("Strings shouldn't be empty."),t?{type:"string",value:t.value}:null})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.maybeMultiplier=e=>t=>{const{stream:n,decl:r}=t,o=()=>e(t),s=()=>{const e=[];for(let t;t=o();)e.push(t);return e};if(n.stash(),r.multiplier){const{type:e,value:t}=r.multiplier;switch(e){case"zero-infinity":return n.recycle(),s();case"one-infinity":{const e=s();return e.length?(n.recycle(),e):(n.pop(),null)}case"range":{const{start:e,end:r}=t,o=s();return o.length<e||~r&&o.length>r?(n.pop(),null):(n.recycle(),o)}}}return n.recycle(),o()}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.lookupValue=(e,t)=>{for(const n of t){if("string"==typeof n){if("object"==typeof e&&null!==e&&void 0!==(e=e[n]))continue}else if(Array.isArray(e)&&n<e.length){e=e[n];continue}return null}return e}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(2),o=n(1),s=n(0);e.exports=o.maybe(e=>{var t,o,l;const u=n(3),i=n(18),c=n(4),a=n(41),p=s.optional(e,!1,"kw","entry","default","export");let f,d=null,h=null;return s.optional(e,!1,"punc","<")?(d=u(e),d||e.throwError("Expected identifier."),h=i(e),r.expect(e,!1,"punc",">"),r.expect(e,!1,"punc","=")):p||e.throwError("Expected declaration."),(null===(t=h)||void 0===t?void 0:t.length)?(f=c(e),f||e.throwError("Expected a group.")):(f=c(e)||a(e),f||e.throwError("Expected a group or block-statement.")),{type:"declaration",name:(null===(o=d)||void 0===o?void 0:o.value)||null,variant:(null===(l=p)||void 0===l?void 0:l.value)||null,value:f,arguments:h}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0),s=n(7);e.exports=r.maybe(e=>{const t=n(3),r=n(4),l=[];for(;;){s.skipWhitespace(e);const n=t(e);if(!n)break;let u=null;o.optional(e,!1,"punc","=")&&(u=r(e),u||e.throwError("Expected a group.")),l.push({type:"argument",name:n.value,value:u})}return l.length?l:null})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(2),o=n(1),s=n(0);e.exports=o.maybe(e=>{var t;const o=n(36),l=n(37),u=n(13),i=n(3),c=n(18),a=n(12),p=!!o(e);if(!s.optional(e,!1,"punc","<"))return null;const f=[];let d=!1;for(;e.hasNext();){const t=i(e);if(t&&(d=!1,f.push(t.value)),!s.optional(e,!1,"punc",":"))break;d=!0}!d&&f.length||e.throwError("Expected identifier");const h=a(e);p&&h&&e.throwError("Type cannot have both a tag an spread operator attached to it.");const y=l(e),v=c(e);r.expect(e,!1,"punc",">");const b=u(e);return{type:"reference",tag:(null===(t=h)||void 0===t?void 0:t.value)||null,arguments:v,multiplier:b,modifiers:y,spread:p,value:f}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.serializeParsingResult=function e(t,n,r=!1){const{obj:o}=n;for(const s of t)"reference"===s.type&&s.tag?((void 0===o[s.tag]||r)&&(o[s.tag]=null),n.pure=!1):"group"===s.type||"combinator"===s.type?e(s.value,n,r):"conditional-statement"===s.type&&(e([s.then],n,r),s.alternative&&e([s.alternative],n,r))}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),e.exports=({config:e,stream:t,decl:r,scope:o,result:s})=>{const l=n(44),u=n(45),i=n(46),c=n(47),a=n(51),p=n(52),f=n(5);switch(t.stash(),r.type){case"combinator":if(!i({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"string":if(!p({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"character-selection":if(!u({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"reference":if(!c({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"group":if(!f({config:e,stream:t,decl:r,scope:o,result:s})){if(r.multiplier){const{type:e}=r.multiplier;if("one-infinity"!==e)break}return t.pop(),!1}break;case"function":if(!a({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"conditional-statement":if(!l({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1}return t.recycle(),!0}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.typeOf=e=>{const t=typeof e;return"object"===t?Array.isArray(e)?"array":"object":t}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(48),o=n(15);e.exports=({config:e,stream:t,decl:s,scope:l,result:u})=>{const i=n(5),c=l.lookupByPath(s.value);if(!c)throw new Error(`Failed to resolve "${s.value.join(":")}". If it's a block a default export may be missing.`);const[a,p]=c,f=a.arguments,d=[...s.arguments||[]];if(f){for(const{value:e,name:t}of f){let n=e;const r=d.findIndex(e=>e.name===t);if(~r&&([{value:n}]=d.splice(r,1)),!n)throw new Error(`Argument "${t}" is missing on type ${a.name}.`);p.injectValue(n,t)}if(d.length)throw new Error(`These arguments were passed into "${a.name}" but not expected: ${d.map(e=>e.name).join(", ")}`)}else if(d.length)throw new Error(`Type "${a.name}" does not expect any arguments.`);const h=o.maybeMultiplier(()=>i({config:e,stream:t,decl:a.value,scope:p}))({config:e,stream:t,decl:s,result:u,scope:p});return h&&s.modifiers&&r.applyModifications(h,s),h}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.consumeWhile=(e,t)=>{let n="";for(;e.hasNext()&&t(e.peek(),n);)n+=e.next();return n}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(26),o=n(27),s=n(42),l=n(53);t.compile=(e,t)=>{const n=Array.isArray(e)?e:o.parseAST(l.tokenize(e),e);return s.compileDeclarations(n,t)},t.compileChunk=e=>o.parseAST(l.tokenize(e),e),t.version=r.ENV_VERSION},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.ENV_VERSION="0.0.18"},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(28);t.parseAST=(e,t)=>{const o=n(17),s=new r.TokenStream(e,t),l=[];for(;s.hasNext();)l.push(o(s));return l}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(9);class o extends r.Streamable{next(e=!1){const{index:t,length:n,vals:r}=this;if(e&&t<n)return r[this.index++];for(let e=t;e<n;e++)if("ws"!==r[e].type)return this.index=e+1,r[e];return null}peek(e=!1){const{index:t,length:n,vals:r}=this;if(e&&t<n)return r[t];for(let e=t;e<n;e++)if("ws"!==r[e].type)return r[e];return null}hasNext(e=!1){return null!==this.peek(e)}}t.TokenStream=o},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(30);class o extends Error{constructor(e,t,n,o){super(n&&o&&t?r.prettifyError(e,t,n,o):e),this.source=t,this.start=n,this.end=o,this.msg=e,this.name="Parsing Error"}}t.ParsingError=o},function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=r(n(31));function s(e,t,n=-1){return e===n?t:e}t.prettifyError=(e,t,n,r)=>{const l=s(o.default(e,"\n",n),-1)+1,u=s(e.indexOf("\n",r),e.length),i=n-l;return`\n${e.slice(l,u)}\n${" ".repeat(i)}^\n${t}`}},function(e,t){e.exports=(e,t,n)=>{if("string"!=typeof t||"string"!=typeof e||n<t.length-1)return-1;"number"!=typeof n&&(n=e.length-1);const r=t.length-1;for(let o=n,s=r;o>=0;o--)if(e[o]===t[s]){if(s--,!~s)return o}else s!==r&&(s=r,o++);return-1}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0);e.exports=r.maybe(e=>{const t=o.optional(e,!1,"punc","|","&");return t?("&"===t.value&&o.optional(e,!1,"punc","&")&&(t.value+="&"),t.value):null})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0);e.exports=r.maybe(e=>{var t;const r=n(11),s=n(4),l=n(12);if(!o.optional(e,!1,"kw","if"))return null;const u=!!o.optional(e,!1,"kw","not"),i=l(e);i||e.throwError("Expected a tag.");const c=(null===(t=r(e))||void 0===t?void 0:t.value)||null,a=s(e);a||e.throwError("Expected a group.");let p=null;return o.optional(e,!1,"kw","else")&&(p=s(e),p||e.throwError("Expected a group.")),{type:"conditional-statement",condition:[i,c],negated:u,then:a,alternative:p}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(35),o=n(2),s=n(1),l=n(0),u=e=>{const t=r.parseUnicodeEscape(e);if(null!==t)return t;if(!e.hasNext())return null;const n=e.peek(),o=String(n.value),s="\\"===o;if(1!==o.length||"punc"===n.type&&!s)return null;if(e.next(),s){if(!e.hasNext())return null;const t=e.peek(),n=String(t.value);return"punc"!==t.type&&e.throwError("Only punctuation characters need to be escaped."),e.next(),n.charCodeAt(0)}return o.charCodeAt(0)},i=e=>{const t=[];for(;;){let n=null,r=null;if(n=u(e),null===n&&e.throwError("Missing character (-sequence)."),l.optional(e,!1,"punc","-")?(r=u(e),null===r&&e.throwError("Expected end position.")):r=null,null!==r?t.push([Math.min(n,r),Math.max(n,r)]):t.push(n),!l.optional(e,!1,"punc",","))break}return t};e.exports=s.maybe(e=>{const t=n(13);if(!l.optional(e,!1,"punc","("))return null;const r=[],s=[];return r.push(...i(e)),l.optional(e,!1,"kw","except")&&s.push(...i(e)),o.expect(e,!1,"punc",")"),{type:"character-selection",multiplier:t(e),included:r,excluded:s}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0);t.parseUnicodeEscape=r.maybe(e=>{if(!o.optional(e,!1,"punc","\\")||!e.hasNext())return null;const t=String(e.next().value);if(!t.startsWith("u"))return null;5!==t.length&&e.throwError('An unicode-escape sequence consists out of an "u" followed by a code-point.');const n=t.slice(1);for(const t of n){const n=t.charCodeAt(0);(n<48||n>57&&n<97||n>102)&&e.throwError("Invalid unicode-range.")}return parseInt(n,16)})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(1),o=n(0);e.exports=r.maybe(e=>{for(let t=0;t<3;t++)if(!o.optional(e,!1,"punc","."))return null;return!0})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(2),o=n(1),s=n(0),l=n(7),u=n(38),i=n(39),c={def:u.parseDefineModifier,del:i.parseDeleteModifier};e.exports=o.maybe(e=>{if(!s.optional(e,!1,"punc","{"))return null;const t=[];do{const n=s.optional(e,!1,"kw","def","del");n?(l.skipWhitespace(e),t.push(c[n.value](e))):e.throwError("Expected operator")}while(s.optional(e,!1,"punc",","));return r.expect(e,!1,"punc","}"),t})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(2),o=n(7);t.parseDefineModifier=e=>{const t=n(11),s=n(14),l=n(3)(e);l||e.throwError("Expected identifier"),r.expect(e,!1,"punc","="),o.skipWhitespace(e);const u=s(e)||t(e);return u||e.throwError("Expected string, function-call or value-accessor."),{type:"def",value:u,key:l.value}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.parseDeleteModifier=e=>{const t=n(11)(e);return t||e.throwError("Expected a value accessor."),{type:"del",param:t}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(6),o=n(10),s=n(2),l=n(1),u=n(0),i=n(7);e.exports=l.maybe(e=>{const t=n(3);i.skipWhitespace(e);const l=t(e);if(!l||!u.optional(e,!1,"punc","("))return null;const c=o.combine(n(3),n(12),n(4),n(14),n(19)),a=[];for(;!r.check(e,!1,"punc",")");){i.skipWhitespace(e),a.length&&s.expect(e,!1,"punc",","),i.skipWhitespace(e);const t=c(e);t||e.throwError("Expected an a group, tag or identifier."),a.push(t)}return s.expect(e,!1,"punc",")"),{type:"function",name:l.value,args:a}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(6),o=n(2),s=n(1),l=n(0);e.exports=s.maybe(e=>{const t=n(17);if(!l.optional(e,!1,"punc","{"))return null;const s=[];for(;!r.check(e,!1,"punc","}");)s.push(t(e));return o.expect(e,!1,"punc","}"),{type:"block",value:s}})},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(9),o=n(43);t.compileDeclarations=(e,t={locationData:!1,functions:{}})=>{const s=n(5),l=new o.Scope({global:!0});l.registerAll(e),!0===t.locationData&&(t.locationData={start:"__starts",end:"__ends"});const u=l.lookup("entry");if(!u)throw new Error("Couldn't resolve entry type. Use the entry keyword to declare one.");const[i,c]=u;return e=>{const n=new r.Streamable(e),o=s({config:t,stream:n,decl:i.value,scope:c});return n.hasNext()?null:o}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});class r{constructor({parent:e=null,global:t=!1}){this.exports=new Map,this.members=new Map,this.specials=new Map,this.parent=e,this.global=t}registerAll(e){for(const t of e)this.register(t)}register(e){const t=this.resolveValueFor(e);switch(e.variant){case"entry":if(this.specials.has("entry"))throw new Error("There can only be one entry.");if(!this.global)throw new Error("Only the global scope can contain entries.");null!==e.name&&this.setMember(e.name,t),this.specials.set("entry",t);break;case"default":if(this.specials.has("default"))throw new Error("There can only be one default export.");if(this.global)throw new Error("The global scope can't have default exports.");null!==e.name&&this.setMember(e.name,t),this.specials.set("default",t);break;case"export":{const n=e.name;if(this.global)throw new Error("The global scope can't have exported members.");this.exports.set(n,t),this.setMember(e.name,t);break}default:this.setMember(e.name,t)}}setMember(e,t){if(this.members.has(e))throw new Error(`The type named "${e}" is already declared.`);this.members.set(e,t)}injectValue(e,t){this.register({type:"declaration",variant:null,arguments:null,value:e,name:t})}lookupByPath(e){const[t,...n]=e,o=this.lookupByName(t);return o?o instanceof r?o.lookupDeepReference(n):n.length?null:[o,this]:null}lookup(e){const t=this.specials.get(e);return t?t instanceof r?t.lookup("default"):[t,this]:null}resolveValueFor(e){if("block"===e.value.type){const t=new r({parent:this});return t.registerAll(e.value.value),t}return e}lookupByName(e){return this.members.has(e)?this.members.get(e):this.parent?this.parent.lookupByName(e):null}lookupDeepReference(e){const t=e.length?this.exports.get(e.shift()):null;return t?t instanceof r?t.lookupDeepReference(e):e.length?null:[t,this]:e.length?null:this.lookup("default")}}t.Scope=r},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(16);e.exports=({config:e,stream:t,decl:o,scope:s,result:l})=>{const u=n(5),{condition:i,then:c,alternative:a,negated:p}=o,[f,d]=i,h=l.obj[f.value],y=!(h&&(!d||!(e=>null==e)(r.lookupValue(h,d))))===p?c:a;return!y||null!==u({config:e,stream:t,scope:s,result:l,decl:y})}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(15),o=(e,t)=>e.some(e=>"number"==typeof e?e===t:t>=e[0]&&t<=e[1]);e.exports=({config:e,stream:t,decl:n,scope:s,result:l})=>{const{included:u,excluded:i}=n,c=r.maybeMultiplier(()=>{if(t.hasNext()){const e=t.peek(),n=e.charCodeAt(0);if(o(u,n)&&!o(i,n))return t.next(),e}return null})({config:e,stream:t,decl:n,scope:s,result:l});if(Array.isArray(c))l.str+=c.join("");else if("string"==typeof c)l.str+=c;else if(!c&&!n.multiplier||n.multiplier&&"optional"!==n.multiplier.type)return!1;return!0}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(20);e.exports=({config:e,stream:t,decl:o,scope:s,result:l})=>{const u=n(21);switch(t.stash(),r.serializeParsingResult(o.value,l),o.sign){case"|":{const n=o.value;for(let r=0;r<n.length;r++)if(u({config:e,stream:t,decl:n[r],scope:s,result:l}))return t.recycle(),!0;break}case"&&":case"&":{const n=[...o.value];for(let r=0;r<n.length;r++)u({config:e,stream:t,decl:n[r],scope:s,result:l})&&(n.splice(r,1),r=-1);if(!n.length||"&&"===o.sign&&n.length<o.value.length)return t.recycle(),!0;break}}return t.pop(),!1}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(22);e.exports=({config:e,stream:t,decl:o,scope:s,result:l})=>{const u=n(23),i=t.index,c=u({config:e,stream:t,decl:o,scope:s,result:l}),a=r.typeOf(c);if(o.tag&&(l.obj[o.tag]=c),t.stash(),null===c)return t.pop(),!(!o.multiplier||"optional"!==o.multiplier.type);if(e.locationData&&"object"===a){const{end:n,start:r}=e.locationData;c[r]=i,c[n]=t.index-1}if(o.spread){if("object"!==a)throw new Error(`"${o.value}" doesn't return a object which is required for the spread operator to work.`);Object.assign(l.obj,c),l.pure=!1}else if(o.tag)l.pure=!1;else if("array"===a&&c.every(e=>"string"==typeof e))l.str+=c.join("");else{if("string"!==a)throw new Error(`Type "${o.value}" is missing a tag.`);l.str+=c}return t.recycle(),!0}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(49),o=n(50);t.applyModifications=(e,t)=>{for(const n of t.modifiers)switch(n.type){case"def":r.def(e,n);break;case"del":o.del(e,n)}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(16);t.def=(e,{value:t,key:n})=>{switch(t.type){case"string":e[n]=t.value;break;case"value-accessor":e[n]=r.lookupValue(e,t.value)}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(22),o=n(16);t.del=(e,t)=>{const n=[...t.param.value],s=n.pop(),l=r.typeOf(s),u=o.lookupValue(e,n),i=r.typeOf(u);if(!u)throw new Error("Failed to resolve parent value.");if("array"===i){if("number"!==l)throw new Error(`To delete a array entry you need to specify a index, got ${s} instead.`);u.splice(s,1)}else{if("object"!==i)throw new Error("Target must be an object or array.");if("string"!==l)throw new Error("To remove an object-property you need to specify a identifier.");delete u[s]}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),e.exports=({config:e,stream:t,decl:r,scope:o,result:s})=>{const l=n(23),u=n(5),i=[];for(const n of r.args)switch(n.type){case"tag":{const e=s.obj[n.value];i.push(void 0===e?null:e);break}case"group":i.push(u({config:e,stream:t,decl:n,scope:o}));break;case"string":case"identifier":i.push(n.value);break;case"reference":i.push(l({config:e,stream:t,scope:o,result:{pure:!1,obj:{},str:""},decl:n}))}const c=e.functions&&e.functions[r.name];if("function"!=typeof c)throw new Error(`There is no such function: ${r.name}`);try{return c((e=>({state:e,setString(t){if(!e.pure)throw new Error("Can't apply string, result isn't pure.");e.str=t},setProperty(t,n){e.obj[t]=n,e.pure=!1}}))(s),...i)}catch(e){throw new Error(`Function "${r.name}" throwed an error:\n${e.message}`)}}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),e.exports=({stream:e,decl:t,result:n})=>{const{value:r}=t;e.stash();for(let t=0;t<r.length;t++)if(e.next()!==r[t])return e.pop(),!1;return e.recycle(),n.str+=r,!0}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(9),o=n(54),s=n(55),l=n(56),u=n(57),i=[n(59).ws,u.str,o.kw,s.num,l.punc];t.tokenize=e=>{const t=new r.Streamable(e),n=[];e:for(;t.hasNext();){for(const e of i){const r=t.index,o=e(t);if(o){if("/"===o.value&&"/"===t.peek()){for(;t.hasNext()&&"\n"!==t.peek();)t.next();continue e}if("ws"===o.type&&n.length&&"ws"===n[n.length-1].type){const e=n[n.length-1];e.value+=o.value,e.end=t.index;continue e}n.push(Object.assign(Object.assign({},o),{start:r,end:t.index}));continue e}}throw new Error("Failed to parse input sequence.")}return n}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(24),o=n(8);t.kw=e=>{const t=r.consumeWhile(e,(e,t)=>o.isNonWhitespace(e)||!(!o.isNumeric(e)||!t.length));return t.length?{type:"kw",value:t}:null}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(8);t.num=e=>{let t="";for(;e.hasNext();){const n=e.peek();if(!r.isNumeric(n))break;t+=n,e.next()}return t.length?{type:"num",value:Number(t)}:null}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(8);t.punc=e=>r.isPunctuation(e.peek())?{type:"punc",value:e.next()}:null},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(58);t.str=e=>{for(const t of["'",'"',"`"]){if(e.stash(),e.peek()===t){e.next();const n=r.consumeEscaped(e,t);if(null!==n)return{type:"str",value:n}}e.pop()}return null}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.consumeEscaped=(e,t)=>{let n=!1,r="";for(let o=e.next();;o=e.next()){if("\n"===o&&!n)return null;if(n)r+=o,n=!1;else if("\\"===o)n=!0;else{if(o===t)return r;if(!e.hasNext())break;r+=o}}return null}},function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});const r=n(24),o=n(8);t.ws=e=>{const t=r.consumeWhile(e,o.isWhiteSpace);return t.length?{type:"ws",value:t}:null}}])},"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Bavary=t():e.Bavary=t();
/*! Bavary 0.0.19 MIT | https://github.com/Simonwep/bavary */
var e,t;e="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:Function("return this")(),t=function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=17)}([function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.maybe=e=>t=>{t.stash();const r=e(t);return null!==r?(t.recycle(),r):(t.pop(),null)}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(6);t.optional=(e,t,r,...o)=>n.check(e,t,r,...o)?e.next(t):null},function(e,t,r){function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),n(r(23)),n(r(24)),n(r(25)),n(r(26)),n(r(28)),n(r(13)),n(r(29)),n(r(30)),n(r(32)),n(r(33)),n(r(34)),n(r(35)),n(r(40)),n(r(41)),n(r(14))},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(1);t.expect=(e,t,r,...o)=>{const s=n.optional(e,t,r,...o);if(null!==s)return s;const a=e.next(t);null!==a?e.throwError(`Expected ${o.join(", ")} (${r}) but got ${a.value} (${a.type})`):e.throwError("Unxpected end of input.")}},function(e,t,r){function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),n(r(43)),n(r(46)),n(r(47)),n(r(48)),n(r(50)),n(r(51)),n(r(53)),n(r(54)),n(r(55)),n(r(56))},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.skipWhitespace=e=>{var t;"ws"===(null===(t=e.peek(!0))||void 0===t?void 0:t.type)&&e.next(!0)}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.check=(e,t,r,...n)=>{const o=e.peek(t);return!(!o||o.type!==r)&&(!n.length||n.includes(o.value))}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.combine=(...e)=>t=>{for(const r of e){const e=r(t);if(null!==e)return e}return null}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.isPunctuation=e=>e<"0"||e>"z"||e>"9"&&e<"A"||e>"Z"&&e<"a",t.isNonWhitespace=e=>e>="a"&&e<="z"||e>="A"&&e<="Z"||"_"===e,t.isWhiteSpace=e=>"\t"===e||"\n"===e||"\r"===e||" "===e,t.isNumeric=e=>e>="0"&&e<="9"},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(20);t.Streamable=class{constructor(e,t=null){this.vals=e,this.length=e.length,this.source=t,this.index=0,this.stashed=[]}stash(){this.stashed.push(this.index)}pop(){this.index=this.stashed.pop()}next(){return this.hasNext()?this.vals[this.index++]:null}peek(){return this.hasNext()?this.vals[this.index]:null}hasNext(){return this.index<this.vals.length}recycle(){this.stashed.pop()}throwError(e){const{index:t,source:r}=this;if(!r)throw new n.ParsingError(e);if(this.hasNext()){const t=this.peek();throw new n.ParsingError(r,e,t.start,t.end)}throw new n.ParsingError(r,e,t,t)}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(11);t.lookupValue=(e,t)=>{for(const r of t){const t=n.typeOf(e);if("array"!==t&&"string"!==t||"length"!==r){if("string"==typeof r){if("object"==typeof e&&null!==e&&void 0!==(e=e[r]))continue}else if(Array.isArray(e)&&r<e.length){e=e[r];continue}return null}e=e.length}return e}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.typeOf=e=>{const t=typeof e;return"object"===t?Array.isArray(e)?"array":"object":t}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.maybeMultiplier=e=>t=>{const{stream:r,decl:n}=t,o=()=>e(t),s=()=>{const e=[];for(let t;t=o();)e.push(t);return e};if(r.stash(),n.multiplier){const{type:e,value:t}=n.multiplier;switch(e){case"zero-infinity":return r.recycle(),s();case"one-infinity":{const e=s();return e.length?(r.recycle(),e):(r.pop(),null)}case"range":{const{start:e,end:n}=t,o=s();return o.length<e||~n&&o.length>n?(r.pop(),null):(r.recycle(),o)}}}return r.recycle(),o()}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(3),s=r(0),a=r(1);t.parseDeclaration=s.maybe(e=>{var t,r,s;const l=a.optional(e,!1,"kw","entry","default","export");let i,u=null,c=null;return a.optional(e,!1,"punc","<")?(u=n.parseIdentifier(e),u||e.throwError("Expected identifier."),c=n.parseArguments(e),o.expect(e,!1,"punc",">"),o.expect(e,!1,"punc","=")):l||e.throwError("Expected declaration."),(null===(t=c)||void 0===t?void 0:t.length)?(i=n.parseGroup(e),i||e.throwError("Expected a group.")):(i=n.parseGroup(e)||n.parseBlock(e),i||e.throwError("Expected a group or block-statement.")),{type:"declaration",name:(null===(r=u)||void 0===r?void 0:r.value)||null,variant:(null===(s=l)||void 0===s?void 0:s.value)||null,value:i,arguments:c}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(7),s=r(3),a=r(0),l=r(1),i=a.maybe(e=>{if(!l.optional(e,!0,"punc","."))return null;const t=n.parseIdentifier(e);return t||e.throwError("Expected identifier."),t.value}),u=a.maybe(e=>{if(!l.optional(e,!0,"punc","["))return null;const t=s.expect(e,!1,"num");return s.expect(e,!0,"punc","]"),t.value});t.parseValueAccessor=a.maybe(e=>{const t=n.parseIdentifier(e),r=t?[t.value]:[],s=o.combine(i,u);for(let t=null;null!==(t=s(e));)r.push(t);return r.length?{type:"value-accessor",value:r}:null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.serializeParsingResult=function e(t,r,n=!1){const{obj:o}=r;for(const s of t)"reference"===s.type&&s.tag?((void 0===o[s.tag]||n)&&(o[s.tag]=null),r.pure=!1):"group"===s.type||"combinator"===s.type?e(s.value,r,n):"conditional-statement"===s.type&&(e([s.consequent],r,n),s.alternate&&e([s.alternate],r,n))}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.consumeWhile=(e,t)=>{let r="";for(;e.hasNext()&&t(e.peek(),r);)r+=e.next();return r}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(18),o=r(42),s=r(58),a=r(59);t.compile=(e,t)=>{const r=Array.isArray(e)?e:n.parseAST(a.tokenize(e),e);return o.compileDeclarations(r,t)},t.compileChunk=e=>n.parseAST(a.tokenize(e),e),t.version=s.ENV_VERSION},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(19);r(2);const o=r(13);t.parseAST=(e,t)=>{const r=new n.TokenStream(e,t),s=[];for(;r.hasNext();)s.push(o.parseDeclaration(r));return s}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(9);class o extends n.Streamable{next(e=!1){const{index:t,length:r,vals:n}=this;if(e&&t<r)return n[this.index++];for(let e=t;e<r;e++)if("ws"!==n[e].type)return this.index=e+1,n[e];return null}peek(e=!1){const{index:t,length:r,vals:n}=this;if(e&&t<r)return n[t];for(let e=t;e<r;e++)if("ws"!==n[e].type)return n[e];return null}hasNext(e=!1){return null!==this.peek(e)}}t.TokenStream=o},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(21);class o extends Error{constructor(e,t,r,o){super(r&&o&&t?n.prettifyError(e,t,r,o):e),this.source=t,this.start=r,this.end=o,this.msg=e,this.name="Parsing Error"}}t.ParsingError=o},function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(r(22));function s(e,t,r=-1){return e===r?t:e}t.prettifyError=(e,t,r,n)=>{const a=s(o.default(e,"\n",r),-1)+1,l=s(e.indexOf("\n",n),e.length),i=r-a;return`\n${e.slice(a,l)}\n${" ".repeat(i)}^\n${t}`}},function(e,t){e.exports=(e,t,r)=>{if("string"!=typeof t||"string"!=typeof e||r<t.length-1)return-1;"number"!=typeof r&&(r=e.length-1);const n=t.length-1;for(let o=r,s=n;o>=0;o--)if(e[o]===t[s]){if(s--,!~s)return o}else s!==n&&(s=n,o++);return-1}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(0),s=r(1),a=r(5);t.parseArguments=o.maybe(e=>{const t=[];for(;;){a.skipWhitespace(e);const r=n.parseIdentifier(e);if(!r)break;let o=null;s.optional(e,!1,"punc","=")&&(o=n.parseGroup(e),o||e.throwError("Expected a group.")),t.push({type:"argument",name:r.value,value:o})}return t.length?t:null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(7),s=r(3),a=r(0),l=r(1),i=r(5),u={"|":1,"&":2,"=":3,"!":3,"<":4,">":4},c=Object.keys(u),p=a.maybe(e=>{var t;const r=n.parseTag(e);return r?{type:"value-accessor",value:[r.value,...(null===(t=n.parseValueAccessor(e))||void 0===t?void 0:t.value)||[]]}:null});t.parseBinaryExpression=a.maybe(e=>{if(!l.optional(e,!1,"punc","("))return null;const r=o.combine(p,t.parseBinaryExpression,n.parseString,n.parseNumber,n.parseIdentifier),a=r(e);if(!a)return null;const f=function e(t,r,n,o=0){var s;r.stash();const a=null===(s=l.optional(r,!1,"punc",...c))||void 0===s?void 0:s.value;if(!a)return t;"!"!==a||l.optional(r,!0,"punc","=")||r.throwError('Expected "="');const p=u[a];if(p>o){i.skipWhitespace(r);const s=n(r);return s||r.throwError("Expected right-hand value"),e({type:"binary-expression",operator:"!"===a?`${a}=`:a,right:e(s,r,n,p),left:t},r,n,o)}return r.pop(),t}(a,e,r);return"binary-expression"!==f.type&&e.throwError("Expected binary expression."),s.expect(e,!1,"punc",")"),f})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(6),s=r(3),a=r(0),l=r(1);t.parseBlock=a.maybe(e=>{if(!l.optional(e,!1,"punc","{"))return null;const t=[];for(;!o.check(e,!1,"punc","}");)t.push(n.parseDeclaration(e));return s.expect(e,!1,"punc","}"),{type:"block",value:t}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(27),s=r(3),a=r(0),l=r(1),i=e=>{const t=o.parseUnicodeEscape(e);if(null!==t)return t;if(!e.hasNext())return null;const r=e.peek(),n=String(r.value),s="\\"===n;if(1!==n.length||"punc"===r.type&&!s)return null;if(e.next(),s){if(!e.hasNext())return null;const t=e.peek(),r=String(t.value);return"punc"!==t.type&&e.throwError("Only punctuation characters need to be escaped."),e.next(),r.charCodeAt(0)}return n.charCodeAt(0)},u=e=>{const t=[];for(;;){let r=null,n=null;if(r=i(e),null===r&&e.throwError("Missing character (-sequence)."),l.optional(e,!1,"punc","-")?(n=i(e),null===n&&e.throwError("Expected end position.")):n=null,null!==n?t.push([Math.min(r,n),Math.max(r,n)]):t.push(r),!l.optional(e,!1,"punc",","))break}return t};t.parseCharacterSelecton=a.maybe(e=>{if(!l.optional(e,!1,"punc","("))return null;const t=[],r=[];return t.push(...u(e)),l.optional(e,!1,"kw","except")&&r.push(...u(e)),s.expect(e,!1,"punc",")"),{type:"character-selection",multiplier:n.parseMultiplier(e),included:t,excluded:r}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(0),o=r(1);t.parseUnicodeEscape=n.maybe(e=>{if(!o.optional(e,!1,"punc","\\")||!e.hasNext())return null;const t=String(e.next().value);if(!t.startsWith("u"))return null;5!==t.length&&e.throwError('An unicode-escape sequence consists out of an "u" followed by a code-point.');const r=t.slice(1);for(const t of r){const r=t.charCodeAt(0);(r<48||r>57&&r<97||r>102)&&e.throwError("Invalid unicode-range.")}return parseInt(r,16)})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(0),s=r(1);t.parseConditionalStatement=o.maybe(e=>{if(!s.optional(e,!1,"kw","if"))return null;const r=n.parseBinaryExpression(e);r||e.throwError("Expected a binary expression.");const o=n.parseGroup(e);o||e.throwError("Expected a group.");let a=null;return s.optional(e,!1,"kw","else")&&(a=n.parseGroup(e)||t.parseConditionalStatement(e),a||e.throwError("Expected a group.")),{type:"conditional-statement",condition:r,consequent:o,alternate:a}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(6),s=r(7),a=r(3),l=r(0),i=r(1),u=r(5);t.parseFunction=l.maybe(e=>{u.skipWhitespace(e);const t=n.parseIdentifier(e);if(!t||!i.optional(e,!1,"punc","("))return null;const r=s.combine(n.parseIdentifier,n.parseTag,n.parseGroup,n.parseString,n.parseReference),l=[];for(;!o.check(e,!1,"punc",")");){u.skipWhitespace(e),l.length&&a.expect(e,!1,"punc",","),u.skipWhitespace(e);const t=r(e);t||e.throwError("Expected an a group, tag or identifier."),l.push(t)}return a.expect(e,!1,"punc",")"),{type:"function",name:t.value,args:l}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(31),s=r(6),a=r(7),l=r(3),i=r(0),u=r(1);t.parseGroup=i.maybe(e=>{if(!u.optional(e,!1,"punc","["))return null;const r=[],i=a.combine(n.parseConditionalStatement,n.parseFunction,t.parseGroup,n.parseReference,n.parseCharacterSelecton,n.parseString);let c=null;for(;!s.check(e,!1,"punc","]");){const t=i(e),n=o.parseCombinator(e);if(t||e.throwError("Expected a type, group or raw string / character-range."),n){if(c){if(n===c.sign)c.value.push(t);else{const e={type:"combinator",value:[t],sign:n};c.value.push(e),c=e}continue}c={type:"combinator",value:[t],sign:n},r.push(c)}else c?(c.value.push(t),c=null):r.push(t)}return c&&e.throwError("Combinator is missing a value!"),l.expect(e,!1,"punc","]"),{type:"group",multiplier:n.parseMultiplier(e),value:r}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(0),o=r(1);t.parseCombinator=n.maybe(e=>{const t=o.optional(e,!1,"punc","|","&");return t?("&"===t.value&&o.optional(e,!1,"punc","&")&&(t.value+="&"),t.value):null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(0);t.parseIdentifier=n.maybe(e=>{let t="";for(;e.hasNext(!0);){const{type:r,value:n}=e.peek(!0);if("ws"===r)break;if(!("punc"===r&&"-"===n&&t.length||"num"===r||"kw"===r))break;t+=n,e.next(!0)}return t.endsWith("-")&&e.throwError("Identifier cannot end with a hyphen"),t.length?{type:"identifier",value:t}:null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(3),o=r(0),s=r(1),a={"*":"zero-infinity","+":"one-infinity","?":"optional"};t.parseMultiplier=o.maybe(e=>{var t;const r=s.optional(e,!1,"punc","*","+","?","{");if(r&&"{"===r.value){const r=n.expect(e,!1,"num");n.expect(e,!1,"punc",",");const o=s.optional(e,!1,"num");return o&&o.value-r.value<0&&e.throwError("The difference between start and end-value cannot be negative or zero."),n.expect(e,!1,"punc","}"),{type:"range",value:{start:r.value,end:(null===(t=o)||void 0===t?void 0:t.value)||-1}}}return r?{type:a[r.value],value:r.value}:null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(0),o=r(1);t.parseNumber=n.maybe(e=>{const t=o.optional(e,!1,"num");return t?{type:"number",value:t.value}:null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(36),s=r(39),a=r(3),l=r(0),i=r(1);t.parseReference=l.maybe(e=>{var t;const r=!!s.parseSpreadOperator(e);if(!i.optional(e,!1,"punc","<"))return null;const l=[];let u=!1;for(;e.hasNext();){const t=n.parseIdentifier(e);if(t&&(u=!1,l.push(t.value)),!i.optional(e,!1,"punc",":"))break;u=!0}!u&&l.length||e.throwError("Expected identifier");const c=n.parseTag(e);r&&c&&e.throwError("Type cannot have both a tag an spread operator attached to it.");const p=o.parseModification(e),f=n.parseArguments(e);a.expect(e,!1,"punc",">");const d=n.parseMultiplier(e);return{type:"reference",tag:(null===(t=c)||void 0===t?void 0:t.value)||null,arguments:f,modifiers:p,multiplier:d,spread:r,value:l}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(3),o=r(0),s=r(1),a=r(5),l=r(37),i=r(38),u={def:l.parseDefineModifier,del:i.parseDeleteModifier};t.parseModification=o.maybe(e=>{if(!s.optional(e,!1,"punc","{"))return null;const t=[];do{const r=s.optional(e,!1,"kw","def","del");r?(a.skipWhitespace(e),t.push(u[r.value](e))):e.throwError("Expected operator")}while(s.optional(e,!1,"punc",","));return n.expect(e,!1,"punc","}"),t})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(3),s=r(5);t.parseDefineModifier=e=>{const t=n.parseIdentifier(e);t||e.throwError("Expected identifier"),o.expect(e,!1,"punc","="),s.skipWhitespace(e);const r=n.parseString(e)||n.parseValueAccessor(e);return r||e.throwError("Expected string, function-call or value-accessor."),{type:"def",value:r,key:t.value}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(14);t.parseDeleteModifier=e=>{const t=n.parseValueAccessor(e);return t||e.throwError("Expected a value accessor."),{type:"del",param:t}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(0),o=r(1);t.parseSpreadOperator=n.maybe(e=>{for(let t=0;t<3;t++)if(!o.optional(e,!1,"punc","."))return null;return!0})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(0),o=r(1);t.parseString=n.maybe(e=>{const t=o.optional(e,!1,"str");return t&&!t.value.length&&e.throwError("Strings shouldn't be empty."),t?{type:"string",value:t.value}:null})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(2),o=r(0),s=r(1);t.parseTag=o.maybe(e=>{if(!s.optional(e,!1,"punc","#"))return null;const t=n.parseIdentifier(e);return t?{type:"tag",value:t.value}:e.throwError("Expected tag-identifier")})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(9),o=r(4),s=r(57);t.compileDeclarations=(e,t={locationData:!1,functions:{}})=>{const r=new s.Scope({global:!0});r.registerAll(e),!0===t.locationData&&(t.locationData={start:"__starts",end:"__ends"});const a=r.lookup("entry");if(!a)throw new Error("Couldn't resolve entry type. Use the entry keyword to declare one.");const[l,i]=a;return e=>{const r=new n.Streamable(e),s=o.evalGroup({config:t,stream:r,scope:i,decl:l.value});return r.hasNext()?null:s}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(44),o=r(45);t.evalModification=(e,t)=>{for(const r of t.modifiers)switch(r.type){case"def":n.def(e,r);break;case"del":o.del(e,r)}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(10);t.def=(e,{value:t,key:r})=>{switch(t.type){case"string":e[r]=t.value;break;case"value-accessor":e[r]=n.lookupValue(e,t.value)}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(11),o=r(10);t.del=(e,t)=>{const r=[...t.param.value],s=r.pop(),a=n.typeOf(s),l=o.lookupValue(e,r),i=n.typeOf(l);if(!l)throw new Error("Failed to resolve parent value.");if("array"===i){if("number"!==a)throw new Error(`To delete a array entry you need to specify a index, got ${s} instead.`);l.splice(s,1)}else{if("object"!==i)throw new Error("Target must be an object or array.");if("string"!==a)throw new Error("To remove an object-property you need to specify a identifier.");delete l[s]}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(12),o=(e,t)=>e.some(e=>"number"==typeof e?e===t:t>=e[0]&&t<=e[1]);t.evalCharacterSelection=({config:e,stream:t,decl:r,scope:s,result:a})=>{const{included:l,excluded:i}=r,u=n.maybeMultiplier(()=>{if(t.hasNext()){const e=t.peek(),r=e.charCodeAt(0);if(o(l,r)&&!o(i,r))return t.next(),e}return null})({config:e,stream:t,decl:r,scope:s,result:a});if(Array.isArray(u))a.str+=u.join("");else if("string"==typeof u)a.str+=u;else if(!u&&!r.multiplier||r.multiplier&&"optional"!==r.multiplier.type)return!1;return!0}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(4),o=r(15);t.evalCombiantor=({config:e,stream:t,decl:r,scope:s,result:a})=>{switch(t.stash(),o.serializeParsingResult(r.value,a),r.sign){case"|":{const o=r.value;for(let r=0;r<o.length;r++)if(n.evalDeclaration({config:e,stream:t,decl:o[r],scope:s,result:a}))return t.recycle(),!0;break}case"&&":case"&":{const o=[...r.value];for(let r=0;r<o.length;r++)n.evalDeclaration({config:e,stream:t,decl:o[r],scope:s,result:a})&&(o.splice(r,1),r=-1);if(!o.length||"&&"===r.sign&&o.length<r.value.length)return t.recycle(),!0;break}}return t.pop(),!1}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(4),o=r(49);t.evalConditionalStatement=({config:e,stream:r,decl:s,scope:a,result:l})=>{const{condition:i,consequent:u,alternate:c}=s,p=o.evalBinaryExpression(l,i)?u:c;if(!p)return!0;const f=("group"===p.type?n.evalGroup:t.evalConditionalStatement)({config:e,stream:r,scope:a,result:l,decl:p});return null!==f&&!1!==f}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(10);function o(e,t){switch(t.type){case"binary-expression":return a(e,t);case"value-accessor":{const[r]=t.value;if(void 0===e.obj[r])throw new Error(`Tag "${r}" isn't defined anywhere but used in a condition.`);return n.lookupValue(e.obj,t.value)}case"identifier":if("null"===t.value)return null;throw new Error(`Unknown constant: "${t.value}"`);default:return t.value}}function s(e){return!(!1===e||null==e)}function a(e,t){let{operator:r}=t,n=o(e,t.left),a=o(e,t.right);switch(">"===r&&(r="<",[n,a]=[a,n]),r){case"|":return s(n)||s(a);case"&":return s(n)&&s(a);case"=":return n===a;case"!=":return n!==a;case"<":{const e=typeof n,t=typeof a;if("string"===e&&"string"===t)return-1===n.localeCompare(a);if("number"===e&&"number"===t)return n<a;if(null!==n&&null!==a)throw new Error(`Invalid types used in comparison: ${e} ("${n}") ≠ ${t} ("${a}")`);return!1}}}t.evalBinaryExpression=a},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(4);t.evalDeclaration=({config:e,stream:t,decl:r,scope:o,result:s})=>{switch(t.stash(),r.type){case"combinator":if(!n.evalCombiantor({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"string":if(!n.evalString({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"character-selection":if(!n.evalCharacterSelection({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"reference":if(!n.evalReference({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"group":if(!n.evalGroup({config:e,stream:t,decl:r,scope:o,result:s})){if(r.multiplier){const{type:e}=r.multiplier;if("one-infinity"!==e)break}return t.pop(),!1}break;case"function":if(!n.evalFunction({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1;break;case"conditional-statement":if(!n.evalConditionalStatement({config:e,stream:t,decl:r,scope:o,result:s}))return t.pop(),!1}return t.recycle(),!0}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(4),o=r(52);t.evalFunction=({config:e,stream:t,decl:r,scope:s,result:a})=>{const l=[];for(const o of r.args)switch(o.type){case"tag":{const e=a.obj[o.value];if(void 0===e)throw new Error(`Tag "${e}" isn't defined anywhere but used in a function call.`);l.push(e);break}case"group":l.push(n.evalGroup({config:e,stream:t,decl:o,scope:s}));break;case"string":case"identifier":l.push(o.value);break;case"reference":l.push(n.evalRawReference({config:e,stream:t,scope:s,result:{pure:!1,obj:{},str:""},decl:o}))}const i=e.functions&&e.functions[r.name];if("function"!=typeof i)throw new Error(`There is no such function: ${r.name}`);try{return i(o.createCustomFunctionUtils(a),...l)}catch(e){throw new Error(`Function "${r.name}" throwed an error:\n${e.message}`)}}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.createCustomFunctionUtils=e=>({state:e,setString(t){if(!e.pure)throw new Error("Can't apply string, result isn't pure.");e.str=t},setProperty(t,r){e.obj[t]=r,e.pure=!1}})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(4),o=r(12),s=r(15);t.evalGroup=o.maybeMultiplier(({config:e,stream:t,decl:r,scope:o,result:a={obj:{},str:"",pure:!0}})=>{t.stash();const l=a.str,i=r.value;for(let r=0;r<i.length;r++){const u=i[r];if(!n.evalDeclaration({config:e,stream:t,decl:u,scope:o,result:a}))return t.pop(),s.serializeParsingResult(i,a,!0),a.str=l,null}return s.serializeParsingResult(i,a),t.recycle(),a.pure?a.str:a.obj})},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(11),o=r(4);t.evalReference=({config:e,stream:t,decl:r,scope:s,result:a})=>{const l=t.index,i=o.evalRawReference({config:e,stream:t,decl:r,scope:s,result:a}),u=n.typeOf(i);if(r.tag&&(a.obj[r.tag]=i),t.stash(),null===i)return t.pop(),!(!r.multiplier||"optional"!==r.multiplier.type);if(e.locationData&&"object"===u){const{end:r,start:n}=e.locationData;i[n]=l,i[r]=t.index-1}if(r.spread){if("object"!==u)throw new Error(`"${r.value}" doesn't return a object which is required for the spread operator to work.`);Object.assign(a.obj,i),a.pure=!1}else if(r.tag)a.pure=!1;else if("array"===u&&i.every(e=>"string"==typeof e))a.str+=i.join("");else{if("string"!==u)throw new Error(`Type "${r.value}" is missing a tag.`);a.str+=i}return t.recycle(),!0}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(4),o=r(12);t.evalRawReference=({config:e,stream:t,decl:r,scope:s,result:a})=>{const l=s.lookupByPath(r.value);if(!l)throw new Error(`Failed to resolve "${r.value.join(":")}". If it's a block a default export may be missing.`);const[i,u]=l,c=i.arguments,p=[...r.arguments||[]];if(c){for(const{value:e,name:t}of c){let r=e;const n=p.findIndex(e=>e.name===t);if(~n&&([{value:r}]=p.splice(n,1)),!r)throw new Error(`Argument "${t}" is missing on type ${i.name}.`);u.injectValue(r,t)}if(p.length)throw new Error(`These arguments were passed into "${i.name}" but not expected: ${p.map(e=>e.name).join(", ")}`)}else if(p.length)throw new Error(`Type "${i.name}" does not expect any arguments.`);const f=o.maybeMultiplier(()=>n.evalGroup({config:e,stream:t,decl:i.value,scope:u}))({config:e,stream:t,decl:r,result:a,scope:u});return f&&r.modifiers&&n.evalModification(f,r),f}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.evalString=({stream:e,decl:t,result:r})=>{const{value:n}=t;e.stash();for(let t=0;t<n.length;t++)if(e.next()!==n[t])return e.pop(),!1;return e.recycle(),r.str+=n,!0}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});class n{constructor({parent:e=null,global:t=!1}){this.exports=new Map,this.members=new Map,this.specials=new Map,this.parent=e,this.global=t}registerAll(e){for(const t of e)this.register(t)}register(e){const t=this.resolveValueFor(e);switch(e.variant){case"entry":if(this.specials.has("entry"))throw new Error("There can only be one entry.");if(!this.global)throw new Error("Only the global scope can contain entries.");null!==e.name&&this.setMember(e.name,t),this.specials.set("entry",t);break;case"default":if(this.specials.has("default"))throw new Error("There can only be one default export.");if(this.global)throw new Error("The global scope can't have default exports.");null!==e.name&&this.setMember(e.name,t),this.specials.set("default",t);break;case"export":{const r=e.name;if(this.global)throw new Error("The global scope can't have exported members.");this.exports.set(r,t),this.setMember(e.name,t);break}default:this.setMember(e.name,t)}}setMember(e,t){if(this.members.has(e))throw new Error(`The type named "${e}" is already declared.`);this.members.set(e,t)}injectValue(e,t){this.register({type:"declaration",variant:null,arguments:null,value:e,name:t})}lookupByPath(e){const[t,...r]=e,o=this.lookupByName(t);return o?o instanceof n?o.lookupDeepReference(r):r.length?null:[o,this]:null}lookup(e){const t=this.specials.get(e);return t?t instanceof n?t.lookup("default"):[t,this]:null}resolveValueFor(e){if("block"===e.value.type){const t=new n({parent:this});return t.registerAll(e.value.value),t}return e}lookupByName(e){return this.members.has(e)?this.members.get(e):this.parent?this.parent.lookupByName(e):null}lookupDeepReference(e){const t=e.length?this.exports.get(e.shift()):null;return t?t instanceof n?t.lookupDeepReference(e):e.length?null:[t,this]:e.length?null:this.lookup("default")}}t.Scope=n},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.ENV_VERSION="0.0.19"},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(9),o=r(60),s=r(61),a=r(62),l=r(63),i=[r(65).ws,l.str,o.kw,s.num,a.punc];t.tokenize=e=>{const t=new n.Streamable(e),r=[];e:for(;t.hasNext();){for(const e of i){const n=t.index,o=e(t);if(o){if("/"===o.value&&"/"===t.peek()){for(;t.hasNext()&&"\n"!==t.peek();)t.next();continue e}if("ws"===o.type&&r.length&&"ws"===r[r.length-1].type){const e=r[r.length-1];e.value+=o.value,e.end=t.index;continue e}r.push(Object.assign(Object.assign({},o),{start:n,end:t.index}));continue e}}throw new Error("Failed to parse input sequence.")}return r}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(16),o=r(8);t.kw=e=>{const t=n.consumeWhile(e,(e,t)=>o.isNonWhitespace(e)||!(!o.isNumeric(e)||!t.length));return t.length?{type:"kw",value:t}:null}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(8);t.num=e=>{let t="";for(;e.hasNext();){const r=e.peek();if(!n.isNumeric(r))break;t+=r,e.next()}return t.length?{type:"num",value:Number(t)}:null}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(8);t.punc=e=>n.isPunctuation(e.peek())?{type:"punc",value:e.next()}:null},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(64);t.str=e=>{for(const t of["'",'"',"`"]){if(e.stash(),e.peek()===t){e.next();const r=n.consumeEscaped(e,t);if(null!==r)return{type:"str",value:r}}e.pop()}return null}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.consumeEscaped=(e,t)=>{let r=!1,n="";for(let o=e.next();;o=e.next()){if("\n"===o&&!r)return null;if(r)n+=o,r=!1;else if("\\"===o)r=!0;else{if(o===t)return n;if(!e.hasNext())break;n+=o}}return null}},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});const n=r(16),o=r(8);t.ws=e=>{const t=n.consumeWhile(e,o.isWhiteSpace);return t.length?{type:"ws",value:t}:null}}])},"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Bavary=t():e.Bavary=t();
//# sourceMappingURL=bavary.js.map
import { RawType } from '../tokenizer/types';
import './internal';
import { Declaration } from './types';

@@ -3,0 +4,0 @@ /**

@@ -1,1 +0,1 @@

export {};
export declare const parseCombinator: import("../types").ParserFunction<string>;

@@ -1,1 +0,6 @@

export {};
import { Modifiers } from '../../types';
/**
* Parses a lookup-sequence
* @type {Function}
*/
export declare const parseModification: import("../../types").ParserFunction<Modifiers | null>;

@@ -1,1 +0,5 @@

export {};
/**
* Parses a spread-operator
* @type {Function}
*/
export declare const parseSpreadOperator: import("../types").ParserFunction<true | null>;
/**
* Parses a unicode escape and converts it into a decimal number
*/
export declare const parseUnicodeEscape: (stream: import("../../misc/token-stream").TokenStream) => number | null;
export declare const parseUnicodeEscape: import("../types").ParserFunction<number>;

@@ -1,1 +0,2 @@

export {};
import { Arguments } from '../types';
export declare const parseArguments: import("../types").ParserFunction<Arguments>;

@@ -1,1 +0,2 @@

export {};
import { Block } from '../types';
export declare const parseBlock: import("../types").ParserFunction<Block>;

@@ -1,1 +0,2 @@

export {};
import { CharacterSelection } from '../types';
export declare const parseCharacterSelecton: import("../types").ParserFunction<CharacterSelection>;

@@ -1,1 +0,2 @@

export {};
import { ConditionalStatement, ParserFunction } from '../types';
export declare const parseConditionalStatement: ParserFunction<ConditionalStatement>;

@@ -1,1 +0,2 @@

export {};
import { Declaration } from '../types';
export declare const parseDeclaration: import("../types").ParserFunction<Declaration>;

@@ -1,1 +0,2 @@

export {};
import { Func } from '../types';
export declare const parseFunction: import("../types").ParserFunction<Func>;

@@ -1,1 +0,2 @@

export {};
import { Group } from '../types';
export declare const parseGroup: import("../types").ParserFunction<Group>;

@@ -1,1 +0,6 @@

export {};
import { Identifier } from '../types';
/**
* Parses an identifier made out of keywords, numbers or hyphens
* @type {Function}
*/
export declare const parseIdentifier: import("../types").ParserFunction<Identifier>;

@@ -1,1 +0,2 @@

export {};
import { Multiplier } from '../types';
export declare const parseMultiplier: import("../types").ParserFunction<Multiplier>;

@@ -1,1 +0,2 @@

export {};
import { Reference } from '../types';
export declare const parseReference: import("../types").ParserFunction<Reference>;

@@ -1,1 +0,2 @@

export {};
import { Str } from '../types';
export declare const parseString: import("../types").ParserFunction<Str>;

@@ -1,1 +0,2 @@

export {};
import { Tag } from '../types';
export declare const parseTag: import("../types").ParserFunction<Tag>;

@@ -1,1 +0,2 @@

export {};
import { ValueAccessor } from '../types';
export declare const parseValueAccessor: import("../types").ParserFunction<ValueAccessor>;

@@ -1,2 +0,2 @@

import { TokenStream } from '../../misc/token-stream';
import { ParserFunction } from '../types';
/**

@@ -7,2 +7,2 @@ * Restores the previous location if the passed function returns null

*/
export declare const maybe: <T>(fn: (stream: TokenStream) => T | null) => (stream: TokenStream) => T | null;
export declare const maybe: <T>(fn: ParserFunction<T>) => ParserFunction<T>;

@@ -1,2 +0,4 @@

export declare type ASTNode = Declaration | CharacterSelection | Type | Group | Multiplier | Reference | Block | Str;
import { TokenStream } from '../misc/token-stream';
export declare type ASTNode = Declaration | CharacterSelection | ValueAccessor | ConditionalStatement | Arguments | Func | Multiplier | Tag | BinaryExpressionValue | Type | Group | Multiplier | Reference | Block | Str;
export declare type ParserFunction<T> = (stream: TokenStream) => T | null;
export declare type DeclarationValue = Group | Block;

@@ -20,3 +22,3 @@ export declare type DeclarationVariant = 'entry' | 'default' | 'export' | null;

type: 'group';
multiplier: Multiplier;
multiplier: Multiplier | null;
value: Array<GroupValue>;

@@ -37,2 +39,6 @@ };

};
export declare type Num = {
type: 'number';
value: number;
};
export declare type Str = {

@@ -101,6 +107,13 @@ type: 'string';

type: 'conditional-statement';
condition: [Tag, ValueAccessorPath | null];
negated: boolean;
then: Group;
alternative: Group | null;
condition: BinaryExpression;
consequent: Group;
alternate: Group | ConditionalStatement | null;
};
export declare type BinaryExpressionValue = BinaryExpression | Str | Identifier | Num | ValueAccessor;
export declare type BinaryOperator = '|' | '&' | '=' | '!=' | '<' | '>';
export declare type BinaryExpression = {
type: 'binary-expression';
operator: BinaryOperator;
left: BinaryExpressionValue;
right: BinaryExpressionValue;
};

@@ -1,1 +0,3 @@

export {};
import { CharacterSelection } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalCharacterSelection: ({ config, stream, decl, scope, result }: ParserArgs<CharacterSelection>) => boolean;

@@ -1,1 +0,3 @@

export {};
import { BinaryCombinator } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalCombiantor: ({ config, stream, decl, scope, result }: ParserArgs<BinaryCombinator>) => boolean;

@@ -1,1 +0,3 @@

export {};
import { ConditionalStatement } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalConditionalStatement: ({ config, stream, decl, scope, result }: ParserArgs<ConditionalStatement>) => boolean;

@@ -1,1 +0,3 @@

export {};
import { GroupValue } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalDeclaration: ({ config, stream, decl, scope, result }: ParserArgs<GroupValue>) => boolean;

@@ -1,1 +0,3 @@

export {};
import { Func } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalFunction: ({ config, stream, decl, scope, result }: ParserArgs<Func>) => boolean;

@@ -1,1 +0,10 @@

export {};
import { Group } from '../../ast/types';
import { ParsingResultObjectValue } from '../types';
export declare const evalGroup: (args: {
decl: Group;
scope: import("../scope").Scope;
config: import("../types").CompilerConfig;
stream: import("../../misc/stream").Streamable<string>;
} & {
result?: import("../types").ParsingResult | undefined;
}) => string | number | ParsingResultObjectValue[] | import("../types").ParsingResultObject | ParsingResultObjectValue[] | null;
import { ModifierTarget, Reference } from '../../../ast/types';
export declare const applyModifications: (res: ModifierTarget, decl: Reference) => void;
export declare const evalModification: (res: ModifierTarget, decl: Reference) => void;

@@ -1,1 +0,3 @@

export {};
import { Reference } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalReference: ({ config, stream, decl, scope, result }: ParserArgs<Reference>) => boolean;

@@ -1,1 +0,3 @@

export {};
import { Reference } from '../../ast/types';
import { ParserArgs, ParsingResultObjectValue } from '../types';
export declare const evalRawReference: ({ config, stream, decl, scope, result }: ParserArgs<Reference>) => ParsingResultObjectValue;

@@ -1,1 +0,3 @@

export {};
import { Str } from '../../ast/types';
import { ParserArgs } from '../types';
export declare const evalString: ({ stream, decl, result }: ParserArgs<Str>) => boolean;

@@ -19,5 +19,5 @@ import { Streamable } from '../misc/stream';

};
export declare type Parser = (content: string) => null | object;
export declare type ParsingFunction = (res: ParserActions, ...args: Array<Array<ParsingResultObjectValue> | ParsingResultObjectValue>) => boolean;
export declare type ParserActions = {
export declare type Parser = (content: string) => null | ParsingResultObjectValue;
export declare type CustomFunction = (res: CustomFunctionUtils, ...args: Array<Array<ParsingResultObjectValue> | ParsingResultObjectValue>) => boolean;
export declare type CustomFunctionUtils = {
/**

@@ -44,3 +44,3 @@ * Current state.

functions?: {
[key: string]: ParsingFunction;
[key: string]: CustomFunction;
};

@@ -47,0 +47,0 @@ };

{
"name": "@bavary/core",
"version": "0.0.18",
"version": "0.0.19",
"description": "Customizable, elegant and fast syntax-parser",

@@ -27,3 +27,2 @@ "author": "Simon Reinisch <trash@reinisch.io>",

"test": "mocha -r ts-node/register test/**/*.spec.ts --timeout 10000",
"test:docs": "markdown-doctest",
"test:coverage": "nyc npm test",

@@ -46,17 +45,17 @@ "test:report": "nyc report --reporter=text-lcov | coveralls",

"@types/mocha": "^5.2.7",
"@types/node": "^12.12.17",
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"@types/node": "^13.1.1",
"@typescript-eslint/eslint-plugin": "^2.13.0",
"@typescript-eslint/parser": "^2.13.0",
"chai": "^4.2.0",
"coveralls": "^3.0.9",
"eslint": "^6.7.2",
"eslint": "^6.8.0",
"eslint-config-problems": "^3.0.1",
"eslint-loader": "^3.0.3",
"mocha": "^6.2.2",
"nyc": "^14.1.1",
"terser-webpack-plugin": "^2.3.0",
"nyc": "^15.0.0",
"terser-webpack-plugin": "^2.3.1",
"ts-loader": "^6.2.1",
"ts-node": "^8.5.4",
"typescript": "^3.7.3",
"webpack": "^4.41.2",
"typescript": "^3.7.4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"

@@ -63,0 +62,0 @@ },

@@ -90,2 +90,3 @@ <h3 align="center">

* [@bavary/cli](https://github.com/Simonwep/bavary-cli) _- CLI with development server._
* [@bavary/lib](https://github.com/Simonwep/bavary-lib) _- Standard library with extensions for bavary._
* [@bavary/bavary-lib](https://github.com/Simonwep/bavary-lib) _- Standard library with extensions for bavary._
* [@bavary/webpack-loader](https://github.com/Simonwep/bavary-webpack-loader) _- Webpack loader for declaration files._

@@ -1,4 +0,6 @@

import {TokenStream} from '../misc/token-stream';
import {RawType} from '../tokenizer/types';
import {Declaration} from './types';
import {TokenStream} from '../misc/token-stream';
import {RawType} from '../tokenizer/types';
import './internal';
import {parseDeclaration} from './nodes/declaration';
import {Declaration} from './types';

@@ -11,3 +13,2 @@ /**

export const parseAST = (tokens: Array<RawType>, source: string): Array<Declaration> => {
const declaration = require('./nodes/declaration');
const stream = new TokenStream(tokens, source);

@@ -17,3 +18,3 @@ const declarations: Array<Declaration> = [];

while (stream.hasNext()) {
declarations.push(declaration(stream));
declarations.push(parseDeclaration(stream) as Declaration);
}

@@ -20,0 +21,0 @@

import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
module.exports = maybe<string>(stream => {
export const parseCombinator = maybe<string>(stream => {
const combinator = optional(stream, false, 'punc', '|', '&');

@@ -6,0 +6,0 @@

@@ -1,12 +0,9 @@

import {TokenStream} from '../../../misc/token-stream';
import {expect} from '../../tools/expect';
import {skipWhitespace} from '../../tools/skip-whitespace';
import {DefineModifier} from '../../types';
import {TokenStream} from '../../../misc/token-stream';
import {parseIdentifier, parseString, parseValueAccessor} from '../../internal';
import {expect} from '../../tools/expect';
import {skipWhitespace} from '../../tools/skip-whitespace';
import {DefineModifier} from '../../types';
export const parseDefineModifier = (stream: TokenStream): DefineModifier => {
const valueAccessor = require('../../nodes/value-accessor');
const string = require('../../nodes/string');
const identifier = require('../../nodes/identifier');
const key = identifier(stream);
const key = parseIdentifier(stream);
if (!key) {

@@ -19,3 +16,3 @@ stream.throwError('Expected identifier');

const val = string(stream) || valueAccessor(stream);
const val = parseString(stream) || parseValueAccessor(stream);
if (!val) {

@@ -22,0 +19,0 @@ stream.throwError('Expected string, function-call or value-accessor.');

@@ -1,8 +0,7 @@

import {TokenStream} from '../../../misc/token-stream';
import {DeleteModifier} from '../../types';
import {TokenStream} from '../../../misc/token-stream';
import {parseValueAccessor} from '../../nodes/value-accessor';
import {DeleteModifier} from '../../types';
export const parseDeleteModifier = (stream: TokenStream): DeleteModifier => {
const valueAccessor = require('../../nodes/value-accessor');
const param = valueAccessor(stream);
const param = parseValueAccessor(stream);
if (!param) {

@@ -9,0 +8,0 @@ stream.throwError('Expected a value accessor.');

@@ -21,3 +21,3 @@ import {TokenStream} from '../../../misc/token-stream';

*/
module.exports = maybe<Modifiers | null>(stream => {
export const parseModification = maybe<Modifiers | null>(stream => {
if (!optional(stream, false, 'punc', '{')) {

@@ -24,0 +24,0 @@ return null;

@@ -8,3 +8,3 @@ import {maybe} from '../tools/maybe';

*/
module.exports = maybe<true | null>(stream => {
export const parseSpreadOperator = maybe<true | null>(stream => {
for (let i = 0; i < 3; i++) {

@@ -11,0 +11,0 @@ if (!optional(stream, false, 'punc', '.')) {

@@ -0,0 +0,0 @@ import {RawType} from '../../tokenizer/types';

@@ -1,9 +0,8 @@

import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {skipWhitespace} from '../tools/skip-whitespace';
import {Arguments} from '../types';
import {parseGroup, parseIdentifier} from '../internal';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {skipWhitespace} from '../tools/skip-whitespace';
import {Arguments} from '../types';
module.exports = maybe<Arguments>(stream => {
const parseIdentifier = require('./identifier');
const parseGroup = require('./group');
export const parseArguments = maybe<Arguments>(stream => {
const args: Arguments = [];

@@ -10,0 +9,0 @@

@@ -0,1 +1,2 @@

import {parseDeclaration} from '../internal';
import {check} from '../tools/check';

@@ -7,4 +8,3 @@ import {expect} from '../tools/expect';

module.exports = maybe<Block>(stream => {
const parseDeclaration = require('./declaration');
export const parseBlock = maybe<Block>(stream => {

@@ -20,3 +20,3 @@ // It may be a block

while (!check(stream, false, 'punc', '}')) {
declarations.push(parseDeclaration(stream));
declarations.push(parseDeclaration(stream) as Declaration);
}

@@ -23,0 +23,0 @@

import {TokenStream} from '../../misc/token-stream';
import {RawType} from '../../tokenizer/types';
import {parseMultiplier} from '../internal';
import {parseUnicodeEscape} from '../modifiers/unicode-escape';

@@ -91,5 +92,3 @@ import {expect} from '../tools/expect';

module.exports = maybe<CharacterSelection>(stream => {
const parseMultiplier = require('./multiplier');
export const parseCharacterSelecton = maybe<CharacterSelection>(stream => {
if (!optional(stream, false, 'punc', '(')) {

@@ -96,0 +95,0 @@ return null;

@@ -1,10 +0,7 @@

import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {ConditionalStatement} from '../types';
import {parseBinaryExpression, parseGroup} from '../internal';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {ConditionalStatement, Group, ParserFunction} from '../types';
module.exports = maybe<ConditionalStatement>(stream => {
const parseValueAccessor = require('./value-accessor');
const parseGroup = require('./group');
const parseTag = require('./tag');
export const parseConditionalStatement: ParserFunction<ConditionalStatement> = maybe(stream => {
if (!optional(stream, false, 'kw', 'if')) {

@@ -14,14 +11,8 @@ return null;

// User may used the not-keyword to negate the condition
const negated = !!optional(stream, false, 'kw', 'not');
// Parse tag
const tag = parseTag(stream);
if (!tag) { // TODO: Create util to expect a value
stream.throwError('Expected a tag.');
// Parse condition
const condition = parseBinaryExpression(stream);
if (!condition) {
stream.throwError('Expected a binary expression.');
}
// The accessor-path is optional
const accessorPath = parseValueAccessor(stream)?.value || null;
// Parse then-block

@@ -34,5 +25,5 @@ const then = parseGroup(stream);

// The else-branch is optional
let alternative = null;
let alternative: Group | ConditionalStatement | null = null;
if (optional(stream, false, 'kw', 'else')) {
alternative = parseGroup(stream);
alternative = parseGroup(stream) || parseConditionalStatement(stream);

@@ -46,6 +37,6 @@ if (!alternative) {

type: 'conditional-statement',
condition: [tag, accessorPath],
negated,
then, alternative
condition,
consequent: then,
alternate: alternative
} as ConditionalStatement;
});

@@ -1,11 +0,8 @@

import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Declaration} from '../types';
import {parseArguments, parseBlock, parseGroup, parseIdentifier} from '../internal';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Declaration} from '../types';
module.exports = maybe<Declaration>(stream => {
const parseIdentifier = require('./identifier');
const parseArguments = require('./arguments');
const parseGroup = require('./group');
const parseBlock = require('./block');
export const parseDeclaration = maybe<Declaration>(stream => {

@@ -12,0 +9,0 @@ // Parse optional variant

@@ -1,11 +0,11 @@

import {check} from '../tools/check';
import {combine} from '../tools/combine';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {skipWhitespace} from '../tools/skip-whitespace';
import {Func, Group, Identifier, Reference, Str, Tag} from '../types';
import {parseGroup, parseIdentifier, parseReference, parseString, parseTag} from '../internal';
import {check} from '../tools/check';
import {combine} from '../tools/combine';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {skipWhitespace} from '../tools/skip-whitespace';
import {Func, FuncArgument} from '../types';
module.exports = maybe<Func>(stream => {
const parseIdentifier = require('./identifier');
export const parseFunction = maybe<Func>(stream => {

@@ -18,8 +18,8 @@ skipWhitespace(stream);

const parse = combine<Tag | Group | Str | Reference | Identifier>(
require('./identifier'),
require('./tag'),
require('./group'),
require('./string'),
require('./reference')
const parse = combine<FuncArgument | null>(
parseIdentifier,
parseTag,
parseGroup,
parseString,
parseReference
);

@@ -26,0 +26,0 @@

@@ -1,17 +0,11 @@

import {check} from '../tools/check';
import {combine} from '../tools/combine';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {BinaryCombinator, CharacterSelection, ConditionalStatement, Func, Group, GroupValue, Reference, Str} from '../types';
import {parseCharacterSelecton, parseConditionalStatement, parseFunction, parseMultiplier, parseReference, parseString} from '../internal';
import {parseCombinator} from '../modifiers/combinator';
import {check} from '../tools/check';
import {combine} from '../tools/combine';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {BinaryCombinator, Group, GroupValue} from '../types';
module.exports = maybe<Group>(stream => {
const parseCombinator = require('../modifiers/combinator');
const parseConditionalStatement = require('./conditional-statement');
const parseCharacterSelection = require('./character-selection');
const parseMultiplier = require('./multiplier');
const parseReference = require('./reference');
const parseString = require('./string');
const parseGroup = require('./group');
const parseFunction = require('./function');
export const parseGroup = maybe<Group>(stream => {

@@ -24,8 +18,8 @@ // It may be a group

const values: Array<GroupValue> = [];
const parsers = combine<Reference | Group | CharacterSelection | ConditionalStatement | Str | Func>(
const parsers = combine<GroupValue | null>(
parseConditionalStatement,
parseFunction,
parseGroup,
parseReference,
parseConditionalStatement,
parseCharacterSelection,
parseCharacterSelecton,
parseString

@@ -32,0 +26,0 @@ );

@@ -9,3 +9,3 @@ import {RawType} from '../../tokenizer/types';

*/
module.exports = maybe<Identifier>(stream => {
export const parseIdentifier = maybe<Identifier>(stream => {
let name = '';

@@ -21,3 +21,3 @@

(type === 'num') ||
( type === 'kw')
(type === 'kw')
) {

@@ -24,0 +24,0 @@ name += value;

@@ -13,3 +13,3 @@ import {RawType} from '../../tokenizer/types';

module.exports = maybe<Multiplier | null>(stream => {
export const parseMultiplier = maybe<Multiplier>(stream => {
const mp = optional(stream, false, 'punc', '*', '+', '?', '{');

@@ -16,0 +16,0 @@

@@ -1,13 +0,10 @@

import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Reference} from '../types';
import {parseArguments, parseIdentifier, parseMultiplier, parseTag} from '../internal';
import {parseModification} from '../modifiers/modifications';
import {parseSpreadOperator} from '../modifiers/spread-operator';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Reference} from '../types';
module.exports = maybe<Reference>(stream => {
const parseSpreadOperator = require('../modifiers/spread-operator');
const parseModifiers = require('../modifiers/modifications');
const parseMultipliers = require('./multiplier');
const parseIdentifier = require('./identifier');
const parseArguments = require('./arguments');
const parseTag = require('./tag');
export const parseReference = maybe<Reference>(stream => {

@@ -52,7 +49,7 @@ // It may have a spread operator attached to it

const modifiers = parseModifiers(stream);
const mods = parseModification(stream);
const args = parseArguments(stream);
expect(stream, false, 'punc', '>');
const multiplier = parseMultipliers(stream);
const mult = parseMultiplier(stream);

@@ -63,4 +60,4 @@ return {

arguments: args,
multiplier,
modifiers,
modifiers: mods,
multiplier: mult,
spread,

@@ -67,0 +64,0 @@ value

@@ -5,3 +5,3 @@ import {maybe} from '../tools/maybe';

module.exports = maybe<Str | null>(stream => {
export const parseString = maybe<Str>(stream => {
const string = optional(stream, false, 'str');

@@ -8,0 +8,0 @@

@@ -1,6 +0,7 @@

import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Tag} from '../types';
import {parseIdentifier} from '../internal';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Tag} from '../types';
module.exports = maybe<Tag | null>(stream => {
export const parseTag = maybe<Tag>(stream => {
if (!optional(stream, false, 'punc', '#')) {

@@ -10,5 +11,5 @@ return null;

const ident = require('./identifier')(stream);
const ident = parseIdentifier(stream);
if (!ident) {
stream.throwError('Expected tag-identifier');
return stream.throwError('Expected tag-identifier');
}

@@ -15,0 +16,0 @@

@@ -1,6 +0,7 @@

import {combine} from '../tools/combine';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {ValueAccessor} from '../types';
import {parseIdentifier} from '../internal';
import {combine} from '../tools/combine';
import {expect} from '../tools/expect';
import {maybe} from '../tools/maybe';
import {optional} from '../tools/optional';
import {Identifier, ValueAccessor} from '../types';

@@ -12,3 +13,3 @@ const parseObjectAccessor = maybe<string>(stream => {

const ident = require('./identifier')(stream);
const ident = parseIdentifier(stream);
if (!ident) {

@@ -18,3 +19,3 @@ stream.throwError('Expected identifier.');

return ident.value;
return (ident as Identifier).value;
});

@@ -33,4 +34,3 @@

module.exports = maybe<ValueAccessor>(stream => {
const parseIdentifier = require('./identifier');
export const parseValueAccessor = maybe<ValueAccessor>(stream => {
const entry = parseIdentifier(stream);

@@ -46,3 +46,3 @@

for (let val = null; (val = parser(stream)) !== null;) {
accessorPath.push(val);
accessorPath.push(val as string);
}

@@ -49,0 +49,0 @@

@@ -0,0 +0,0 @@ import {TokenStream} from '../../misc/token-stream';

@@ -0,0 +0,0 @@ import {TokenStream} from '../../misc/token-stream';

@@ -1,2 +0,3 @@

import {TokenStream} from '../../misc/token-stream';
import {TokenStream} from '../../misc/token-stream';
import {ParserFunction} from '../types';

@@ -8,13 +9,15 @@ /**

*/
export const maybe = <T>(fn: (stream: TokenStream) => T | null) => (stream: TokenStream): T | null => {
stream.stash();
export const maybe = <T>(fn: ParserFunction<T>): ParserFunction<T> => {
return (stream: TokenStream): T | null => {
stream.stash();
const result = fn(stream);
if (result !== null) {
stream.recycle();
return result;
}
const result = fn(stream);
if (result !== null) {
stream.recycle();
return result;
}
stream.pop();
return null;
stream.pop();
return null;
};
};

@@ -0,0 +0,0 @@ import {TokenStream} from '../../misc/token-stream';

@@ -1,4 +0,8 @@

export type ASTNode = Declaration | CharacterSelection |
Type | Group | Multiplier | Reference | Block | Str;
import {TokenStream} from '../misc/token-stream';
export type ASTNode = Declaration | CharacterSelection | ValueAccessor | ConditionalStatement |
Arguments | Func | Multiplier | Tag | BinaryExpressionValue | Type | Group | Multiplier | Reference | Block | Str;
export type ParserFunction<T> = (stream: TokenStream) => T | null;
export type DeclarationValue = Group | Block;

@@ -26,3 +30,3 @@ export type DeclarationVariant = 'entry' | 'default' | 'export' | null;

type: 'group';
multiplier: Multiplier;
multiplier: Multiplier | null;
value: Array<GroupValue>;

@@ -47,2 +51,7 @@ }

export type Num = {
type: 'number';
value: number;
}
export type Str = {

@@ -108,3 +117,2 @@ type: 'string';

export type CharacterSelectionArray = Array<number | [number, number]>;
export type Block = {

@@ -123,6 +131,14 @@ type: 'block';

type: 'conditional-statement';
condition: [Tag, ValueAccessorPath | null];
negated: boolean;
then: Group;
alternative: Group | null;
condition: BinaryExpression;
consequent: Group;
alternate: Group | ConditionalStatement | null;
}
export type BinaryExpressionValue = BinaryExpression | Str | Identifier | Num | ValueAccessor;
export type BinaryOperator = '|' | '&' | '=' | '!=' | '<' | '>';
export type BinaryExpression = {
type: 'binary-expression';
operator: BinaryOperator;
left: BinaryExpressionValue;
right: BinaryExpressionValue;
}

@@ -1,5 +0,6 @@

import {Declaration} from '../ast/types';
import {Streamable} from '../misc/stream';
import {Scope} from './scope';
import {CompilerConfig, Parser} from './types';
import {Declaration, Group} from '../ast/types';
import {Streamable} from '../misc/stream';
import {evalGroup} from './internal';
import {Scope} from './scope';
import {CompilerConfig, Parser, ParsingResultObjectValue} from './types';

@@ -19,3 +20,2 @@ /**

): Parser => {
const group = require('./parser/group');

@@ -43,11 +43,11 @@ // Resolve sub-scopes

const [decl, scope] = entry;
return (content: string): null | object => {
return (content: string): null | ParsingResultObjectValue => {
// Parse and return result if successful
const stream = new Streamable(content);
const res = group({
const res = evalGroup({
config,
stream,
decl: decl.value,
scope
scope,
decl: decl.value as Group
});

@@ -54,0 +54,0 @@

import {CharacterSelection, CharacterSelectionArray} from '../../ast/types';
import {maybeMultiplier} from '../tools/multiplier';
import {ParserArgs} from '../types';
import {maybeMultiplier} from './multiplier';

@@ -18,3 +18,3 @@ /**

module.exports = (
export const evalCharacterSelection = (
{

@@ -21,0 +21,0 @@ config,

import {BinaryCombinator} from '../../ast/types';
import {evalDeclaration} from '../internal';
import {serializeParsingResult} from '../tools/serialize';
import {ParserArgs} from '../types';
module.exports = (
export const evalCombiantor = (
{

@@ -14,3 +15,2 @@ config,

): boolean => {
const parseDeclaration = require('./declaration');
stream.stash();

@@ -27,3 +27,3 @@

for (let i = 0; i < decs.length; i++) {
if (parseDeclaration({config, stream, decl: decs[i], scope, result})) {
if (evalDeclaration({config, stream, decl: decs[i], scope, result})) {
stream.recycle();

@@ -42,3 +42,3 @@ return true;

for (let i = 0; i < cpy.length; i++) {
if (parseDeclaration({config, stream, decl: cpy[i], scope, result})) {
if (evalDeclaration({config, stream, decl: cpy[i], scope, result})) {
cpy.splice(i, 1);

@@ -45,0 +45,0 @@ i = -1;

@@ -1,9 +0,7 @@

import {ConditionalStatement} from '../../ast/types';
import {lookupValue} from '../tools/lookup-value';
import {ParserArgs} from '../types';
import {ConditionalStatement, Group} from '../../ast/types';
import {evalGroup} from '../internal';
import {evalBinaryExpression} from '../tools/eval-binary-expression';
import {ParserArgs} from '../types';
const isNullOrUndefined = (v: unknown): boolean => v === null || v === undefined;
module.exports = (
export const evalConditionalStatement = (
{

@@ -17,15 +15,7 @@ config,

): boolean => {
const parseGroup = require('./group');
const {condition, then, alternative, negated} = decl;
const [tag, accessor] = condition;
const tagValue = result.obj[tag.value];
const {condition, consequent, alternate} = decl;
const conditionValue = evalBinaryExpression(result, condition);
// Check condition based on whenever the value is not falsy
const evaluatedCondition = tagValue && (
!accessor || // There's also no deep-accessor attached to it
!isNullOrUndefined(lookupValue(tagValue, accessor)) // Deep accessor present but points to nothing
);
// Choose branch and take into account that the user may negate the value
const branch = !evaluatedCondition === negated ? then : alternative;
const branch = conditionValue ? consequent : alternate;

@@ -38,3 +28,3 @@ // Branch not declared, that's fine

// Try to match branch
const res = parseGroup({
const res = (branch.type === 'group' ? evalGroup : evalConditionalStatement)({
config,

@@ -44,6 +34,6 @@ stream,

result,
decl: branch
decl: branch as (Group & ConditionalStatement)
});
return res !== null;
return res !== null && res !== false;
};

@@ -1,5 +0,6 @@

import {GroupValue} from '../../ast/types';
import {ParserArgs} from '../types';
import {GroupValue} from '../../ast/types';
import {evalCharacterSelection, evalCombiantor, evalConditionalStatement, evalFunction, evalGroup, evalReference, evalString} from '../internal';
import {ParserArgs} from '../types';
module.exports = (
export const evalDeclaration = (
{

@@ -13,9 +14,2 @@ config,

): boolean => {
const parseConditionalStatement = require('./conditional-statement');
const parseCharacterSelection = require('./character-selection');
const parseCombinator = require('./combinator');
const parseReference = require('./reference');
const parseFunction = require('./function');
const parseString = require('./string');
const parseGroup = require('./group');

@@ -26,3 +20,3 @@ stream.stash();

if (!parseCombinator({config, stream, decl, scope, result})) {
if (!evalCombiantor({config, stream, decl, scope, result})) {
stream.pop();

@@ -36,3 +30,3 @@ return false;

if (!parseString({config, stream, decl, scope, result})) {
if (!evalString({config, stream, decl, scope, result})) {
stream.pop();

@@ -46,3 +40,3 @@ return false;

if (!parseCharacterSelection({config, stream, decl, scope, result})) {
if (!evalCharacterSelection({config, stream, decl, scope, result})) {
stream.pop();

@@ -56,3 +50,3 @@ return false;

if (!parseReference({config, stream, decl, scope, result})) {
if (!evalReference({config, stream, decl, scope, result})) {
stream.pop();

@@ -65,3 +59,3 @@ return false;

case 'group': {
const res = parseGroup({config, stream, decl, scope, result});
const res = evalGroup({config, stream, decl, scope, result});

@@ -86,3 +80,3 @@ if (!res) {

if (!parseFunction({config, stream, decl, scope, result})) {
if (!evalFunction({config, stream, decl, scope, result})) {
stream.pop();

@@ -96,3 +90,3 @@ return false;

if (!parseConditionalStatement({config, stream, decl, scope, result})) {
if (!evalConditionalStatement({config, stream, decl, scope, result})) {
stream.pop();

@@ -99,0 +93,0 @@ return false;

@@ -1,22 +0,7 @@

import {Func} from '../../ast/types';
import {ParserActions, ParserArgs, ParsingResult} from '../types';
import {Func} from '../../ast/types';
import {evalGroup, evalRawReference} from '../internal';
import {createCustomFunctionUtils} from '../tools/create-custom-function-utils';
import {ParserArgs} from '../types';
const createParserActionsObj = (res: ParsingResult): ParserActions => ({
state: res,
setString(str): void {
if (!res.pure) {
throw new Error('Can\'t apply string, result isn\'t pure.');
}
res.str = str;
},
setProperty(key, val): void {
res.obj[key] = val;
res.pure = false;
}
});
module.exports = (
export const evalFunction = (
{

@@ -30,4 +15,2 @@ config,

): boolean => {
const parseRawReference = require('./resolve-reference');
const parseGroup = require('./group');

@@ -40,7 +23,12 @@ // Resolve arguments

const val = result.obj[arg.value];
resolvedArgs.push(typeof val === 'undefined' ? null : val);
if (val === undefined) {
throw new Error(`Tag "${val}" isn't defined anywhere but used in a function call.`);
}
resolvedArgs.push(val);
break;
}
case 'group': {
resolvedArgs.push(parseGroup({
resolvedArgs.push(evalGroup({
config, stream, decl: arg, scope

@@ -56,3 +44,3 @@ }));

case 'reference': {
resolvedArgs.push(parseRawReference({
resolvedArgs.push(evalRawReference({
config, stream, scope,

@@ -74,3 +62,3 @@ result: {pure: false, obj: {}, str: ''},

return fn(
createParserActionsObj(result),
createCustomFunctionUtils(result),
...resolvedArgs

@@ -77,0 +65,0 @@ );

import {Group} from '../../ast/types';
import {evalDeclaration} from '../internal';
import {maybeMultiplier} from '../tools/multiplier';
import {serializeParsingResult} from '../tools/serialize';
import {ParsingResultObjectValue} from '../types';
import {maybeMultiplier} from './multiplier';
module.exports = maybeMultiplier<ParsingResultObjectValue, Group>((
export const evalGroup = maybeMultiplier<ParsingResultObjectValue, Group>((
{

@@ -19,3 +20,2 @@ config,

): ParsingResultObjectValue => {
const parseDeclaration = require('./declaration');
stream.stash();

@@ -31,3 +31,3 @@

// Parse declaration
if (!parseDeclaration({config, stream, decl, scope, result})) {
if (!evalDeclaration({config, stream, decl, scope, result})) {
stream.pop();

@@ -34,0 +34,0 @@

@@ -5,3 +5,3 @@ import {Modifiers, ModifierTarget, Reference} from '../../../ast/types';

export const applyModifications = (res: ModifierTarget, decl: Reference): void => {
export const evalModification = (res: ModifierTarget, decl: Reference): void => {
for (const ext of decl.modifiers as Modifiers) {

@@ -8,0 +8,0 @@ switch (ext.type) {

import {ModifierTarget, Reference} from '../../ast/types';
import {typeOf} from '../../misc/type-of';
import {evalRawReference} from '../internal';
import {LocationDataObject, ParserArgs} from '../types';
module.exports = (
export const evalReference = (
{

@@ -14,7 +15,6 @@ config,

): boolean => {
const parseRawReference = require('./resolve-reference');
// Type may have a multiplier attached to it
const starts = stream.index;
const matches = parseRawReference({config, stream, decl, scope, result});
const matches = evalRawReference({config, stream, decl, scope, result});

@@ -21,0 +21,0 @@ // Identify result type

@@ -1,7 +0,7 @@

import {ModifierTarget, Reference} from '../../ast/types';
import {Group, ModifierTarget, Reference} from '../../ast/types';
import {evalGroup, evalModification} from '../internal';
import {maybeMultiplier} from '../tools/multiplier';
import {ParserArgs, ParsingResultObjectValue} from '../types';
import {applyModifications} from './modification';
import {maybeMultiplier} from './multiplier';
module.exports = (
export const evalRawReference = (
{

@@ -15,3 +15,2 @@ config,

): ParsingResultObjectValue => {
const parseGroup = require('./group');

@@ -60,6 +59,6 @@ // Resolve reference

const matches = maybeMultiplier<ParsingResultObjectValue, Reference>(
() => parseGroup({
() => evalGroup({
config,
stream,
decl: target.value,
decl: target.value as Group,
scope: newScope

@@ -75,3 +74,3 @@ })

if (decl.modifiers) {
applyModifications(matches as ModifierTarget, decl);
evalModification(matches as ModifierTarget, decl);
}

@@ -78,0 +77,0 @@ }

import {Str} from '../../ast/types';
import {ParserArgs} from '../types';
module.exports = (
export const evalString = (
{stream, decl, result}: ParserArgs<Str>

@@ -6,0 +6,0 @@ ): boolean => {

import {ValueAccessorPath} from '../../ast/types';
import {typeOf} from '../../misc/type-of';

@@ -7,2 +8,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

for (const ent of path) {
const sourceType = typeOf(source);
// Allow access to length propertie of strings and arrays
if ((sourceType === 'array' || sourceType === 'string') && ent === 'length') {
source = source.length;
continue;
}
if (typeof ent === 'string') {

@@ -9,0 +18,0 @@ if (typeof source === 'object' && source !== null) {

@@ -28,6 +28,6 @@ import {GroupValue} from '../../ast/types';

} else if (item.type === 'conditional-statement') {
serializeParsingResult([item.then], target, nullish);
item.alternative && serializeParsingResult([item.alternative], target, nullish);
serializeParsingResult([item.consequent], target, nullish);
item.alternate && serializeParsingResult([item.alternate], target, nullish);
}
}
}

@@ -24,5 +24,5 @@ import {Streamable} from '../misc/stream';

export type Parser = (content: string) => null | object;
export type ParsingFunction = (res: ParserActions, ...args: Array<Array<ParsingResultObjectValue> | ParsingResultObjectValue>) => boolean;
export type ParserActions = {
export type Parser = (content: string) => null | ParsingResultObjectValue;
export type CustomFunction = (res: CustomFunctionUtils, ...args: Array<Array<ParsingResultObjectValue> | ParsingResultObjectValue>) => boolean;
export type CustomFunctionUtils = {

@@ -53,3 +53,3 @@ /**

functions?: {
[key: string]: ParsingFunction;
[key: string]: CustomFunction;
};

@@ -56,0 +56,0 @@ }

@@ -1,2 +0,1 @@

import {ENV_VERSION} from './env';
import {parseAST} from './ast';

@@ -6,2 +5,3 @@ import {Declaration} from './ast/types';

import {CompilerConfig, Parser} from './compiler/types';
import {ENV_VERSION} from './env';
import {tokenize} from './tokenizer';

@@ -8,0 +8,0 @@

@@ -83,8 +83,7 @@ import {ParsingError} from './parsing-error';

throw new ParsingError(source, msg, peek.start, peek.end);
} else {
}
// Otherwise use current index as start and end value
throw new ParsingError(source, msg, index, index);
}
// Otherwise use current index as start and end value
throw new ParsingError(source, msg, index, index);
}
}

@@ -0,0 +0,0 @@ import {Streamable} from '../misc/stream';

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc