1 | <?php |
||
28 | class Shell extends GreedyLanguage |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * Tokenization rules setup |
||
33 | */ |
||
34 | 1 | public function setupRules() |
|
35 | { |
||
36 | 1 | $this->rules->addMany([ |
|
37 | 1 | 'call' => new Rule(new RegexMatcher( |
|
38 | '/(?>(?<![^\\\]\\\)(?<=\n|\(|\)|\||;|`|^|do|if|then|else|fi|esac|done\$\(|^\$\s)\s*\b(\w+))(?!\s*=)/i' |
||
39 | 1 | ), ['priority' => 1, 'context' => ['*none', '*expression']]), |
|
40 | |||
41 | 1 | 'comment' => new Rule(new CommentMatcher(['#'])), |
|
42 | 1 | 'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"']), |
|
43 | |||
44 | 1 | 'keyword' => new Rule(new WordMatcher([ |
|
45 | 1 | 'if', 'then', 'else', 'elif', 'fi', 'case', 'esac', 'for', 'select', 'while', 'until', 'do', 'done', |
|
46 | 1 | 'in', 'function', 'time', 'coproc' |
|
47 | 1 | ]), ['priority' => 3]), |
|
48 | |||
49 | 'variable' => [ |
||
50 | 1 | 'assign' => new Rule(new RegexMatcher('/(\w+)[+-]?=/')), |
|
51 | 1 | new Rule(new RegexMatcher('/(\$\w+)/i'), ['context' => ['*none', '*string.double']]), |
|
52 | 1 | 'special' => new Rule(new RegexMatcher('/(\$[#@_])/i'), ['context' => ['*none', '*string.double']]), |
|
53 | 1 | 'argument' => new Rule(new RegexMatcher('/(\$\d+)/i'), ['context' => ['*none', '*string.double']]), |
|
54 | 1 | new Rule(new RegexMatcher('/\$\{(\w+)(.*?)\}/i', [ 1 => Token::NAME, 2 => 'string' ]), ['context' => ['*none', '*string.double']]) |
|
55 | 1 | ], |
|
56 | |||
57 | 1 | 'number' => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')), |
|
58 | 1 | 'delimiter' => new Rule(new RegexMatcher('/^(\$)/m')), |
|
59 | |||
60 | 1 | 'symbol.parameter' => new Rule(new RegexMatcher('/[\s|](-{1,2}[\w-]+=?)\b/i'), [ |
|
61 | 1 | 'priority' => 0, |
|
62 | 1 | 'context' => ['!string', '!comment', '!call'] |
|
63 | 1 | ]), |
|
64 | |||
65 | 'expression' => [ |
||
66 | 1 | new Rule(new RegexMatcher('/(?=(\$\(((?>[^$()]+|(?1))+)\)))/x'), [ |
|
67 | 1 | 'context' => Validator::everywhere(), |
|
68 | 1 | 'factory' => new TokenFactory(LanguageToken::class), |
|
69 | 'inject' => $this |
||
70 | 1 | ]), |
|
71 | 1 | ], |
|
72 | |||
73 | 1 | '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'), [ |
|
74 | 1 | 'context' => ['*'] |
|
75 | 1 | ]), |
|
76 | 1 | ]); |
|
77 | 1 | } |
|
78 | |||
79 | /** |
||
80 | * Unique language identifier, for example 'php' |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 1 | public function getIdentifier() |
|
85 | { |
||
86 | 1 | return 'shell'; |
|
87 | } |
||
88 | |||
89 | public static function getMetadata() |
||
97 | } |
||
98 |