l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

hy.js (4233B)


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