Completed
Push — master ( f8b2ff...51cde5 )
by Kacper
03:30
created

LatexLanguage::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
use Kadet\Highlighter\Parser\Token;
24
25
class LatexLanguage extends Language
26
{
27
    static $mathEnvs = ['align', 'equation', 'math'];
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $mathEnvs.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
28
29
    /**
30
     * Tokenization rules definition
31
     *
32
     * @return array
33
     */
34
    public function getRules()
35
    {
36
        return [
37
            'call.symbol' => new Rule(new RegexMatcher('/(\\\\\w+)/'), ['context' => ['!!'], 'priority' => -1]),
38
            /*'string' => [
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
                new OpenRule(new SubStringMatcher('{'), ['context' => ['!!'], 'inside' => true, 'priority' => 0]),
40
                new CloseRule(new SubStringMatcher('}'), ['inside' => true, 'priority' => -2])
41
            ],*/
42
43
            'string.math' => [
44
                new Rule(new RegexMatcher('/((\${1,2}).*?\2)/s')),
45
                new Rule(new RegexMatcher('/\\\begin{((?:'.implode('|', self::$mathEnvs).')\*?)}(.*?)\\\end{\1}/s', [2 => Token::NAME]))
46
            ],
47
48
            'symbol.argument' => new Rule(new RegexMatcher('/\[(.*?)\]/')),
49
            'symbol.environment' => new Rule(new RegexMatcher('/\\\(?:begin|end){(.*?)}/')),
50
51
            'symbol.label' => new Rule(new RegexMatcher('/\\\(?:label|ref){(.*?)}/')),
52
53
            'operator' => new Rule(new WordMatcher(['*', '&', '\\\\'], ['separated' => false]), ['context' => ['!!']]),
54
55
            'comment' => new Rule(new CommentMatcher(['%'], [])),
56
        ];
57
    }
58
59
    /**
60
     * Unique language identifier, for example 'php'
61
     *
62
     * @return string
63
     */
64
    public function getIdentifier()
65
    {
66
        return 'latex';
67
    }
68
}