l0bsterssg

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

lisp.js (2383B)


      1 /*
      2 Language: Lisp
      3 Description: Generic lisp syntax
      4 Author: Vasily Polovnyov <vast@whiteants.net>
      5 Category: lisp
      6 */
      7 
      8 function lisp(hljs) {
      9   var LISP_IDENT_RE = '[a-zA-Z_\\-\\+\\*\\/\\<\\=\\>\\&\\#][a-zA-Z0-9_\\-\\+\\*\\/\\<\\=\\>\\&\\#!]*';
     10   var MEC_RE = '\\|[^]*?\\|';
     11   var LISP_SIMPLE_NUMBER_RE = '(\\-|\\+)?\\d+(\\.\\d+|\\/\\d+)?((d|e|f|l|s|D|E|F|L|S)(\\+|\\-)?\\d+)?';
     12   var LITERAL = {
     13     className: 'literal',
     14     begin: '\\b(t{1}|nil)\\b'
     15   };
     16   var NUMBER = {
     17     className: 'number',
     18     variants: [
     19       {begin: LISP_SIMPLE_NUMBER_RE, relevance: 0},
     20       {begin: '#(b|B)[0-1]+(/[0-1]+)?'},
     21       {begin: '#(o|O)[0-7]+(/[0-7]+)?'},
     22       {begin: '#(x|X)[0-9a-fA-F]+(/[0-9a-fA-F]+)?'},
     23       {begin: '#(c|C)\\(' + LISP_SIMPLE_NUMBER_RE + ' +' + LISP_SIMPLE_NUMBER_RE, end: '\\)'}
     24     ]
     25   };
     26   var STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null});
     27   var COMMENT = hljs.COMMENT(
     28     ';', '$',
     29     {
     30       relevance: 0
     31     }
     32   );
     33   var VARIABLE = {
     34     begin: '\\*', end: '\\*'
     35   };
     36   var KEYWORD = {
     37     className: 'symbol',
     38     begin: '[:&]' + LISP_IDENT_RE
     39   };
     40   var IDENT = {
     41     begin: LISP_IDENT_RE,
     42     relevance: 0
     43   };
     44   var MEC = {
     45     begin: MEC_RE
     46   };
     47   var QUOTED_LIST = {
     48     begin: '\\(', end: '\\)',
     49     contains: ['self', LITERAL, STRING, NUMBER, IDENT]
     50   };
     51   var QUOTED = {
     52     contains: [NUMBER, STRING, VARIABLE, KEYWORD, QUOTED_LIST, IDENT],
     53     variants: [
     54       {
     55         begin: '[\'`]\\(', end: '\\)'
     56       },
     57       {
     58         begin: '\\(quote ', end: '\\)',
     59         keywords: {name: 'quote'}
     60       },
     61       {
     62         begin: '\'' + MEC_RE
     63       }
     64     ]
     65   };
     66   var QUOTED_ATOM = {
     67     variants: [
     68       {begin: '\'' + LISP_IDENT_RE},
     69       {begin: '#\'' + LISP_IDENT_RE + '(::' + LISP_IDENT_RE + ')*'}
     70     ]
     71   };
     72   var LIST = {
     73     begin: '\\(\\s*', end: '\\)'
     74   };
     75   var BODY = {
     76     endsWithParent: true,
     77     relevance: 0
     78   };
     79   LIST.contains = [
     80     {
     81       className: 'name',
     82       variants: [
     83         {begin: LISP_IDENT_RE},
     84         {begin: MEC_RE}
     85       ]
     86     },
     87     BODY
     88   ];
     89   BODY.contains = [QUOTED, QUOTED_ATOM, LIST, LITERAL, NUMBER, STRING, COMMENT, VARIABLE, KEYWORD, MEC, IDENT];
     90 
     91   return {
     92     name: 'Lisp',
     93     illegal: /\S/,
     94     contains: [
     95       NUMBER,
     96       hljs.SHEBANG(),
     97       LITERAL,
     98       STRING,
     99       COMMENT,
    100       QUOTED,
    101       QUOTED_ATOM,
    102       LIST,
    103       IDENT
    104     ]
    105   };
    106 }
    107 
    108 module.exports = lisp;