hy.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. module.exports = function(hljs) {
  2. var keywords = {
  3. 'builtin-name':
  4. // keywords
  5. '!= % %= & &= * ** **= *= *map ' +
  6. '+ += , --build-class-- --import-- -= . / // //= ' +
  7. '/= < << <<= <= = > >= >> >>= ' +
  8. '@ @= ^ ^= abs accumulate all and any ap-compose ' +
  9. 'ap-dotimes ap-each ap-each-while ap-filter ap-first ap-if ap-last ap-map ap-map-when ap-pipe ' +
  10. 'ap-reduce ap-reject apply as-> ascii assert assoc bin break butlast ' +
  11. 'callable calling-module-name car case cdr chain chr coll? combinations compile ' +
  12. 'compress cond cons cons? continue count curry cut cycle dec ' +
  13. 'def default-method defclass defmacro defmacro-alias defmacro/g! defmain defmethod defmulti defn ' +
  14. 'defn-alias defnc defnr defreader defseq del delattr delete-route dict-comp dir ' +
  15. 'disassemble dispatch-reader-macro distinct divmod do doto drop drop-last drop-while empty? ' +
  16. 'end-sequence eval eval-and-compile eval-when-compile even? every? except exec filter first ' +
  17. 'flatten float? fn fnc fnr for for* format fraction genexpr ' +
  18. 'gensym get getattr global globals group-by hasattr hash hex id ' +
  19. 'identity if if* if-not if-python2 import in inc input instance? ' +
  20. 'integer integer-char? integer? interleave interpose is is-coll is-cons is-empty is-even ' +
  21. 'is-every is-float is-instance is-integer is-integer-char is-iterable is-iterator is-keyword is-neg is-none ' +
  22. 'is-not is-numeric is-odd is-pos is-string is-symbol is-zero isinstance islice issubclass ' +
  23. 'iter iterable? iterate iterator? keyword keyword? lambda last len let ' +
  24. 'lif lif-not list* list-comp locals loop macro-error macroexpand macroexpand-1 macroexpand-all ' +
  25. 'map max merge-with method-decorator min multi-decorator multicombinations name neg? next ' +
  26. 'none? nonlocal not not-in not? nth numeric? oct odd? open ' +
  27. 'or ord partition permutations pos? post-route postwalk pow prewalk print ' +
  28. 'product profile/calls profile/cpu put-route quasiquote quote raise range read read-str ' +
  29. 'recursive-replace reduce remove repeat repeatedly repr require rest round route ' +
  30. 'route-with-methods rwm second seq set-comp setattr setv some sorted string ' +
  31. 'string? sum switch symbol? take take-nth take-while tee try unless ' +
  32. 'unquote unquote-splicing vars walk when while with with* with-decorator with-gensyms ' +
  33. 'xi xor yield yield-from zero? zip zip-longest | |= ~'
  34. };
  35. var SYMBOLSTART = 'a-zA-Z_\\-!.?+*=<>&#\'';
  36. var SYMBOL_RE = '[' + SYMBOLSTART + '][' + SYMBOLSTART + '0-9/;:]*';
  37. var SIMPLE_NUMBER_RE = '[-+]?\\d+(\\.\\d+)?';
  38. var SHEBANG = {
  39. className: 'meta',
  40. begin: '^#!', end: '$'
  41. };
  42. var SYMBOL = {
  43. begin: SYMBOL_RE,
  44. relevance: 0
  45. };
  46. var NUMBER = {
  47. className: 'number', begin: SIMPLE_NUMBER_RE,
  48. relevance: 0
  49. };
  50. var STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null});
  51. var COMMENT = hljs.COMMENT(
  52. ';',
  53. '$',
  54. {
  55. relevance: 0
  56. }
  57. );
  58. var LITERAL = {
  59. className: 'literal',
  60. begin: /\b([Tt]rue|[Ff]alse|nil|None)\b/
  61. };
  62. var COLLECTION = {
  63. begin: '[\\[\\{]', end: '[\\]\\}]'
  64. };
  65. var HINT = {
  66. className: 'comment',
  67. begin: '\\^' + SYMBOL_RE
  68. };
  69. var HINT_COL = hljs.COMMENT('\\^\\{', '\\}');
  70. var KEY = {
  71. className: 'symbol',
  72. begin: '[:]{1,2}' + SYMBOL_RE
  73. };
  74. var LIST = {
  75. begin: '\\(', end: '\\)'
  76. };
  77. var BODY = {
  78. endsWithParent: true,
  79. relevance: 0
  80. };
  81. var NAME = {
  82. keywords: keywords,
  83. lexemes: SYMBOL_RE,
  84. className: 'name', begin: SYMBOL_RE,
  85. starts: BODY
  86. };
  87. var DEFAULT_CONTAINS = [LIST, STRING, HINT, HINT_COL, COMMENT, KEY, COLLECTION, NUMBER, LITERAL, SYMBOL];
  88. LIST.contains = [hljs.COMMENT('comment', ''), NAME, BODY];
  89. BODY.contains = DEFAULT_CONTAINS;
  90. COLLECTION.contains = DEFAULT_CONTAINS;
  91. return {
  92. aliases: ['hylang'],
  93. illegal: /\S/,
  94. contains: [SHEBANG, LIST, STRING, HINT, HINT_COL, COMMENT, KEY, COLLECTION, NUMBER, LITERAL]
  95. }
  96. };