hy.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. const SYMBOLSTART = 'a-zA-Z_\\-!.?+*=<>&#\'';
  10. const SYMBOL_RE = '[' + SYMBOLSTART + '][' + SYMBOLSTART + '0-9/;:]*';
  11. const keywords = {
  12. $pattern: SYMBOL_RE,
  13. built_in:
  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. const SIMPLE_NUMBER_RE = '[-+]?\\d+(\\.\\d+)?';
  46. const SYMBOL = {
  47. begin: SYMBOL_RE,
  48. relevance: 0
  49. };
  50. const NUMBER = {
  51. className: 'number',
  52. begin: SIMPLE_NUMBER_RE,
  53. relevance: 0
  54. };
  55. const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null });
  56. const COMMENT = hljs.COMMENT(
  57. ';',
  58. '$',
  59. { relevance: 0 }
  60. );
  61. const LITERAL = {
  62. className: 'literal',
  63. begin: /\b([Tt]rue|[Ff]alse|nil|None)\b/
  64. };
  65. const COLLECTION = {
  66. begin: '[\\[\\{]',
  67. end: '[\\]\\}]',
  68. relevance: 0
  69. };
  70. const HINT = {
  71. className: 'comment',
  72. begin: '\\^' + SYMBOL_RE
  73. };
  74. const HINT_COL = hljs.COMMENT('\\^\\{', '\\}');
  75. const KEY = {
  76. className: 'symbol',
  77. begin: '[:]{1,2}' + SYMBOL_RE
  78. };
  79. const LIST = {
  80. begin: '\\(',
  81. end: '\\)'
  82. };
  83. const BODY = {
  84. endsWithParent: true,
  85. relevance: 0
  86. };
  87. const NAME = {
  88. className: 'name',
  89. relevance: 0,
  90. keywords: keywords,
  91. begin: SYMBOL_RE,
  92. starts: BODY
  93. };
  94. const DEFAULT_CONTAINS = [
  95. LIST,
  96. STRING,
  97. HINT,
  98. HINT_COL,
  99. COMMENT,
  100. KEY,
  101. COLLECTION,
  102. NUMBER,
  103. LITERAL,
  104. SYMBOL
  105. ];
  106. LIST.contains = [
  107. hljs.COMMENT('comment', ''),
  108. NAME,
  109. BODY
  110. ];
  111. BODY.contains = DEFAULT_CONTAINS;
  112. COLLECTION.contains = DEFAULT_CONTAINS;
  113. return {
  114. name: 'Hy',
  115. aliases: [ 'hylang' ],
  116. illegal: /\S/,
  117. contains: [
  118. hljs.SHEBANG(),
  119. LIST,
  120. STRING,
  121. HINT,
  122. HINT_COL,
  123. COMMENT,
  124. KEY,
  125. COLLECTION,
  126. NUMBER,
  127. LITERAL
  128. ]
  129. };
  130. }
  131. export { hy as default };