Advertisement
Guest User

generic hyperlight syntax highlighter

a guest
May 30th, 2014
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.76 KB | None | 0 0
  1. <?php
  2.  
  3. // Highlights most languages reasonably: Java, C#, JavaScript, AS3, C, C++, Lua
  4. class GenericLanguage extends HyperLanguage {
  5.     public function __construct() {
  6.         $this->setInfo(array(
  7.             parent::NAME => 'Generic',
  8.             parent::VERSION => '0.1',
  9.             parent::AUTHOR => array(
  10.                 parent::NAME => 'Nathan Sweet', // based Konrad Rudolph's csharp.php!
  11.                 parent::WEBSITE => 'esotericsoftware.com',
  12.                 parent::EMAIL => 'misc@n4te.com'
  13.             )
  14.         ));
  15.  
  16.         $this->setExtensions(array('java'));
  17.  
  18.         $this->setCaseInsensitive(false);
  19.  
  20.         $this->addStates(array(
  21.             'init' => array(
  22.                 'string',
  23.                 'char',
  24.                 'number',
  25.                 'comment',
  26.                 'keyword' => array('', 'preprocessor'),
  27.                 'method',
  28.                 'ctor',
  29.                 'function',
  30.                 'operator',
  31.                 'type',
  32.                 'identifier',
  33.                 'whitespace',
  34.             ),
  35.         ));
  36.  
  37.         $this->addRules(array(
  38.             'whitespace' => Rule::ALL_WHITESPACE,
  39.             'operator' => '/[-+*\/%&|^!~=<>?{}()\[\].,:;]|&&|\|\||<<|>>|[-=!<>+*\/%&|^]=|<<=|>>=|->/',
  40.             'string' => Rule::C_DOUBLEQUOTESTRING,
  41.             'char' => Rule::C_SINGLEQUOTESTRING,
  42.             'number' => Rule::C_NUMBER,
  43.             'comment' => '#(//|--)(?:[^/].*?)?\n|/\*.*?\*/#s',
  44.             'keyword' => array(
  45.                 array(
  46.                     // C#
  47.                     'abstract', 'break', 'case', 'catch', 'checked', 'class',
  48.                     'const', 'continue', 'default', 'delegate', 'do', 'else',
  49.                     'enum', 'explicit', 'extern', 'finally', 'fixed',
  50.                     'for', 'foreach', 'goto', 'if', 'implicit', 'in', 'interface',
  51.                     'internal', 'lock', 'namespace', 'operator', 'out', 'override',
  52.                     'params', 'private', 'protected', 'public', 'readonly', 'ref',
  53.                     'return', 'sealed', 'static', 'struct', 'switch', 'throw',
  54.                     'try', 'unchecked', 'unsafe', 'using', 'var', 'virtual',
  55.                     'volatile', 'while',
  56.                     'bool', 'byte', 'char', 'decimal', 'double', 'float', 'int',
  57.                     'long', 'object', 'sbyte', 'short', 'string', 'uint', 'ulong',
  58.                     'ushort', 'void',
  59.                     'base', 'false', 'null', 'this', 'true',
  60.                     'as', 'is', 'new', 'sizeof', 'stackallock', 'typeof',
  61.                     // Java
  62.                     'extends', 'throws', 'implements',
  63.                     'final', 'native', 'synchronized',
  64.                     'transient', 'assert',
  65.                     'package', 'strictfp', 'super',
  66.                     'import', 'boolean', 'instanceof',
  67.                     // JavaScript
  68.                     'function',
  69.                     // Lua
  70.                     'local', 'not', 'then', 'end', 'nil', 'pairs', 'ipairs',
  71.                 ),
  72.                 'preprocessor' => '/#(?:if|else|elif|endif|define|undef|warning|error|line|region|endregion|include|import)[^\r\n]*/',
  73.             ),
  74.             'method' => '/(?<=\.)\s*([a-zA-Z][^\s\.\(:]+)(?=\s*\()/',
  75.             'ctor' => '/(?<=new)\s+([a-zA-Z][^\s\(:]+)(?=\s*\()/',
  76.             'function' => '/([a-zA-Z][^\s\.\(:]+)(?=\s*\()/',
  77.             'type' => '/@?(sp)?[A-Z][a-z0-9_]*/',
  78.             'identifier' => '/@?[a-z_][a-z0-9_]*/i',
  79.         ));
  80.  
  81.         $this->addMappings(array(
  82.             'whitespace' => '',
  83.         ));
  84.     }
  85. }
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement