Add Swift syntax highlighting to webkit.org
[WebKit-https.git] / Websites / webkit.org / wp-content / plugins / hyperlight / hyperlight / languages / swift.php
1 <?php
2 /**
3  * Based on Swift 3.0.1 grammars: 
4  * https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/zzSummaryOfTheGrammar.html#//apple_ref/doc/uid/TP40014097-CH38-ID458 
5  **/
6 class SwiftLanguage extends HyperLanguage {
7     public function __construct() {
8         $this->setInfo(array(
9             parent::NAME => 'Swift',
10             parent::VERSION => '1.0',
11             parent::AUTHOR => array(
12                 parent::NAME => 'Jonathan Davis',
13                 parent::WEBSITE => 'webkit.org',
14                 parent::EMAIL => 'jond@webkit.org'
15             )
16         ));
17
18         $this->setExtensions(array('swift'));
19
20         $this->addStates(array(
21             'init' => array(
22                 'string', 'char', 'number', 'comment',
23                 'keyword' => array('', 'declaration', 'type', 'modifier','control','literal', 'operator', 'preprocessor', 'macros', 'builtin'),
24                 'identifier',
25                 'operator'
26             )
27         ));
28
29         $this->addRules(array(
30             'whitespace' => RULE::ALL_WHITESPACE,
31             'operator' => '/[!|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|\/=|%=|\+=|\-=|&=|\^=|:]/',
32             'string' => Rule::C_DOUBLEQUOTESTRING,
33             'char' => Rule::C_SINGLEQUOTESTRING,
34             'number' => Rule::C_NUMBER,
35             'comment' => Rule::C_COMMENT,
36             'keyword' => array(
37                 array(
38                     'optional','self','super','import','deinit','import','init','subscript'
39                 ),
40                 'declaration' => array(
41                     'precedencegroup','class','struct','enum','extension','protocol','let','var','typealias','func','throws','rethrows'
42                 ),
43                 'type' => array(
44                     'boolean','byte','char','const','double','enum','float','int','interface','long','short','void','typealias','struct','const'
45                 ),
46                 'modifier' => array(
47                     'get','set','convenience','dynamic','final','infix','lazy','optional','override','postfix','prefix','required','static','unowned','weak','private','fileprivate','internal','public','open','mutating'
48                 ),
49                 'control' => array(
50                     'try','catch','repeat','break','case','continue','default','do','else','fallthrough','if','in','for','return','switch','where','while','guard','defer'
51                 ),
52                 'literal' => array(
53                     'false','this','true','nil','none'
54                 ),
55                 'operator' => array(
56                     'delete','in','instanceof','new','of','typeof','void','with','as','is'
57                 ),
58                 'preprocessor' => '/#(?:if|else|endif|elseif|define|undef|warning|error|line|region|endregion)/',
59                 'macros' => '/@(?:IBAction|IBOutlet|IBDesignable|IBInspectable|warn_unused_result|discardableResult|objc)/',
60                 'builtin' => '/\b((UI|NS|CF|CG)[A-Z][a-zA-Z0-9]+|Character|U?Int|U?Int(8|16|32|64)|Float|Double|Float(32|64)|Bool|String|Date|Data|URL|Any|AnyObject|Error|Equatable|Hashable|Comparable|CustomDebugStringConvertible|CustomStringConvertible|OptionSet|ManagedBuffer|ManagedBufferPointer|BitwiseOperations|CountedSet|Counter|Directions|ExpressibleByArrayLiteral|ExpressibleByBooleanLiteral|ExpressibleByDictionaryLiteral|ExpressibleByExtendedGraphemeClusterLiteral|ExpressibleByFloatLitera|ExpressibleByIntegerLiteral|ExpressibleByNilLiteral|ExpressibleByStringInterpolation|ExpressibleByStringLiteral|ExpressibleByUnicodeScalarLiteral|OrderedSet|PaperSize|RawRepresentable|(UI|NS|CF|CG)[A-Z][a-zA-Z0-9]+|Stream|(In|Out)putStream|FileManager|Array|Unsafe[a-zA-Z]*Pointer|Bundle|Jex)\b/'
61             ),
62             'identifier' => Rule::C_IDENTIFIER,
63         ));
64
65         $this->addMappings(array(
66             'whitespace' => '',
67             'identifier' => '',
68         ));
69     }
70 }