/** * Tokenization rules */ public function setupRules() { $this->rules->addMany(['string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!operator.escape', '!comment', '!string', '!expression']]), 'string.heredoc' => new Rule(new RegexMatcher('/<<<\\s*(\\w+)(?P<string>.*?)\\R\\1;/sm', ['string' => Token::NAME, 0 => 'keyword.heredoc']), ['context' => ['!comment']]), 'string.nowdoc' => new Rule(new RegexMatcher('/<<<\\s*\'(\\w+)\'(?P<string>.*?)\\R\\1;/sm', ['string' => Token::NAME, 0 => 'keyword.nowdoc']), ['context' => ['!comment']]), 'variable' => new Rule(new RegexMatcher('/(?:[^\\\\]|^)(\\$[a-z_]\\w*)/i'), ['context' => ['*comment.docblock', '!string.nowdoc', '!string.single', '!comment']]), 'variable.property' => new Rule(new RegexMatcher('/(?=(?:\\w|\\)|\\])\\s*->([a-z_]\\w*))/i'), ['priority' => -2]), 'symbol.function' => new Rule(new RegexMatcher('/function\\s+([a-z_]\\w+)\\s*\\(/i')), 'symbol.class' => [new Rule(new RegexMatcher('/(?:class|new|use|extends)\\s+([\\w\\\\]+)/i')), new Rule(new RegexMatcher('/([\\w\\\\]+)::/i')), new Rule(new RegexMatcher('/@(?:var|property(?:-read|-write)?)(?:\\s+|\\s+\\$\\w+\\s+)([^$][\\w\\\\]+)/i'), ['context' => ['comment.docblock']])], 'expression.in-string' => new Rule(new RegexMatcher('/(?=(\\{\\$((?>[^${}]+|(?1))+)\\}))/x'), ['context' => ['string'], 'factory' => new TokenFactory(LanguageToken::class), 'inject' => $this]), 'symbol.class.interface' => [new Rule(new RegexMatcher('/interface\\s+([\\w\\\\]+)/i')), new Rule(new DelegateRegexMatcher('/implements\\s+((?:[\\w\\\\]+)(?:,\\s*([\\w\\\\]+))+)/i', function ($match, TokenFactoryInterface $factory) { foreach (preg_split('/,\\s*/', $match[1][0], 0, PREG_SPLIT_OFFSET_CAPTURE) as $interface) { (yield $factory->create(Token::NAME, ['pos' => $match[1][1] + $interface[1], 'length' => strlen($interface[0])])); } }))], 'symbol.namespace' => [new Rule(new RegexMatcher('/namespace\\s*(\\\\{0,2}(?:\\w+\\\\{1,2})+\\w+);/i'), ['context' => ['*symbol', '*none']])], 'operator.escape' => [new Rule(new RegexMatcher('/(\\\\(?:x[0-9a-fA-F]{1,2}|u\\{[0-9a-fA-F]{1,6}\\}|[0-7]{1,3}|[^\'\\\\]))/i'), ['context' => ['string.double', '!operator.escape']]), new Rule(new RegexMatcher('/(\\\\[\'\\\\])/i'), ['context' => ['string', '!operator.escape']])], 'comment' => new Rule(new CommentMatcher(['//', '#'], ['$.docblock' => ['/**', '*/'], ['/* ', '*/']])), 'symbol.annotation' => new Rule(new RegexMatcher('/[\\s]+(@[\\w-]+)/i'), ['context' => ['comment.docblock']]), 'call' => new Rule(new RegexMatcher('/([a-z_]\\w*)\\s*\\(/i'), ['priority' => -1]), 'constant' => new Rule(new WordMatcher(array_merge(['__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', '__TRAIT__'], array_keys(get_defined_constants(true)["Core"]))), ['priority' => -2]), 'constant.static' => new Rule(new RegexMatcher('/(?:[\\w\\\\]+::|const\\s+)(\\w+)/i'), ['priority' => -2]), 'keyword' => new Rule(new WordMatcher(['__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'parent', 'self', 'use', 'var', 'while', 'xor', 'yield']), ['context' => ['!string', '!variable', '!comment']]), 'keyword.cast' => new Rule(new RegexMatcher('/(\\((?:int|integer|bool|boolean|float|double|real|string|array|object|unset)\\))/')), 'delimiter' => new Rule(new RegexMatcher('/(<\\?php|<\\?=|\\?>)/')), 'number' => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\\d+))/')), 'operator.punctuation' => new Rule(new WordMatcher([',', ';'], ['separated' => false]), ['priority' => 0])]); }
/** * Tokenization rules setup */ public function setupRules() { $this->rules->addMany(['keyword' => new Rule(new WordMatcher(['auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', 'goto', 'if', 'register', 'return', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'volatile', 'while'])), 'meta.newline' => new CloseRule(new RegexMatcher('/()\\R/m'), ['factory' => new TokenFactory(TerminatorToken::class), 'context' => ['!operator.escape', '*string', '*call.preprocessor'], 'closes' => ['string.double', 'preprocessor']]), 'preprocessor' => new OpenRule(new RegexMatcher('/^(#)/m'), ['context' => Validator::everywhere()]), 'call' => ['preprocessor' => new Rule(new RegexMatcher('/^#\\s*(\\w+)\\b/m'), ['context' => ['preprocessor']]), new Rule(new RegexMatcher('/([a-z_]\\w*)\\s*\\(/i'), ['priority' => -1])], 'operator.escape' => new Rule(new RegexMatcher('/(\\\\(?:.|[0-7]{3}|x\\x{2}))/s'), ['context' => Validator::everywhere()]), 'keyword.format' => new Rule(new RegexMatcher('/(%[diuoxXfFeEgGaAcspn%][-+#0]?(?:[0-9]+|\\*)?(?:\\.(?:[0-9]+|\\*))?)/'), ['context' => ['string']]), 'string' => array_merge([new Rule(new RegexMatcher('/(<.*?>)/'), ['context' => ['preprocessor']])], CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!operator.escape', '!comment', '!string']])), 'symbol.type' => [new Rule(new RegexMatcher('/(\\w+)(?:\\s+|\\s*\\*\\s*)\\w+\\s*[=();,]/')), new Rule(new WordMatcher(['int', 'float', 'double', 'char', 'void', 'long', 'short', 'signed', 'unsigned']))], 'comment' => [new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 2])], 'variable.property' => new Rule(new RegexMatcher('/(?=(?:\\w|\\)|\\])\\s*(?:->|\\.)\\s*([a-z_]\\w*))/'), ['priority' => 0]), 'number' => new Rule(new RegexMatcher('/\\b(-?(?:0x[\\da-f]+|\\d*\\.?\\d+(?:e[+-]?\\d+)?)[ful]*)\\b/i')), 'operator' => ['punctuation' => new Rule(new RegexMatcher('/([;,])/'), ['priority' => 0]), new Rule(new RegexMatcher('/([*&])/'), ['priority' => 0]), new Rule(new RegexMatcher('/([!+\\-\\/*&|^<>=]{1,2}=?)/'), ['priority' => 0])]]); }
/** * Tokenization rules setup */ public function setupRules() { $function = '[a-z]\\w*[!?]?'; $this->rules->addMany(['comment' => [new Rule(new CommentMatcher(['#']), ['context' => ['!string.regex', '!string']]), 'doc' => [new OpenRule(new RegexMatcher('/^(=begin)/m')), new CloseRule(new RegexMatcher('/^(=end)/m'))]], 'keyword' => new Rule(new WordMatcher(['BEGIN', 'class', 'ensure', 'when', 'END', 'def', 'not', 'super', 'while', 'alias', 'defined', 'for', 'or', 'then', 'yield', 'and', 'do', 'if', 'redo', 'begin', 'else', 'in', 'rescue', 'undef', 'break', 'elsif', 'module', 'retry', 'unless', 'case', 'end', 'next', 'return', 'until'], ['case-sensitivity' => true])), 'string' => [CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!operator.escape', '!comment', '!string', '!expression']]), 'generalized' => []], 'operator.escape' => new Rule(new RegexMatcher('/(\\\\.)/'), ['context' => ['string']]), 'constant' => [new Rule(new RegexMatcher('/(?:[a-z_])?::([a-z_]\\w*)/i')), 'special' => new Rule(new WordMatcher(['self', 'nil', 'true', 'false', '__FILE__', '__LINE__']))], 'variable' => ['global' => new Rule(new RegexMatcher('/(?:[^\\\\]|^)(\\$\\w*)/i')), 'property' => new Rule(new RegexMatcher('/(?:[^\\\\]|^)(@{1,2}\\w*)/i'))], 'string.regex' => [new OpenRule(new RegexMatcher('#(?>[\\[=(?:+,!~]|^|return|=>|&&|\\|\\|)\\s*(/).*?/#sm'), ['context' => ['!comment']]), new Rule(new RegexMatcher('#(?=\\/.*?(/[mixounse]*))#sm'), ['priority' => 2, 'factory' => new TokenFactory(ContextualToken::class), 'context' => ['!operator.escape', 'string.regex']])], 'call' => [new Rule(new RegexMatcher("/({$function})\\s*\\(/i"), ['priority' => 2]), new Rule(new RegexMatcher("/(?<![^\\\\]\\\\)(?<=\\n|\\{|\\(|\\}|\\|\\||or|&&|and|=|;)\\s*(?:\\w+(?:::|\\.))?({$function})(?:[\\h\r]*\$|\\h+['\":\\w])/im"), ['priority' => 0])], 'symbol' => ['symbol' => new Rule(new RegexMatcher('/[^\\B:](:[a-z_]\\w*)/i')), 'class' => new Rule(new RegexMatcher('/class\\s+([a-z_]\\w*)/i')), 'function' => new Rule(new RegexMatcher('/def\\s+(?:\\[\\]\\s*|\\*\\s*|\\w+\\.){0,2}([a-z_]\\w*)/i'))], 'expression.in-string' => new Rule(new RegexMatcher('/(?=(\\#\\{((?>[^\\#{}]+|(?1))+)\\}))/x'), ['context' => ['string.double'], 'factory' => new TokenFactory(LanguageToken::class), 'inject' => $this]), 'number' => new Rule(new RegexMatcher('/((?:-|\\b)(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\\d+))/'))]); }
/** * Tokenization rules */ public function setupRules() { $identifier = '-?[_a-zA-Z]+[_a-zA-Z0-9-]*'; $at = ['charset', 'import', 'namespace', 'media', 'supports', 'document', 'page', 'font-face', 'keyframes', 'viewport', 'counter-style', 'font-feature-values', 'swash', 'ornaments', 'annotation', 'stylistic', 'styleset', 'character-variant']; $this->rules->addMany(['string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => $this->everywhere()]), 'meta.declaration' => [new OpenRule(new SubStringMatcher('{'), ['context' => ['!meta.declaration.media', '!comment'], 'factory' => new TokenFactory(MetaToken::class)]), new CloseRule(new SubStringMatcher('}'))], 'meta.declaration.media' => [new Rule(new RegexMatcher('/@media(.*?\\{)/'), ['context' => Validator::everywhere(), 'factory' => new TokenFactory(MetaToken::class)])], 'meta.declaration.rule' => [new OpenRule(new RegexMatcher('/@media.*(\\()/'), ['context' => ['meta.declaration.media'], 'factory' => new TokenFactory(MetaToken::class)]), new CloseRule(new SubStringMatcher(')'))], 'keyword.at-rule' => new Rule(new RegexMatcher('/(@(?:-[a-z]+-)?(?:' . implode('|', $at) . '))/'), ['priority' => 2]), 'symbol.selector.id' => new Rule(new RegexMatcher("/(#{$identifier})/i")), 'symbol.selector.tag' => new Rule(new RegexMatcher('/(?>[\\s}]|^)(?=(\\w+)[^;]*\\{)/ms')), 'symbol.selector.class' => new Rule(new RegexMatcher("/(\\.{$identifier})/i")), 'symbol.selector.class.pseudo' => new Rule(new RegexMatcher("/(:{1,2}{$identifier})/")), 'number' => new Rule(new RegexMatcher("/([-+]?[0-9]*\\.?[0-9]+([\\w%]+)?)/"), ['context' => ['meta.declaration', '!constant.color', '!comment', '!symbol', '!comment', '!string'], 'priority' => 0]), 'symbol.property' => new Rule(new RegexMatcher("/({$identifier}:)/"), ['context' => ['meta.declaration', '!symbol', '!comment'], 'priority' => 2]), 'call' => new Rule(new RegexMatcher("/({$identifier})\\s*\\((?:(?P<string>[a-z].*?)|.*?)\\)/", [1 => Token::NAME, 'string' => 'string.argument']), ['context' => ['meta.declaration', '!comment', '!string', '!keyword']]), 'constant.color' => [new Rule(new RegexMatcher("/(#[0-9a-f]{3,6})/i"), ['priority' => 2, 'context' => ['meta.declaration', '!comment']]), new Rule(new WordMatcher(['white', 'silver', 'gray', 'black', 'red', 'maroon', 'yellow', 'olive', 'lime', 'green', 'aqua', 'teal', 'blue', 'navy', 'fuchsia', 'purple']), ['context' => ['meta.declaration', '!comment', '!symbol', '!variable']])], 'operator' => new Rule(new WordMatcher(['>', '+', '*', '!important'], ['separated' => false]), ['context' => $this->everywhere()]), 'operator.punctuation' => new Rule(new SubStringMatcher(';'), ['context' => $this->everywhere()]), 'comment' => new Rule(new CommentMatcher([], [['/*', '*/']]), ['context' => $this->everywhere()])]); }
/** * Tokenization rules setup */ public function setupRules() { $this->rules->addMany(['call' => new Rule(new RegexMatcher('/(?>(?<![^\\\\]\\\\)(?<=\\n|\\(|\\||;|`|^|do|if|then|else|\\$\\(|^\\$\\s)\\s*(\\w+))(?!\\s*=)/im'), ['priority' => 1, 'context' => ['*none', '*expression']]), 'comment' => new Rule(new CommentMatcher(['#'])), 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"']), 'keyword' => new Rule(new WordMatcher(['if', 'then', 'else', 'elif', 'fi', 'case', 'esac', 'for', 'select', 'while', 'until', 'do', 'done', 'in', 'function', 'time', 'coproc']), ['priority' => 3]), 'variable' => ['assign' => new Rule(new RegexMatcher('/(\\w+)\\s*=/')), new Rule(new RegexMatcher('/(\\$\\w+)/i'), ['context' => ['*none', '*string.double']])], 'number' => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\\d+))/')), 'delimiter' => new Rule(new RegexMatcher('/^(\\$)/m')), 'symbol.parameter' => new Rule(new RegexMatcher('/\\s(-{1,2}\\w+=?)\\b/i'), ['priority' => 0, 'context' => ['!string', '!comment', '!call']]), 'expression' => [new Rule(new RegexMatcher('/(?=(\\$\\(((?>[^$()]+|(?1))+)\\)))/x'), ['context' => Validator::everywhere(), 'factory' => new TokenFactory(LanguageToken::class), 'inject' => $this])], 'operator.escape' => new Rule(new RegexMatcher('/(\\\\(?:x[0-9a-fA-F]{1,2}|u\\{[0-9a-fA-F]{1,6}\\}|[0-7]{1,3}|.))/i'), ['context' => ['string']])]); }
/** * Tokenization rules setup */ public function setupRules() { $this->rules->addMany(['comment' => new Rule(new CommentMatcher([], [['{#', '#}']]), ['priority' => 0]), 'delimiter' => new Rule(new RegexMatcher('/((\\{[{%]|[%}]\\}))/')), 'variable' => new Rule(new RegexMatcher('/\\{\\{\\s*([a-z]\\w*)/')), 'call' => new Rule(new RegexMatcher('/\\{\\{.*?\\|([a-z]\\w*)/')), 'call.template-tag' => new Rule(new RegexMatcher('/{%\\s*([a-z]\\w*)/')), 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!string', '!comment']])]); }
/** * Tokenization rules */ public function setupRules() { $this->rules->addMany(['keyword' => new Rule(new WordMatcher($this->_keywords, ['escape' => false])), 'symbol.type' => new Rule(new WordMatcher($this->_types, ['escape' => false])), 'constant' => new Rule(new WordMatcher(['FALSE', 'TRUE', 'NULL'])), 'comment' => new Rule(new CommentMatcher(['#', '--'], [['/*', '*/']])), 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"']), 'number' => new Rule(new RegexMatcher('/\\b(-?\\d+)\\b/i')), 'call' => new Rule(new RegexMatcher('/([a-z_]\\w*)\\s*\\(/i'), ['priority' => -1]), 'operator.escape' => new Rule(new RegexMatcher('/(\\[\\0\'|bnrtZ%_])/'), ['context' => ['string']])]); }
/** * Tokenization rules */ public function setupRules() { $this->rules->addMany(['string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!operator.escape', '!comment', '!string']]), 'variable.property' => new Rule(new RegexMatcher('/(?=(?:\\w|\\)|\\])\\s*\\.([a-z_]\\w*))/i'), ['priority' => -2]), 'symbol.function' => new Rule(new RegexMatcher('/function\\s+([a-z_]\\w+)\\s*\\(/i')), 'operator.escape' => new Rule(new RegexMatcher('/(\\\\(?:x[0-9a-fA-F]{1,2}|u\\{[0-9a-fA-F]{1,6}\\}|[0-7]{1,3}|.))/i'), ['context' => ['string']]), 'comment' => new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 3]), 'call' => new Rule(new RegexMatcher('/(' . self::IDENTIFIER . ')\\s*\\(/iu'), ['priority' => -1]), 'keyword' => new Rule(new WordMatcher(['do', 'if', 'in', 'for', 'let', 'new', 'try', 'var', 'case', 'else', 'enum', 'eval', 'void', 'with', 'break', 'catch', 'class', 'const', 'super', 'throw', 'while', 'yield', 'delete', 'export', 'import', 'public', 'return', 'static', 'switch', 'typeof', 'default', 'extends', 'finally', 'package', 'private', 'continue', 'debugger', 'function', 'arguments', 'interface', 'protected', 'implements', 'instanceof', 'get', 'set', 'from']), ['context' => ['!string', '!comment', '!symbol', '!call']]), 'constant.special' => new Rule(new WordMatcher(['null', 'true', 'false'])), 'variable.special' => new Rule(new SubStringMatcher('this')), 'number' => new Rule(new RegexMatcher('/\\b(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\\d+))\\b/')), 'operator.punctuation' => new Rule(new WordMatcher([',', ';'], ['separated' => false]), ['priority' => 0]), 'operator' => new Rule(new RegexMatcher('/(=>|\\+{1,2}|-{1,2}|={1,3}|\\|{1,2}|&{1,2})/'), ['priority' => 0]), 'string.regex' => [new OpenRule(new RegexMatcher('#(?>[\\[=(?:+,!]|^|return|=>|&&|\\|\\|)\\s*(/).*?/#m'), ['context' => ['!comment']]), new Rule(new RegexMatcher('#\\/.*(/[gimuy]{0,5})#m'), ['priority' => 1, 'factory' => new TokenFactory(ContextualToken::class), 'context' => ['!operator.escape', 'string.regex']])], 'variable' => new Rule(new RegexMatcher('/\\b(?<!\\.)(' . self::IDENTIFIER . ':?)/iu'), ['priority' => -1, 'enabled' => $this->variables])]); }
/** * Tokenization rules */ public function setupRules() { $this->rules->addMany(['string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!operator.escape', '!comment', '!string']]), 'variable' => [new Rule(new RegexMatcher('/(?<!`)(\\$(?P<namespace>\\w+:)?[a-z_]\\w*)/i'), ['context' => ['!string.single', '!comment', '!variable'], 'priority' => 0]), new Rule(new RegexMatcher('/[^`](\\$\\{(?P<namespace>\\w+:)?.*?\\})/i'), ['context' => ['!string.single', '!comment', '!variable'], 'priority' => 0])], 'variable.splat' => new Rule(new RegexMatcher('/[^`](\\@(?P<namespace>\\w+:)?[a-z_]\\w*)/i'), ['context' => ['!string.single', '!comment'], 'priority' => 0]), 'variable.special' => new Rule(new RegexMatcher('/(\\$(?:\\$|\\^|\\?|_|true|false|null))\\b/i'), ['priority' => 5, 'context' => ['!string.single', '!comment']]), 'variable.scope' => new Rule(null, ['context' => ['*variable']]), 'comment' => new Rule(new CommentMatcher(['#'], [['<#', '#>']])), 'keyword.doc-section' => new Rule(new RegexMatcher('/[\\s\\R](\\.\\w+)/i'), ['context' => ['comment']]), 'symbol.dotnet' => new Rule(new RegexMatcher('/(\\[[a-z][\\w\\.]*(?:\\[\\])?\\])/si')), 'symbol.annotation' => new Rule(new RegexMatcher('/\\[([\\w\\.]+)\\s*(?P<arguments>\\((?>[^()]+|(?&arguments))*\\))\\s*\\]/si', [1 => Token::NAME, 'arguments' => '$.arguments'])), 'keyword' => new Rule(new WordMatcher(['Begin', 'Break', 'Catch', 'Continue', 'Data', 'Do', 'DynamicParam', 'Else', 'Elseif', 'End', 'Exit', 'Filter', 'Finally', 'For', 'ForEach', 'From', 'Function', 'If', 'In', 'InlineScript', 'Hidden', 'Parallel', 'Param', 'Process', 'Return', 'Sequence', 'Switch', 'Throw', 'Trap', 'Try', 'Until', 'While', 'Workflow']), ['priority' => 3]), 'operator' => new Rule(new RegexMatcher('/(&|\\-eq|\\-ne|\\-gt|\\-ge|\\-lt|\\-le|\\-ieq|\\-ine|\\-igt|\\-ige|\\-ilt|\\-ile|\\-ceq|\\-cne|\\-cgt|\\-cge|\\-clt|\\-cle|\\-like|\\-notlike|\\-match|\\-notmatch|\\-ilike|\\-inotlike|\\-imatch|\\-inotmatch|\\-clike|\\-cnotlike|\\-cmatch|\\-cnotmatch|\\-contains|\\-notcontains|\\-icontains|\\-inotcontains|\\-ccontains|\\-cnotcontains|\\-isnot|\\-is|\\-as|\\-replace|\\-ireplace|\\-creplace|\\-and|\\-or|\\-band|\\-bor|\\-not|\\-bnot|\\-f|\\-casesensitive|\\-exact|\\-file|\\-regex|\\-wildcard)\\b/i'), ['context' => ['!string', '!comment']]), 'symbol.parameter' => new Rule(new RegexMatcher('/\\s(-\\w+:?)\\b/i'), ['priority' => 0, 'context' => ['!string', '!comment', '!call']]), 'operator.punctuation' => new Rule(new WordMatcher([',', ';', '.', '::', '%'], ['separated' => false]), ['priority' => 0, 'context' => ['!string', '!comment', '!call']]), 'number' => [new Rule(new RegexMatcher('/\\b(-?(?:0x[0-9a-f]+|\\d+)l?(?:kb|mb|gb|tb|pb)?)\\b/i'), ['priority' => 0, 'context' => ['!string', '!comment', '!variable', '!call']]), new Rule(new RegexMatcher('/\\b(-?(?>\\d+)?\\.\\d+(?>d|l)(?>e(?:\\+|-)?\\d+)?(?:kb|mb|gb|tb|pb)?)\\b/i'), ['priority' => 0, 'context' => ['!string', '!comment', '!variable', '!call']])], 'call' => new Rule(new RegexMatcher('/(?<![^`]`)(?<=\\n|\\{|\\(|\\}|\\||=|;|^|function|filter|^PS>)\\s*((?:\\w+\\\\)?\\w[\\w-\\.]+)/im'), ['priority' => 2]), 'delimiter.prompt' => new Rule(new RegexMatcher('/^(PS>)/im'), ['priority' => 4])]); }
/** * Tokenization rules */ public function setupRules() { $this->rules->addMany(['tag.open' => [new OpenRule(new RegexMatcher('/(<[\\w\\.-]+)[:\\/>:\\s]/')), new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']])], 'tag.close' => new Rule(new RegexMatcher('/(<\\/(?:[\\w\\.-]+:)?(?:[\\w\\.]+)>)/')), 'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', ['name' => Token::NAME, 'namespace' => '$.namespace']), ['context' => ['tag', '!string']]), 'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', ['name' => Token::NAME, 'namespace' => '$.namespace']), ['context' => ['tag', '!string']]), 'constant.entity' => new Rule(new RegexMatcher('/(&(?:\\#\\d+|[a-z])+;)/si')), 'comment' => new Rule(new CommentMatcher(null, [['<!--', '-->']])), 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['tag']])]); }
/** * Tokenization rules setup */ public function setupRules() { $identifier = '[\\p{L}\\p{Nl}$_][\\p{L}\\p{Nl}$\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}]*'; $this->rules->addMany(['comment' => new Rule(new CommentMatcher(['//'], [['/*', '*/']])), 'keyword' => new Rule(new WordMatcher(['break', 'default', 'func', 'interface', 'select', 'case', 'defer', 'go', 'map', 'struct', 'chan', 'else', 'goto', 'package', 'switch', 'const', 'fallthrough', 'if', 'range', 'type', 'continue', 'for', 'import', 'return', 'var'])), 'number' => ['integer' => new Rule(new RegexMatcher('/\\b([1-9]\\d*|0x\\x+|[0-7]+)\\b/si')), 'float' => new Rule(new RegexMatcher('/\\v((?:\\d+\\.\\d*(?P<exponent>e[+-]?\\d+)?|\\.\\d+(?&exponent)?|\\d+(?&exponent))i?)\\b/si'))], 'string' => ['rune' => new Rule(new RegexMatcher('/(\'(?:\\\\(?:[abfnrtv\\\'"]|[0-7]{3}|x\\x{2})|u\\x{4}|U\\x{8})\')/si')), CommonFeatures::strings(['single' => '`', 'double' => '"'])], 'constant.special' => new Rule(new WordMatcher(['true', 'false', 'iota'])), 'type' => new Rule(new RegexMatcher('/((?:\\*\\s*)?(?:u?int(?:8|16|32|64|ptr)?|float(?:32|64)|complex(?:64|128)|byte|rune|string|error))/')), 'symbol' => ['function' => new Rule(new RegexMatcher("/func\\s*({$identifier})/")), 'struct' => new Rule(new RegexMatcher("/type\\s*({$identifier})\\s*struct/")), 'interface' => new Rule(new RegexMatcher("/type\\s*({$identifier})\\s*interface/"))], 'call' => new Rule(new RegexMatcher("/({$identifier})\\s*\\(/i"), ['priority' => -1]), 'operator' => [new Rule(new RegexMatcher('~((?>&{2}|<-|[+-]{2}|\\|\\||[+&=!/:%*^-|]?=|<{1,2}=?|>{1,2}=?|&^=?))~si')), 'punctuation' => new Rule(new RegexMatcher('/([;,]|\\.\\.\\.)/'))]]); }
/** * Tokenization rules definition */ public function setupRules() { $identifier = '\\w+'; $number = '[+-]?(?=\\d|\\.\\d)\\d*(\\.\\d*)?([Ee]([+-]?\\d+))?'; $this->rules->addMany(['string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['!keyword', '!comment', '!string', '!language', '!number']]), 'comment' => new Rule(new CommentMatcher(['#'])), 'keyword' => new Rule(new WordMatcher(['case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach', 'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then', 'unless', 'until', 'while', 'use', 'print', 'new', 'BEGIN', 'sub', 'CHECK', 'INIT', 'END', 'return', 'exit'])), 'operator.escape' => new Rule(new RegexMatcher('/(\\\\.)/'), ['context' => ['string']]), 'string.nowdoc' => new Rule(new RegexMatcher('/<<\\s*\'(\\w+)\';(?P<string>.*?)\\R\\1/sm', ['string' => Token::NAME, 0 => 'keyword.nowdoc']), ['context' => ['!comment']]), 'language.shell' => new Rule(new SubStringMatcher('`'), ['context' => ['!operator.escape', '!comment', '!string', '!keyword.nowdoc'], 'factory' => new TokenFactory(ContextualToken::class)]), 'variable.scalar' => new Rule(new RegexMatcher("/(\\\${$identifier})/")), 'variable.array' => new Rule(new RegexMatcher("/(\\@{$identifier})/")), 'variable.hash' => new Rule(new RegexMatcher("/(\\%{$identifier})/")), 'variable.property' => new Rule(new RegexMatcher("/\\\${$identifier}{({$identifier})}/")), 'variable.special' => new Rule(new RegexMatcher('/([$@%][^\\s\\w]+[\\w]*)/')), 'operator' => [new Rule(new RegexMatcher('/(-[rwxoRWXOezsfdlpSbctugkTBMAC])/')), new Rule(new WordMatcher(['not', 'and', 'or', 'xor', 'goto', 'last', 'next', 'redo', 'dump', 'eq', 'ne', 'cmp', 'not', 'and', 'or', 'xor'], ['atomic' => true]))], 'call' => new Rule(new RegexMatcher('/([a-z]\\w+)(?:\\s*\\(|\\s+[$%@"\'`{])/i')), 'number' => [new Rule(new RegexMatcher("/(\\b|\"|'){$number}\\1/", [0 => Token::NAME]), ['priority' => 5])], 'string.regex' => [new OpenRule(new RegexMatcher('#~\\s*[ms]?(/).*?/#m'), ['context' => Validator::everywhere()]), new OpenRule(new RegexMatcher('#~\\s*(s/).*?/#m')), new Rule(new RegexMatcher('#(?=\\/.*?(/[gimuy]{0,5}))#m'), ['priority' => 1, 'factory' => new TokenFactory(ContextualToken::class), 'context' => ['!operator.escape', 'string.regex']])], 'symbol.iterator' => [new Rule(new RegexMatcher('#(<\\w+>)#s'))]]); }