l0bsterssg

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

abnf.js (1675B)


      1 /*
      2 Language: Augmented Backus-Naur Form
      3 Author: Alex McKibben <alex@nullscope.net>
      4 Website: https://tools.ietf.org/html/rfc5234
      5 */
      6 
      7 /** @type LanguageFn */
      8 function abnf(hljs) {
      9     var regexes = {
     10         ruleDeclaration: "^[a-zA-Z][a-zA-Z0-9-]*",
     11         unexpectedChars: "[!@#$^&',?+~`|:]"
     12     };
     13 
     14     var keywords = [
     15         "ALPHA",
     16         "BIT",
     17         "CHAR",
     18         "CR",
     19         "CRLF",
     20         "CTL",
     21         "DIGIT",
     22         "DQUOTE",
     23         "HEXDIG",
     24         "HTAB",
     25         "LF",
     26         "LWSP",
     27         "OCTET",
     28         "SP",
     29         "VCHAR",
     30         "WSP"
     31     ];
     32 
     33     var commentMode = hljs.COMMENT(";", "$");
     34 
     35     var terminalBinaryMode = {
     36         className: "symbol",
     37         begin: /%b[0-1]+(-[0-1]+|(\.[0-1]+)+){0,1}/
     38     };
     39 
     40     var terminalDecimalMode = {
     41         className: "symbol",
     42         begin: /%d[0-9]+(-[0-9]+|(\.[0-9]+)+){0,1}/
     43     };
     44 
     45     var terminalHexadecimalMode = {
     46         className: "symbol",
     47         begin: /%x[0-9A-F]+(-[0-9A-F]+|(\.[0-9A-F]+)+){0,1}/,
     48     };
     49 
     50     var caseSensitivityIndicatorMode = {
     51         className: "symbol",
     52         begin: /%[si]/
     53     };
     54 
     55     var ruleDeclarationMode = {
     56         className: "attribute",
     57         begin: regexes.ruleDeclaration + '(?=\\s*=)',
     58     };
     59 
     60     return {
     61       name: 'Augmented Backus-Naur Form',
     62       illegal: regexes.unexpectedChars,
     63       keywords: keywords.join(" "),
     64       contains: [
     65           ruleDeclarationMode,
     66           commentMode,
     67           terminalBinaryMode,
     68           terminalDecimalMode,
     69           terminalHexadecimalMode,
     70           caseSensitivityIndicatorMode,
     71           hljs.QUOTE_STRING_MODE,
     72           hljs.NUMBER_MODE
     73       ]
     74     };
     75 }
     76 
     77 module.exports = abnf;