l0bsterssg

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

erlang.js (3893B)


      1 /*
      2 Language: Erlang
      3 Description: Erlang is a general-purpose functional language, with strict evaluation, single assignment, and dynamic typing.
      4 Author: Nikolay Zakharov <nikolay.desh@gmail.com>, Dmitry Kovega <arhibot@gmail.com>
      5 Website: https://www.erlang.org
      6 Category: functional
      7 */
      8 
      9 function erlang(hljs) {
     10   var BASIC_ATOM_RE = '[a-z\'][a-zA-Z0-9_\']*';
     11   var FUNCTION_NAME_RE = '(' + BASIC_ATOM_RE + ':' + BASIC_ATOM_RE + '|' + BASIC_ATOM_RE + ')';
     12   var ERLANG_RESERVED = {
     13     keyword:
     14       'after and andalso|10 band begin bnot bor bsl bzr bxor case catch cond div end fun if ' +
     15       'let not of orelse|10 query receive rem try when xor',
     16     literal:
     17       'false true'
     18   };
     19 
     20   var COMMENT = hljs.COMMENT('%', '$');
     21   var NUMBER = {
     22     className: 'number',
     23     begin: '\\b(\\d+(_\\d+)*#[a-fA-F0-9]+(_[a-fA-F0-9]+)*|\\d+(_\\d+)*(\\.\\d+(_\\d+)*)?([eE][-+]?\\d+)?)',
     24     relevance: 0
     25   };
     26   var NAMED_FUN = {
     27     begin: 'fun\\s+' + BASIC_ATOM_RE + '/\\d+'
     28   };
     29   var FUNCTION_CALL = {
     30     begin: FUNCTION_NAME_RE + '\\(', end: '\\)',
     31     returnBegin: true,
     32     relevance: 0,
     33     contains: [
     34       {
     35         begin: FUNCTION_NAME_RE, relevance: 0
     36       },
     37       {
     38         begin: '\\(', end: '\\)', endsWithParent: true,
     39         returnEnd: true,
     40         relevance: 0
     41         // "contains" defined later
     42       }
     43     ]
     44   };
     45   var TUPLE = {
     46     begin: '{', end: '}',
     47     relevance: 0
     48     // "contains" defined later
     49   };
     50   var VAR1 = {
     51     begin: '\\b_([A-Z][A-Za-z0-9_]*)?',
     52     relevance: 0
     53   };
     54   var VAR2 = {
     55     begin: '[A-Z][a-zA-Z0-9_]*',
     56     relevance: 0
     57   };
     58   var RECORD_ACCESS = {
     59     begin: '#' + hljs.UNDERSCORE_IDENT_RE,
     60     relevance: 0,
     61     returnBegin: true,
     62     contains: [
     63       {
     64         begin: '#' + hljs.UNDERSCORE_IDENT_RE,
     65         relevance: 0
     66       },
     67       {
     68         begin: '{', end: '}',
     69         relevance: 0
     70         // "contains" defined later
     71       }
     72     ]
     73   };
     74 
     75   var BLOCK_STATEMENTS = {
     76     beginKeywords: 'fun receive if try case', end: 'end',
     77     keywords: ERLANG_RESERVED
     78   };
     79   BLOCK_STATEMENTS.contains = [
     80     COMMENT,
     81     NAMED_FUN,
     82     hljs.inherit(hljs.APOS_STRING_MODE, {className: ''}),
     83     BLOCK_STATEMENTS,
     84     FUNCTION_CALL,
     85     hljs.QUOTE_STRING_MODE,
     86     NUMBER,
     87     TUPLE,
     88     VAR1, VAR2,
     89     RECORD_ACCESS
     90   ];
     91 
     92   var BASIC_MODES = [
     93     COMMENT,
     94     NAMED_FUN,
     95     BLOCK_STATEMENTS,
     96     FUNCTION_CALL,
     97     hljs.QUOTE_STRING_MODE,
     98     NUMBER,
     99     TUPLE,
    100     VAR1, VAR2,
    101     RECORD_ACCESS
    102   ];
    103   FUNCTION_CALL.contains[1].contains = BASIC_MODES;
    104   TUPLE.contains = BASIC_MODES;
    105   RECORD_ACCESS.contains[1].contains = BASIC_MODES;
    106 
    107   var PARAMS = {
    108     className: 'params',
    109     begin: '\\(', end: '\\)',
    110     contains: BASIC_MODES
    111   };
    112   return {
    113     name: 'Erlang',
    114     aliases: ['erl'],
    115     keywords: ERLANG_RESERVED,
    116     illegal: '(</|\\*=|\\+=|-=|/\\*|\\*/|\\(\\*|\\*\\))',
    117     contains: [
    118       {
    119         className: 'function',
    120         begin: '^' + BASIC_ATOM_RE + '\\s*\\(', end: '->',
    121         returnBegin: true,
    122         illegal: '\\(|#|//|/\\*|\\\\|:|;',
    123         contains: [
    124           PARAMS,
    125           hljs.inherit(hljs.TITLE_MODE, {begin: BASIC_ATOM_RE})
    126         ],
    127         starts: {
    128           end: ';|\\.',
    129           keywords: ERLANG_RESERVED,
    130           contains: BASIC_MODES
    131         }
    132       },
    133       COMMENT,
    134       {
    135         begin: '^-', end: '\\.',
    136         relevance: 0,
    137         excludeEnd: true,
    138         returnBegin: true,
    139         keywords: {
    140           $pattern: '-' + hljs.IDENT_RE,
    141           keyword: '-module -record -undef -export -ifdef -ifndef -author -copyright -doc -vsn ' +
    142           '-import -include -include_lib -compile -define -else -endif -file -behaviour ' +
    143           '-behavior -spec'
    144         },
    145         contains: [PARAMS]
    146       },
    147       NUMBER,
    148       hljs.QUOTE_STRING_MODE,
    149       RECORD_ACCESS,
    150       VAR1, VAR2,
    151       TUPLE,
    152       {begin: /\.$/} // relevance booster
    153     ]
    154   };
    155 }
    156 
    157 module.exports = erlang;