l0bsterssg

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

zephir.js (3410B)


      1 /*
      2  Language: Zephir
      3  Description: Zephir, an open source, high-level language designed to ease the creation and maintainability of extensions for PHP with a focus on type and memory safety.
      4  Author: Oleg Efimov <efimovov@gmail.com>
      5  Website: https://zephir-lang.com/en
      6  */
      7 
      8 function zephir(hljs) {
      9   var STRING = {
     10     className: 'string',
     11     contains: [hljs.BACKSLASH_ESCAPE],
     12     variants: [
     13       hljs.inherit(hljs.APOS_STRING_MODE, {illegal: null}),
     14       hljs.inherit(hljs.QUOTE_STRING_MODE, {illegal: null})
     15     ]
     16   };
     17   var TITLE_MODE = hljs.UNDERSCORE_TITLE_MODE;
     18   var NUMBER = {variants: [hljs.BINARY_NUMBER_MODE, hljs.C_NUMBER_MODE]};
     19   var KEYWORDS =
     20     // classes and objects
     21     'namespace class interface use extends ' +
     22     'function return ' +
     23     'abstract final public protected private static deprecated ' +
     24     // error handling
     25     'throw try catch Exception ' +
     26     // keyword-ish things their website does NOT seem to highlight (in their own snippets)
     27     // 'typeof fetch in ' +
     28     // operators/helpers
     29     'echo empty isset instanceof unset ' +
     30     // assignment/variables
     31     'let var new const self ' +
     32     // control
     33     'require ' +
     34     'if else elseif switch case default ' +
     35     'do while loop for continue break ' +
     36     'likely unlikely ' +
     37     // magic constants
     38     // https://github.com/phalcon/zephir/blob/master/Library/Expression/Constants.php
     39     '__LINE__ __FILE__ __DIR__ __FUNCTION__ __CLASS__ __TRAIT__ __METHOD__ __NAMESPACE__ ' +
     40     // types - https://docs.zephir-lang.com/0.12/en/types
     41     'array boolean float double integer object resource string ' +
     42     'char long unsigned bool int uint ulong uchar ' +
     43     // built-ins
     44     'true false null undefined';
     45 
     46   return {
     47     name: 'Zephir',
     48     aliases: ['zep'],
     49     keywords: KEYWORDS,
     50     contains: [
     51       hljs.C_LINE_COMMENT_MODE,
     52       hljs.COMMENT(
     53         '/\\*',
     54         '\\*/',
     55         {
     56           contains: [
     57             {
     58               className: 'doctag',
     59               begin: '@[A-Za-z]+'
     60             }
     61           ]
     62         }
     63       ),
     64       {
     65         className: 'string',
     66         begin: '<<<[\'"]?\\w+[\'"]?$', end: '^\\w+;',
     67         contains: [hljs.BACKSLASH_ESCAPE]
     68       },
     69       {
     70         // swallow composed identifiers to avoid parsing them as keywords
     71         begin: /(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/
     72       },
     73       {
     74         className: 'function',
     75         beginKeywords: 'function fn', end: /[;{]/, excludeEnd: true,
     76         illegal: '\\$|\\[|%',
     77         contains: [
     78           TITLE_MODE,
     79           {
     80             className: 'params',
     81             begin: '\\(', end: '\\)',
     82             keywords: KEYWORDS,
     83             contains: [
     84               'self',
     85               hljs.C_BLOCK_COMMENT_MODE,
     86               STRING,
     87               NUMBER
     88             ]
     89           }
     90         ]
     91       },
     92       {
     93         className: 'class',
     94         beginKeywords: 'class interface', end: '{', excludeEnd: true,
     95         illegal: /[:\(\$"]/,
     96         contains: [
     97           {beginKeywords: 'extends implements'},
     98           TITLE_MODE
     99         ]
    100       },
    101       {
    102         beginKeywords: 'namespace', end: ';',
    103         illegal: /[\.']/,
    104         contains: [TITLE_MODE]
    105       },
    106       {
    107         beginKeywords: 'use', end: ';',
    108         contains: [TITLE_MODE]
    109       },
    110       {
    111         begin: '=>' // No markup, just a relevance booster
    112       },
    113       STRING,
    114       NUMBER
    115     ]
    116   };
    117 }
    118 
    119 module.exports = zephir;