xl.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. Language: XL
  3. Author: Christophe de Dinechin <christophe@taodyne.com>
  4. Description: An extensible programming language, based on parse tree rewriting
  5. Website: http://xlr.sf.net
  6. */
  7. function xl(hljs) {
  8. const KWS = [
  9. "if",
  10. "then",
  11. "else",
  12. "do",
  13. "while",
  14. "until",
  15. "for",
  16. "loop",
  17. "import",
  18. "with",
  19. "is",
  20. "as",
  21. "where",
  22. "when",
  23. "by",
  24. "data",
  25. "constant",
  26. "integer",
  27. "real",
  28. "text",
  29. "name",
  30. "boolean",
  31. "symbol",
  32. "infix",
  33. "prefix",
  34. "postfix",
  35. "block",
  36. "tree"
  37. ];
  38. const BUILT_INS = [
  39. "in",
  40. "mod",
  41. "rem",
  42. "and",
  43. "or",
  44. "xor",
  45. "not",
  46. "abs",
  47. "sign",
  48. "floor",
  49. "ceil",
  50. "sqrt",
  51. "sin",
  52. "cos",
  53. "tan",
  54. "asin",
  55. "acos",
  56. "atan",
  57. "exp",
  58. "expm1",
  59. "log",
  60. "log2",
  61. "log10",
  62. "log1p",
  63. "pi",
  64. "at",
  65. "text_length",
  66. "text_range",
  67. "text_find",
  68. "text_replace",
  69. "contains",
  70. "page",
  71. "slide",
  72. "basic_slide",
  73. "title_slide",
  74. "title",
  75. "subtitle",
  76. "fade_in",
  77. "fade_out",
  78. "fade_at",
  79. "clear_color",
  80. "color",
  81. "line_color",
  82. "line_width",
  83. "texture_wrap",
  84. "texture_transform",
  85. "texture",
  86. "scale_?x",
  87. "scale_?y",
  88. "scale_?z?",
  89. "translate_?x",
  90. "translate_?y",
  91. "translate_?z?",
  92. "rotate_?x",
  93. "rotate_?y",
  94. "rotate_?z?",
  95. "rectangle",
  96. "circle",
  97. "ellipse",
  98. "sphere",
  99. "path",
  100. "line_to",
  101. "move_to",
  102. "quad_to",
  103. "curve_to",
  104. "theme",
  105. "background",
  106. "contents",
  107. "locally",
  108. "time",
  109. "mouse_?x",
  110. "mouse_?y",
  111. "mouse_buttons"
  112. ];
  113. const BUILTIN_MODULES = [
  114. "ObjectLoader",
  115. "Animate",
  116. "MovieCredits",
  117. "Slides",
  118. "Filters",
  119. "Shading",
  120. "Materials",
  121. "LensFlare",
  122. "Mapping",
  123. "VLCAudioVideo",
  124. "StereoDecoder",
  125. "PointCloud",
  126. "NetworkAccess",
  127. "RemoteControl",
  128. "RegExp",
  129. "ChromaKey",
  130. "Snowfall",
  131. "NodeJS",
  132. "Speech",
  133. "Charts"
  134. ];
  135. const LITERALS = [
  136. "true",
  137. "false",
  138. "nil"
  139. ];
  140. const KEYWORDS = {
  141. $pattern: /[a-zA-Z][a-zA-Z0-9_?]*/,
  142. keyword: KWS,
  143. literal: LITERALS,
  144. built_in: BUILT_INS.concat(BUILTIN_MODULES)
  145. };
  146. const DOUBLE_QUOTE_TEXT = {
  147. className: 'string',
  148. begin: '"',
  149. end: '"',
  150. illegal: '\\n'
  151. };
  152. const SINGLE_QUOTE_TEXT = {
  153. className: 'string',
  154. begin: '\'',
  155. end: '\'',
  156. illegal: '\\n'
  157. };
  158. const LONG_TEXT = {
  159. className: 'string',
  160. begin: '<<',
  161. end: '>>'
  162. };
  163. const BASED_NUMBER = {
  164. className: 'number',
  165. begin: '[0-9]+#[0-9A-Z_]+(\\.[0-9-A-Z_]+)?#?([Ee][+-]?[0-9]+)?'
  166. };
  167. const IMPORT = {
  168. beginKeywords: 'import',
  169. end: '$',
  170. keywords: KEYWORDS,
  171. contains: [ DOUBLE_QUOTE_TEXT ]
  172. };
  173. const FUNCTION_DEFINITION = {
  174. className: 'function',
  175. begin: /[a-z][^\n]*->/,
  176. returnBegin: true,
  177. end: /->/,
  178. contains: [
  179. hljs.inherit(hljs.TITLE_MODE, { starts: {
  180. endsWithParent: true,
  181. keywords: KEYWORDS
  182. } })
  183. ]
  184. };
  185. return {
  186. name: 'XL',
  187. aliases: [ 'tao' ],
  188. keywords: KEYWORDS,
  189. contains: [
  190. hljs.C_LINE_COMMENT_MODE,
  191. hljs.C_BLOCK_COMMENT_MODE,
  192. DOUBLE_QUOTE_TEXT,
  193. SINGLE_QUOTE_TEXT,
  194. LONG_TEXT,
  195. FUNCTION_DEFINITION,
  196. IMPORT,
  197. BASED_NUMBER,
  198. hljs.NUMBER_MODE
  199. ]
  200. };
  201. }
  202. export { xl as default };