Completed
Push — master ( 76a0ca...704293 )
by Kacper
03:04
created

Shell   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setupRules() 0 29 1
A getIdentifier() 0 4 1
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;
17
18
19
use Kadet\Highlighter\Matcher\CommentMatcher;
20
use Kadet\Highlighter\Matcher\RegexMatcher;
21
use Kadet\Highlighter\Matcher\WordMatcher;
22
use Kadet\Highlighter\Parser\Rule;
23
24
class Shell extends GreedyLanguage
25
{
26
27
    /**
28
     * Tokenization rules setup
29
     */
30
    public function setupRules()
31
    {
32
        $this->rules->addMany([
33
            'call' => new Rule(new RegexMatcher(
34
                '/(?>(?<![^\\\]\\\)(?<=\n|\(|\||;|^|do|if|then|else|^\$\s)\s*(\w+))(?!\s*=)/im'
35
            ), ['priority' => 1, 'context' => ['*none', '*expression']]),
36
37
            'comment' => new Rule(new CommentMatcher(['#'])),
38
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"']),
39
40
            'keyword' => new Rule(new WordMatcher([
41
                'if', 'then', 'else', 'elif', 'fi', 'case', 'esac', 'for', 'select', 'while', 'until', 'do', 'done',
42
                'in', 'function', 'time', 'coproc'
43
            ]), ['priority' => 3]),
44
45
            'variable'  => [
46
                'assign' => new Rule(new RegexMatcher('/(\w+)\s*=/')),
47
                new Rule(new RegexMatcher('/(\$\w+)/i'), ['context' => ['*none', '*string.double']])
48
            ],
49
50
            'number'    => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')),
51
            'delimiter'    => new Rule(new RegexMatcher('/^(\$)/m')),
52
53
            'symbol.parameter' => new Rule(new RegexMatcher('/\s(-{1,2}\w+=?)\b/i'), [
54
                'priority' => 0,
55
                'context'  => ['!string', '!comment', '!call']
56
            ]),
57
        ]);
58
    }
59
60
    /**
61
     * Unique language identifier, for example 'php'
62
     *
63
     * @return string
64
     */
65
    public function getIdentifier()
66
    {
67
        return 'shell';
68
    }
69
}
70