A templating language that looks like Lisp and compiles to HTML
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

core.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const AST = require('./ast')
  2. const OsloError = require('./osloError')
  3. function element(name, args) {
  4. return new AST.HTMLElement({
  5. name: name,
  6. attributes: args.filter(arg => arg.constructor === AST.Attribute),
  7. contents: args.filter(arg => arg.constructor !== AST.Attribute),
  8. })
  9. }
  10. const core = {
  11. '+': (a, b) => new AST.Number({ value: a.value + b.value }),
  12. '-': (a, b) => new AST.Number({ value: a.value - b.value }),
  13. '*': (a, b) => new AST.Number({ value: a.value * b.value }),
  14. '/': (a, b) => new AST.Number({ value: a.value / b.value }),
  15. '=': (a, b) => new AST.Boolean({ value: a.value === b.value }),
  16. '>': (a, b) => new AST.Boolean({ value: a.value > b.value }),
  17. '<': (a, b) => new AST.Boolean({ value: a.value < b.value }),
  18. '>=': (a, b) => new AST.Boolean({ value: a.value >= b.value }),
  19. '<=': (a, b) => new AST.Boolean({ value: a.value <= b.value }),
  20. list: (...args) => new AST.List({ elements: args }),
  21. length: xs => new AST.Number({ value: xs.elements.length }),
  22. cons: (x, xs) => new AST.List({ elements: [x, ...xs.elements] }),
  23. first: xs => xs.elements[0],
  24. rest: xs => new AST.List({ elements: xs.elements.slice(1) }),
  25. }
  26. const tags = [
  27. '!DOCTYPE',
  28. '!doctype',
  29. 'a',
  30. 'abbr',
  31. 'acronym',
  32. 'address',
  33. 'applet',
  34. 'area',
  35. 'article',
  36. 'aside',
  37. 'audio',
  38. 'b',
  39. 'base',
  40. 'basefont',
  41. 'bdi',
  42. 'bdo',
  43. 'bgsound',
  44. 'big',
  45. 'blink',
  46. 'blockquote',
  47. 'body',
  48. 'br',
  49. 'button',
  50. 'canvas',
  51. 'caption',
  52. 'center',
  53. 'cite',
  54. 'code',
  55. 'col',
  56. 'colgroup',
  57. 'command',
  58. 'content',
  59. 'data',
  60. 'datalist',
  61. 'dd',
  62. 'del',
  63. 'details',
  64. 'dfn',
  65. 'dialog',
  66. 'dir',
  67. 'div',
  68. 'dl',
  69. 'dt',
  70. 'element',
  71. 'em',
  72. 'embed',
  73. 'fieldset',
  74. 'figcaption',
  75. 'figure',
  76. 'font',
  77. 'footer',
  78. 'form',
  79. 'frame',
  80. 'frameset',
  81. 'h1',
  82. 'head',
  83. 'header',
  84. 'hgroup',
  85. 'hr',
  86. 'html',
  87. 'i',
  88. 'iframe',
  89. 'image',
  90. 'img',
  91. 'input',
  92. 'ins',
  93. 'isindex',
  94. 'kbd',
  95. 'keygen',
  96. 'label',
  97. 'legend',
  98. 'li',
  99. 'link',
  100. 'listing',
  101. 'main',
  102. 'map',
  103. 'mark',
  104. 'marquee',
  105. 'menu',
  106. 'menuitem',
  107. 'meta',
  108. 'meter',
  109. 'multicol',
  110. 'nav',
  111. 'nextid',
  112. 'nobr',
  113. 'noembed',
  114. 'noframes',
  115. 'noscript',
  116. 'object',
  117. 'ol',
  118. 'optgroup',
  119. 'option',
  120. 'output',
  121. 'p',
  122. 'param',
  123. 'picture',
  124. 'plaintext',
  125. 'pre',
  126. 'progress',
  127. 'q',
  128. 'rb',
  129. 'rp',
  130. 'rt',
  131. 'rtc',
  132. 'ruby',
  133. 's',
  134. 'samp',
  135. 'script',
  136. 'section',
  137. 'select',
  138. 'shadow',
  139. 'slot',
  140. 'small',
  141. 'source',
  142. 'spacer',
  143. 'span',
  144. 'strike',
  145. 'strong',
  146. 'style',
  147. 'sub',
  148. 'summary',
  149. 'sup',
  150. 'table',
  151. 'tbody',
  152. 'td',
  153. 'template',
  154. 'textarea',
  155. 'tfoot',
  156. 'th',
  157. 'thead',
  158. 'time',
  159. 'title',
  160. 'tr',
  161. 'track',
  162. 'tt',
  163. 'u',
  164. 'ul',
  165. 'var',
  166. 'video',
  167. 'wbr',
  168. 'xm'
  169. ]
  170. tags.forEach(tagName => {
  171. core[tagName] = (...args) => element(tagName, args)
  172. })
  173. module.exports = core