hy.js 4.2 KB

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