Completed
Push — master ( c80620...0cd8d9 )
by Martijn
03:25
created

Rfc2234   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 65 1
1
<?php /** @noinspection PhpUndefinedFieldInspection */
2
3
/**
4
 * RFC 2234 - Augmented BNF for Syntax Specifications: ABNF
5
 *
6
 * Obsoleted by RFC 4234
7
 *
8
 * @see https://tools.ietf.org/html/rfc2234
9
 * @package Vanderlee\Comprehend\Library
10
 */
11
12
namespace Vanderlee\Comprehend\Library;
13
14
use Vanderlee\Comprehend\builder\AbstractRuleset;
15
use Vanderlee\Comprehend\Parser\Parser;
16
17
require_once 'functions.php';
18
19
/**
20
 * @property-read Parser ALPHA Alphabetic characters (upper- and lowercase)
21
 * @property-read Parser DIGIT Decimal character
22
 * @property-read Parser HEXDIG Hexadecimal character
23
 * @property-read Parser BIT Binary digit
24
 * @property-read Parser SB Whitespace
25
 *
26
 * @package Vanderlee\Comprehend\Library
27
 */
28
class Rfc2234 extends AbstractRuleset
29
{
30
    protected static $name = 'Rfc2234';
31
32
    public function __construct($overwrites = [])
33
    {
34
        /*
35
         * Support rules.
36
         * These are not part of the published specification, but help make the published rules more manageable without
37
         * altering meaning or syntax. They exist outside the named scope.
38
         */
39
        $hexdigs = plus($this->HEXDIG);
40
        $digits  = plus($this->DIGIT);
41
        $bits    = plus($this->BIT);
42
        $c_wsps  = star($this->c_wsp);
0 ignored issues
show
Bug Best Practice introduced by
The property c_wsp does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
44
        /*
45
         * Normal rules
46
         */
47
        $rules = [
48
            /*
49
             * Core rules
50
             */
51
            'ALPHA'         => set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),
52
            'BIT'           => set('01'),
53
            'CHAR'          => range(0x01, 0x7F),
54
            'CR'            => char("\r"),
55
            'CRLF'          => text("\r\n"),
56
            'DIGIT'         => set('0123456789'),
57
            'DQUOTE'        => char('"'),
58
            'HEXDIG'        => set('0123456789ABCDEF'),
59
            'HTAB'          => char("\t"),
60
            'LF'            => char("\n"),
61
            'LWSP'          => regex("/(?:[ \t]|(?:\r\n[ \t]))*/"),
62
            'OCTET'         => range(0x00, 0xFF),
63
            'SP'            => char(' '),
64
            'VCHAR'         => range(0x21, 0x7E), // ['!', '~']
65
            'WSP'           => set(" \t"),
66
67
            /*
68
             * Definition of ABNF syntax (in reverse order for performance)
69
             */
70
            'prose_val'     => s('<', star(c(range(0x20, 0x3D), range(0x3F, 0x7E))), '>'),
71
            'hex_val'       => s('x', $hexdigs, opt(c(plus(['.', $hexdigs]), ['-', $hexdigs]))),
72
            'dec_val'       => s('d', $digits, opt(c(plus(['.', $digits]), ['-', $digits]))),
73
            'bin_val'       => s('b', $bits, opt(c(plus(['.', $bits]), ['-', $bits]))),
74
            'num_val'       => s('%', [$this->bin_val, $this->dec_val, $this->hex_val]),
0 ignored issues
show
Bug Best Practice introduced by
The property dec_val does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property hex_val does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property bin_val does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
75
            'char_val'      => s($this->DQUOTE, star(c(range(0x20, 0x21), range(0x23, 0x7E))), $this->DQUOTE),
0 ignored issues
show
Bug Best Practice introduced by
The property DQUOTE does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
76
            'option'        => s('[', $c_wsps, $this->alternation, $c_wsps, ']'),
0 ignored issues
show
Bug Best Practice introduced by
The property alternation does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
77
            'group'         => s('(', $c_wsps, $this->alternation, $c_wsps, ')'),
78
            'element'       => c($this->rulename, $this->group, $this->option, $this->char_val, $this->num_val,
0 ignored issues
show
Bug Best Practice introduced by
The property group does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property option does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property num_val does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property rulename does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property char_val does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
79
                $this->prose_val),
0 ignored issues
show
Bug Best Practice introduced by
The property prose_val does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
80
            'repeat'        => c($digits, [star($this->digit), '*', star($this->digit)]),
0 ignored issues
show
Bug Best Practice introduced by
The property digit does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
81
            'repetition'    => s(opt($this->repeat), $this->element),
0 ignored issues
show
Bug Best Practice introduced by
The property repeat does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property element does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
82
            'concatenation' => s($this->repetition, star([plus($this->c_wsp), $this->repetition])),
0 ignored issues
show
Bug Best Practice introduced by
The property repetition does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
83
            'alternation'   => s($this->concatenation, star([$c_wsps, '/', $c_wsps, $this->concatenation])),
0 ignored issues
show
Bug Best Practice introduced by
The property concatenation does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
84
            'comment'       => s(';', star(c($this->WSP, $this->VCHAR)), $this->CRLF),
0 ignored issues
show
Bug Best Practice introduced by
The property VCHAR does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property WSP does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property CRLF does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
85
            'c_nl'          => c($this->comment, $this->CRLF),
0 ignored issues
show
Bug Best Practice introduced by
The property comment does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
86
            'c_wsp'         => c($this->WSP, [$this->c_nl, $this->WSP]),
0 ignored issues
show
Bug Best Practice introduced by
The property c_nl does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
87
            'elements'      => [$this->alternation, $c_wsps],
88
            'defined_as'    => [$c_wsps, ['=', '=/'], $c_wsps],
89
            'rulename'      => s($this->ALPHA, star(c($this->ALPHA, $this->DIGIT, '-'))),
90
            'rule'          => s($this->rulename, $this->defined_as, $this->elements, $this->c_nl),
0 ignored issues
show
Bug Best Practice introduced by
The property defined_as does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property elements does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
91
            'rulelist'      => plus(c($this->rule, [$c_wsps, $this->c_nl])),
0 ignored issues
show
Bug Best Practice introduced by
The property rule does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
92
93
            self::DEFAULT => $this->rulelist,
0 ignored issues
show
Bug Best Practice introduced by
The property rulelist does not exist on Vanderlee\Comprehend\Library\Rfc2234. Since you implemented __get, consider adding a @property annotation.
Loading history...
94
        ];
95
96
        parent::__construct(array_merge($rules, $overwrites));
97
    }
98
}