UNPKG

imba

Version:

Intuitive and powerful language for building webapps that fly

469 lines (453 loc) 14.2 kB
function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; }; // imba$inlineHelpers=1 // List of the token pairs that must be balanced. var BALANCED_PAIRS = [ ['(',')'], ['[',']'], ['{','}'], ['{{','}}'], ['INDENT','OUTDENT'], ['CALL_START','CALL_END'], ['PARAM_START','PARAM_END'], ['INDEX_START','INDEX_END'], ['TAG_START','TAG_END'], ['STYLE_START','STYLE_END'], ['BLOCK_PARAM_START','BLOCK_PARAM_END'] ]; var BITWISE_OPERATORS = { '|': true, '&': true, '!&': true, '~': true, '|=': true, '&=': true, '~=': true, '^=': true, '^': true, '<<': true, '<<=': true, '>>': true, '>>=': true }; var ASSIGNMENT_OPERATORS = { '=': true, '=?': true, '??=': true, '||=': true, '&&=': true, '|=': true, '|=?': true, '&=': true, '&=?': true, '^=': true, '^=?': true, '~=': true, '~=?': true }; // The inverse mappings of `BALANCED_PAIRS` we're trying to fix up, so we can // look things up from either end. var INVERSES = {}; // The tokens that signal the start/end of a balanced pair. // var EXPRESSION_START = [] // var EXPRESSION_END = [] for (let i = 0, len = BALANCED_PAIRS.length, pair; i < len; i++) { pair = BALANCED_PAIRS[i]; var left = pair[0]; var rite = pair[1]; INVERSES[rite] = left; INVERSES[left] = rite; BALANCED_PAIRS[left] = rite; }; var ALL_KEYWORDS = [ 'true','false','null','this', 'delete','typeof','in','instanceof', 'throw','break','continue','debugger', 'if','else','switch','for','while','do','try','catch','finally', 'class','extends','super','return', 'undefined','then','unless','until','loop','of','by', 'when','def','tag','do','elif','begin','var','let','self','await','import', 'and','or','is','isnt','not','yes','no','isa','case','nil','require' ]; var TOK = { TERMINATOR: 'TERMINATOR', INDENT: 'INDENT', OUTDENT: 'OUTDENT', DEF_BODY: 'DEF_BODY', THEN: 'THEN', CATCH: 'CATCH' }; var OPERATOR_ALIASES = { and: '&&', or: '||', is: '==', isnt: '!=', isa: 'instanceof' }; var HEREGEX_OMIT = /\s+(?:#.*)?/g; var HEREGEX = /^\/{3}([\s\S]+?)\/{3}([a-z]{0,8})(?!\w)/; var HEX_REGEX = /^#([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}([A-Fa-f0-9]{2})?)$/; var TAG_GLOBAL_ATTRIBUTES = { itemid: 1, itemprop: 1, itemref: 1, itemscope: 1, itemtype: 1, enterkeyhint: 1, autofocus: 1, autocapitalize: 1, autocomplete: 1, accesskey: 1, inputmode: 1, spellcheck: 1, translate: 1, is: 1 }; var SYSVAR_PREFIX = { TAG: 'τ', FLIP: 'ω', VALUE: 'υ', CACHE: 'ρ', KEY: 'κ', ANY: 'φ', B: 'Θ', T: 'τ', C: 'ρ', V: 'υ', K: 'κ', D: 'Δ' }; var TAG_TYPES = { "": [-1,{id: 1,className: 'class',slot: 1,part: 1,elementTiming: 'elementtiming'}], HTML: [-1,{title: 1,lang: 1,translate: 1,dir: 1,accessKey: 'accesskey',draggable: 1,spellcheck: 1,autocapitalize: 1,inputMode: 'inputmode',style: 1,tabIndex: 'tabindex',enterKeyHint: 'enterkeyhint'}], HTMLAnchor: [1,{target: 1,download: 1,ping: 1,rel: 1,relList: 'rel',hreflang: 1,type: 1,referrerPolicy: 'referrerpolicy',coords: 1,charset: 1,name: 1,rev: 1,shape: 1,href: 1}], HTMLArea: [1,{alt: 1,coords: 1,download: 1,shape: 1,target: 1,ping: 1,rel: 1,relList: 'rel',referrerPolicy: 'referrerpolicy',href: 1}], HTMLMedia: [1,{src: 1,crossOrigin: 'crossorigin',preload: 1,controlsList: 'controlslist'}], HTMLAudio: [4,{}], HTMLBase: [1,{href: 1,target: 1}], HTMLQuote: [1,{cite: 1}], HTMLBody: [1,{text: 1,link: 1,vLink: 'vlink',aLink: 'alink',bgColor: 'bgcolor',background: 1}], HTMLBR: [1,{clear: 1}], HTMLButton: [1,{formAction: 'formaction',formEnctype: 'formenctype',formMethod: 'formmethod',formTarget: 'formtarget',name: 1,type: 1,value: 1}], HTMLCanvas: [1,{width: 1,height: 1}], HTMLTableCaption: [1,{align: 1}], HTMLTableCol: [1,{span: 1,align: 1,ch: 'char',chOff: 'charoff',vAlign: 'valign',width: 1}], HTMLData: [1,{value: 1}], HTMLDataList: [1,{}], HTMLMod: [1,{cite: 1,dateTime: 'datetime'}], HTMLDetails: [1,{}], HTMLDialog: [1,{}], HTMLDiv: [1,{align: 1}], HTMLDList: [1,{}], HTMLEmbed: [1,{src: 1,type: 1,width: 1,height: 1,align: 1,name: 1}], HTMLFieldSet: [1,{name: 1}], HTMLForm: [1,{acceptCharset: 'accept-charset',action: 1,autocomplete: 1,enctype: 1,encoding: 'enctype',method: 1,name: 1,target: 1}], HTMLHeading: [1,{align: 1}], HTMLHead: [1,{}], HTMLHR: [1,{align: 1,color: 1,size: 1,width: 1}], HTMLHtml: [1,{version: 1}], HTMLIFrame: [1,{src: 1,srcdoc: 1,name: 1,sandbox: 1,width: 1,height: 1,referrerPolicy: 'referrerpolicy',csp: 1,allow: 1,align: 1,scrolling: 1,frameBorder: 'frameborder',longDesc: 'longdesc',marginHeight: 'marginheight',marginWidth: 'marginwidth',loading: 1}], HTMLImage: [1,{alt: 1,src: 1,srcset: 1,sizes: 1,crossOrigin: 'crossorigin',useMap: 'usemap',width: 1,height: 1,referrerPolicy: 'referrerpolicy',decoding: 1,name: 1,lowsrc: 1,align: 1,hspace: 1,vspace: 1,longDesc: 'longdesc',border: 1,loading: 1}], HTMLInput: [1,{accept: 1,alt: 1,autocomplete: 1,dirName: 'dirname',formAction: 'formaction',formEnctype: 'formenctype',formMethod: 'formmethod',formTarget: 'formtarget',height: 1,max: 1,maxLength: 'maxlength',min: 1,minLength: 'minlength',name: 1,pattern: 1,placeholder: 1,src: 1,step: 1,type: 1,defaultValue: 'value',width: 1,align: 1,useMap: 'usemap'}], HTMLLabel: [1,{htmlFor: 'for'}], HTMLLegend: [1,{align: 1}], HTMLLI: [1,{value: 1,type: 1}], HTMLLink: [1,{href: 1,crossOrigin: 'crossorigin',rel: 1,relList: 'rel',media: 1,hreflang: 1,type: 1,as: 1,referrerPolicy: 'referrerpolicy',sizes: 1,imageSrcset: 'imagesrcset',imageSizes: 'imagesizes',charset: 1,rev: 1,target: 1,integrity: 1}], HTMLMap: [1,{name: 1}], HTMLMenu: [1,{}], HTMLMeta: [1,{name: 1,httpEquiv: 'http-equiv',content: 1,scheme: 1}], HTMLMeter: [1,{value: 1,min: 1,max: 1,low: 1,high: 1,optimum: 1}], HTMLObject: [1,{data: 1,type: 1,name: 1,useMap: 'usemap',width: 1,height: 1,align: 1,archive: 1,code: 1,hspace: 1,standby: 1,vspace: 1,codeBase: 'codebase',codeType: 'codetype',border: 1}], HTMLOList: [1,{start: 1,type: 1}], HTMLOptGroup: [1,{label: 1}], HTMLOption: [1,{label: 1,value: 1}], HTMLOutput: [1,{htmlFor: 'for',name: 1}], HTMLParagraph: [1,{align: 1}], HTMLParam: [1,{name: 1,value: 1,type: 1,valueType: 'valuetype'}], HTMLPicture: [1,{}], HTMLPre: [1,{width: 1}], HTMLProgress: [1,{value: 1,max: 1}], HTMLScript: [1,{src: 1,type: 1,charset: 1,crossOrigin: 'crossorigin',referrerPolicy: 'referrerpolicy',event: 1,htmlFor: 'for',integrity: 1}], HTMLSelect: [1,{autocomplete: 1,name: 1,size: 1}], HTMLSlot: [1,{name: 1}], HTMLSource: [1,{src: 1,type: 1,srcset: 1,sizes: 1,media: 1}], HTMLSpan: [1,{}], HTMLStyle: [1,{media: 1,type: 1}], HTMLTable: [1,{align: 1,border: 1,frame: 1,rules: 1,summary: 1,width: 1,bgColor: 'bgcolor',cellPadding: 'cellpadding',cellSpacing: 'cellspacing'}], HTMLTableSection: [1,{align: 1,ch: 'char',chOff: 'charoff',vAlign: 'valign'}], HTMLTableCell: [1,{colSpan: 'colspan',rowSpan: 'rowspan',headers: 1,align: 1,axis: 1,height: 1,width: 1,ch: 'char',chOff: 'charoff',vAlign: 'valign',bgColor: 'bgcolor',abbr: 1,scope: 1}], HTMLTemplate: [1,{}], HTMLTextArea: [1,{autocomplete: 1,cols: 1,dirName: 'dirname',maxLength: 'maxlength',minLength: 'minlength',name: 1,placeholder: 1,rows: 1,wrap: 1}], HTMLTime: [1,{dateTime: 'datetime'}], HTMLTitle: [1,{}], HTMLTableRow: [1,{align: 1,ch: 'char',chOff: 'charoff',vAlign: 'valign',bgColor: 'bgcolor'}], HTMLTrack: [1,{kind: 1,src: 1,srclang: 1,label: 1}], HTMLUList: [1,{type: 1}], HTMLVideo: [4,{width: 1,height: 1,poster: 1}], SVG: [-1,{}], SVGGraphics: [66,{transform: 1}], SVGA: [67,{}], SVGAnimation: [66,{}], SVGAnimate: [69,{}], SVGAnimateMotion: [69,{}], SVGAnimateTransform: [69,{}], SVGGeometry: [67,{}], SVGCircle: [73,{cx: 1,cy: 1,r: 1}], SVGClipPath: [67,{clipPathUnits: 1}], SVGDefs: [67,{}], SVGDesc: [66,{}], SVGDiscard: [66,{}], SVGEllipse: [73,{cx: 1,cy: 1,rx: 1,ry: 1}], SVGFEBlend: [66,{mode: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEColorMatrix: [66,{type: 1,values: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEComponentTransfer: [66,{x: 1,y: 1,width: 1,height: 1}], SVGFEComposite: [66,{operator: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEConvolveMatrix: [66,{orderX: 1,orderY: 1,kernelMatrix: 1,divisor: 1,edgeMode: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEDiffuseLighting: [66,{surfaceScale: 1,diffuseConstant: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEDisplacementMap: [66,{xChannelSelector: 1,yChannelSelector: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEDistantLight: [66,{}], SVGFEDropShadow: [66,{dx: 1,dy: 1,stdDeviationX: 1,stdDeviationY: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEFlood: [66,{x: 1,y: 1,width: 1,height: 1}], SVGComponentTransferFunction: [66,{type: 1,tableValues: 1,slope: 1,amplitude: 1,exponent: 1}], SVGFEFuncA: [90,{}], SVGFEFuncB: [90,{}], SVGFEFuncG: [90,{}], SVGFEFuncR: [90,{}], SVGFEGaussianBlur: [66,{x: 1,y: 1,width: 1,height: 1}], SVGFEImage: [66,{preserveAspectRatio: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEMerge: [66,{x: 1,y: 1,width: 1,height: 1}], SVGFEMergeNode: [66,{}], SVGFEMorphology: [66,{operator: 1,x: 1,y: 1,width: 1,height: 1}], SVGFEOffset: [66,{x: 1,y: 1,width: 1,height: 1}], SVGFEPointLight: [66,{}], SVGFESpecularLighting: [66,{surfaceScale: 1,specularConstant: 1,specularExponent: 1,x: 1,y: 1,width: 1,height: 1}], SVGFESpotLight: [66,{specularExponent: 1}], SVGFETile: [66,{x: 1,y: 1,width: 1,height: 1}], SVGFETurbulence: [66,{numOctaves: 1,stitchTiles: 1,type: 1,x: 1,y: 1,width: 1,height: 1}], SVGFilter: [66,{filterUnits: 1,primitiveUnits: 1,x: 1,y: 1,width: 1,height: 1}], SVGForeignObject: [67,{x: 1,y: 1,width: 1,height: 1}], SVGG: [67,{}], SVGImage: [67,{x: 1,y: 1,width: 1,height: 1,preserveAspectRatio: 1}], SVGLine: [73,{x1: 1,y1: 1,x2: 1,y2: 1}], SVGGradient: [66,{gradientUnits: 1,gradientTransform: 1,spreadMethod: 1}], SVGLinearGradient: [111,{x1: 1,y1: 1,x2: 1,y2: 1}], SVGMarker: [66,{refX: 1,refY: 1,markerUnits: 1,markerWidth: 1,markerHeight: 1,orientType: 1,orientAngle: 1,viewBox: 1,preserveAspectRatio: 1}], SVGMask: [66,{maskUnits: 1,maskContentUnits: 1,x: 1,y: 1,width: 1,height: 1}], SVGMetadata: [66,{}], SVGMPath: [66,{}], SVGPath: [73,{}], SVGPattern: [66,{patternUnits: 1,patternContentUnits: 1,patternTransform: 1,x: 1,y: 1,width: 1,height: 1,viewBox: 1,preserveAspectRatio: 1}], SVGPolygon: [73,{}], SVGPolyline: [73,{}], SVGRadialGradient: [111,{cx: 1,cy: 1,r: 1,fx: 1,fy: 1,fr: 1}], SVGRect: [73,{x: 1,y: 1,width: 1,height: 1,rx: 1,ry: 1}], SVGScript: [66,{}], SVGSet: [69,{}], SVGStop: [66,{}], SVGStyle: [66,{}], SVGSVG: [67,{x: 1,y: 1,width: 1,height: 1,viewBox: 1,preserveAspectRatio: 1}], SVGSwitch: [67,{}], SVGSymbol: [66,{viewBox: 1,preserveAspectRatio: 1}], SVGTextContent: [67,{textLength: 1,lengthAdjust: 1}], SVGTextPositioning: [130,{x: 1,y: 1,dx: 1,dy: 1,rotate: 1}], SVGText: [131,{}], SVGTextPath: [130,{startOffset: 1,method: 1,spacing: 1}], SVGTitle: [66,{}], SVGTSpan: [131,{}], SVGUse: [67,{x: 1,y: 1,width: 1,height: 1}], SVGView: [66,{viewBox: 1,preserveAspectRatio: 1}] }; var TAG_NAMES = { a: 2, abbr: 1, address: 1, area: 3, article: 1, aside: 1, audio: 5, b: 1, base: 6, bdi: 1, bdo: 1, blockquote: 7, body: 8, br: 9, button: 10, canvas: 11, caption: 12, cite: 1, code: 1, col: 13, colgroup: 13, data: 14, datalist: 15, dd: 1, del: 16, details: 17, dfn: 1, dialog: 18, div: 19, dl: 20, dt: 1, em: 1, embed: 21, fieldset: 22, figcaption: 1, figure: 1, footer: 1, form: 23, h1: 24, h2: 24, h3: 24, h4: 24, h5: 24, h6: 24, head: 25, header: 1, hgroup: 1, hr: 26, html: 27, i: 1, iframe: 28, img: 29, input: 30, ins: 16, kbd: 1, label: 31, legend: 32, li: 33, link: 34, main: 1, map: 35, mark: 1, menu: 36, meta: 37, meter: 38, nav: 1, noscript: 1, object: 39, ol: 40, optgroup: 41, option: 42, output: 43, p: 44, param: 45, picture: 46, pre: 47, progress: 48, q: 7, rp: 1, rt: 1, ruby: 1, s: 1, samp: 1, script: 49, section: 1, select: 50, slot: 51, small: 1, source: 52, span: 53, strike: 1, strong: 1, style: 54, sub: 1, summary: 1, sup: 1, table: 55, tbody: 56, td: 57, template: 58, textarea: 59, tfoot: 56, th: 57, thead: 56, time: 60, title: 61, tr: 62, track: 63, u: 1, ul: 64, 'var': 1, video: 65, wbr: 1, svg_a: 68, svg_animate: 70, svg_animateMotion: 71, svg_animateTransform: 72, svg_audio: 66, svg_canvas: 66, svg_circle: 74, svg_clipPath: 75, svg_defs: 76, svg_desc: 77, svg_discard: 78, svg_ellipse: 79, svg_feBlend: 80, svg_feColorMatrix: 81, svg_feComponentTransfer: 82, svg_feComposite: 83, svg_feConvolveMatrix: 84, svg_feDiffuseLighting: 85, svg_feDisplacementMap: 86, svg_feDistantLight: 87, svg_feDropShadow: 88, svg_feFlood: 89, svg_feFuncA: 91, svg_feFuncB: 92, svg_feFuncG: 93, svg_feFuncR: 94, svg_feGaussianBlur: 95, svg_feImage: 96, svg_feMerge: 97, svg_feMergeNode: 98, svg_feMorphology: 99, svg_feOffset: 100, svg_fePointLight: 101, svg_feSpecularLighting: 102, svg_feSpotLight: 103, svg_feTile: 104, svg_feTurbulence: 105, svg_filter: 106, svg_foreignObject: 107, svg_g: 108, svg_iframe: 66, svg_image: 109, svg_line: 110, svg_linearGradient: 112, svg_marker: 113, svg_mask: 114, svg_metadata: 115, svg_mpath: 116, svg_path: 117, svg_pattern: 118, svg_polygon: 119, svg_polyline: 120, svg_radialGradient: 121, svg_rect: 122, svg_script: 123, svg_set: 124, svg_stop: 125, svg_style: 126, svg_svg: 127, svg_switch: 128, svg_symbol: 129, svg_text: 132, svg_textPath: 133, svg_title: 134, svg_tspan: 135, svg_unknown: 66, svg_use: 136, svg_video: 66, svg_view: 137 }; var keys = Object.keys(TAG_TYPES); for (let i = 0, items = iter$(keys), len = items.length, typ; i < len; i++) { typ = items[i]; let item = TAG_TYPES[typ]; item.up = TAG_TYPES[keys[item[0]]]; item.name = typ + 'Element'; }; for (let ref, i = 0, keys1 = Object.keys(TAG_NAMES), l = keys1.length, name; i < l; i++){ name = keys1[i];ref = TAG_NAMES[name];TAG_NAMES[name] = TAG_TYPES[keys[ref]]; }; export { ALL_KEYWORDS, ASSIGNMENT_OPERATORS, BALANCED_PAIRS, BITWISE_OPERATORS, HEREGEX, HEREGEX_OMIT, HEX_REGEX, INVERSES, OPERATOR_ALIASES, SYSVAR_PREFIX, TAG_GLOBAL_ATTRIBUTES, TAG_NAMES, TAG_TYPES, TOK };