l0bsterssg

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

ebnf.js (1083B)


      1 /*
      2 Language: Extended Backus-Naur Form
      3 Author: Alex McKibben <alex@nullscope.net>
      4 Website: https://en.wikipedia.org/wiki/Extended_Backus–Naur_form
      5 */
      6 
      7 function ebnf(hljs) {
      8     var commentMode = hljs.COMMENT(/\(\*/, /\*\)/);
      9 
     10     var nonTerminalMode = {
     11         className: "attribute",
     12         begin: /^[ ]*[a-zA-Z][a-zA-Z-_]*([\s-_]+[a-zA-Z][a-zA-Z]*)*/
     13     };
     14 
     15     var specialSequenceMode = {
     16         className: "meta",
     17         begin: /\?.*\?/
     18     };
     19 
     20     var ruleBodyMode = {
     21         begin: /=/, end: /[.;]/,
     22         contains: [
     23             commentMode,
     24             specialSequenceMode,
     25             {
     26               // terminals
     27               className: 'string',
     28               variants: [
     29                 hljs.APOS_STRING_MODE,
     30                 hljs.QUOTE_STRING_MODE,
     31                 {begin: '`', end: '`'},
     32               ]
     33             },
     34         ]
     35     };
     36 
     37     return {
     38         name: 'Extended Backus-Naur Form',
     39         illegal: /\S/,
     40         contains: [
     41             commentMode,
     42             nonTerminalMode,
     43             ruleBodyMode
     44         ]
     45     };
     46 }
     47 
     48 module.exports = ebnf;