123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- 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
|