|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Highlighter |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2016, Some right reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Kacper "Kadet" Donat <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* Contact with author: |
|
10
|
|
|
* Xmpp: [email protected] |
|
11
|
|
|
* E-mail: [email protected] |
|
12
|
|
|
* |
|
13
|
|
|
* From Kadet with love. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Kadet\Highlighter\Language\Sql; |
|
17
|
|
|
|
|
18
|
|
|
use Kadet\Highlighter\Language\Sql; |
|
19
|
|
|
use Kadet\Highlighter\Matcher\SubStringMatcher; |
|
20
|
|
|
use Kadet\Highlighter\Parser\Token\ContextualToken; |
|
21
|
|
|
use Kadet\Highlighter\Parser\Rule; |
|
22
|
|
|
use Kadet\Highlighter\Parser\TokenFactory; |
|
23
|
|
|
|
|
24
|
|
|
class MySql extends Sql |
|
25
|
|
|
{ |
|
26
|
|
|
protected $_types = [ |
|
27
|
|
|
'(?:tiny|small|medium|big)?int', 'integer', 'date', 'datetime', 'time', 'bool', 'unsigned', 'int[12348]?', |
|
28
|
|
|
'(?:tiny|medium|long)?text', '(?:tiny|medium|long)?blob', 'float[48]?', 'double(?:\s+precision)?', 'real', 'numeric', |
|
29
|
|
|
'dec', 'decimal', 'timestamp', 'year', '(?:var)?char', 'varbinary', 'varcharacter', 'enum', 'set', 'bit', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
protected $_keywords = [ |
|
33
|
|
|
'add', 'all', 'alter', 'analyze', 'and', 'as', 'asc', 'asensitive', 'before', 'between', 'bigint', 'binary', |
|
34
|
|
|
'blob', 'both', 'by', 'call', 'cascade', 'case', 'change', 'check', 'collate', 'column', 'comment', 'charset', |
|
35
|
|
|
'condition', 'constraint', 'continue', 'convert', 'create', 'cross', 'current(?>_date|_time|_timestamp|_user)', |
|
36
|
|
|
'cursor', 'databases?', 'day(?>_hour|_(?:micro)?second|_minute)', 'dec', 'declare', 'default', 'delayed', |
|
37
|
|
|
'delete', 'desc', 'describe', 'deterministic', 'distinct', 'distinctrow', 'div', 'drop', 'dual', 'each', 'else', |
|
38
|
|
|
'elseif', 'enclosed', 'escaped', 'exists', 'exit', 'explain', 'fetch', 'flush', 'for', 'force', 'foreign', |
|
39
|
|
|
'from', 'fulltext', 'grant', 'group', 'having', 'high_priority', 'hour(?>_microsecond|_minute|_second)', 'if', |
|
40
|
|
|
'ignore', 'in', 'index', 'infile', 'inner', 'inout', 'insensitive', 'insert', 'interval', 'into', 'is', |
|
41
|
|
|
'iterate', 'join', 'key', 'keys', 'kill', 'leading', 'leave', 'left', 'like', 'limit', 'lines', 'load', |
|
42
|
|
|
'localtime(?:stamp)?', 'lock', 'long', 'loop', 'low_priority', 'match', 'minute_(micro)?second', 'mod', |
|
43
|
|
|
'modifies', 'natural', 'no_write_to_binlog', 'not', 'on', 'optimize', 'option', 'optionally', 'or', 'order', |
|
44
|
|
|
'out', 'outer', 'outfile', 'precision', 'primary', 'procedure', 'purge', 'raid0', 'reads?', 'references', |
|
45
|
|
|
'regexp', 'release', 'rename', 'repeat', 'replace', 'require', 'restrict', 'return', 'revoke', 'right', 'rlike', |
|
46
|
|
|
'schemas?', 'second_microsecond', 'select', 'sensitive', 'separator', 'set', 'show', 'soname', 'spatial', |
|
47
|
|
|
'specific', 'sql(?>_big_result|_calc_found_rows|_small_result|exception|state|warning)?', 'ssl', 'starting', |
|
48
|
|
|
'straight_join', 'table', 'terminated', 'then', 'to', 'trailing', 'trigger', 'undo', 'union', 'unique', |
|
49
|
|
|
'unlock', 'unsigned', 'update', 'usage', 'use', 'using', 'utc_(?>date|timestamp|time)', 'values', 'arying', |
|
50
|
|
|
'when', 'where', 'while', 'with', 'write', 'x509', 'xor', 'year_month', 'zerofill', 'auto_increment', 'engine' |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Tokenization rules |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setupRules() |
|
57
|
|
|
{ |
|
58
|
|
|
parent::setupRules(); |
|
59
|
|
|
$this->rules->add('symbol', new Rule(new SubStringMatcher('`'), [ |
|
60
|
|
|
'factory' => new TokenFactory(ContextualToken::class) |
|
61
|
|
|
])); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** {@inheritdoc} */ |
|
65
|
|
|
public function getIdentifier() |
|
66
|
|
|
{ |
|
67
|
|
|
return 'mysql'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public static function getMetadata() |
|
71
|
|
|
{ |
|
72
|
|
|
return [ |
|
73
|
|
|
'name' => ['mysql'], |
|
74
|
|
|
'mime' => ['text/x-mysql'], |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|