Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
12 / 12
Syntax
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
9 / 9
13
100.00% covered (success)
100.00%
12 / 12
 new
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 default
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 numbers
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 strings
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 hasChar
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 characters
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 mlComments
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
3 / 3
 comments
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
1<?php declare(strict_types=1);
2
3namespace Aviat\Kilo;
4
5class Syntax {
6    // Tokens for PHP files
7    public array $tokens = [];
8
9    public static function new(
10        string $name,
11        array $keywords1 = [],
12        array $keywords2 = [],
13        array $operators = [],
14        string $slcs = '//',
15        string $mcs = '/*',
16        string $mce = '*/',
17        bool $highlightNumbers = true,
18        bool $highlightStrings = true,
19        bool $highlightComments = true,
20        bool $hasCharType = false,
21        bool $highlightCharacters = false,
22    ): self
23    {
24        return new self(
25            $name,
26            $keywords1,
27            $keywords2,
28            $operators,
29            $slcs,
30            $mcs,
31            $mce,
32            $highlightNumbers,
33            $hasCharType,
34            $highlightCharacters,
35            $highlightStrings,
36            $highlightComments,
37        );
38    }
39
40    public static function default(): self
41    {
42        return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false);
43    }
44
45    private function __construct(
46        /** The name of the programming language */
47        public string $filetype,
48        /** Primary set of language keywords */
49        public array $keywords1,
50        /** Secondary set of language keywords */
51        public array $keywords2,
52        /** Operators for the current language */
53        public array $operators,
54        /** Syntax to start a single line comment */
55        public string $singleLineCommentStart,
56        /** Syntax to start a multi-line comment */
57        public string $multiLineCommentStart,
58        /** Syntax to end a multi-line commment */
59        public string $multiLineCommentEnd,
60        /** Should we highlight numbers? */
61        private bool $highlightNumbers,
62        /** Does this language have a character type, separate from strings? */
63        private bool $hasCharType,
64        /** Should we highlight chars? */
65        private bool $highlightCharacters,
66        /** should we highlight Strings? */
67        private bool $highlightStrings,
68        /** should we highlight comments? */
69        private bool $highlightComments,
70    ) {}
71
72    public function numbers(): bool
73    {
74        return $this->highlightNumbers;
75    }
76
77    public function strings(): bool
78    {
79        return $this->highlightStrings;
80    }
81
82    public function hasChar(): bool
83    {
84        return $this->hasCharType;
85    }
86
87    public function characters(): bool
88    {
89        return $this->hasCharType && $this->highlightCharacters;
90    }
91
92    public function mlComments(): bool
93    {
94        return $this->highlightComments
95            && strlen($this->multiLineCommentStart) !== 0
96            && strlen($this->multiLineCommentStart) !== 0;
97    }
98
99    public function comments(): bool
100    {
101        return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0;
102    }
103}