const AST = require('./ast') const OsloError = require('./osloError') function element(name, args) { return new AST.HTMLElement({ name: name, attributes: args.filter(arg => arg.constructor === AST.Attribute), contents: args.filter(arg => arg.constructor !== AST.Attribute), }) } const core = { '+': (a, b) => new AST.Number({ value: a.value + b.value }), '-': (a, b) => new AST.Number({ value: a.value - b.value }), '*': (a, b) => new AST.Number({ value: a.value * b.value }), '/': (a, b) => new AST.Number({ value: a.value / b.value }), '=': (a, b) => new AST.Boolean({ value: a.value === b.value }), '>': (a, b) => new AST.Boolean({ value: a.value > b.value }), '<': (a, b) => new AST.Boolean({ value: a.value < b.value }), '>=': (a, b) => new AST.Boolean({ value: a.value >= b.value }), '<=': (a, b) => new AST.Boolean({ value: a.value <= b.value }), list: (...args) => new AST.List({ elements: args }), length: xs => new AST.Number({ value: xs.elements.length }), cons: (x, xs) => new AST.List({ elements: [x, ...xs.elements] }), first: xs => xs.elements[0], rest: xs => new AST.List({ elements: xs.elements.slice(1) }), } const tags = [ '!DOCTYPE', '!doctype', 'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base', 'basefont', 'bdi', 'bdo', 'bgsound', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'content', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'frame', 'frameset', 'h1', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'image', 'img', 'input', 'ins', 'isindex', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'listing', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'multicol', 'nav', 'nextid', 'nobr', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'plaintext', 'pre', 'progress', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr', 'xm' ] tags.forEach(tagName => { core[tagName] = (...args) => element(tagName, args) }) module.exports = core