Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AFPToken
100.00% covered (success)
100.00%
1 / 1
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
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\AbuseFilter\Parser;
4
5/**
6 * Abuse filter parser.
7 * Copyright © Victor Vasiliev, 2008.
8 * Based on ideas by Andrew Garrett
9 * Distributed under GNU GPL v2 terms.
10 *
11 * Types of token:
12 * * T_NONE - special-purpose token
13 * * T_BRACE  - ( or )
14 * * T_COMMA - ,
15 * * T_OP - operator like + or ^
16 * * T_NUMBER - number
17 * * T_STRING - string, in "" or ''
18 * * T_KEYWORD - keyword
19 * * T_ID - identifier
20 * * T_STATEMENT_SEPARATOR - ;
21 * * T_SQUARE_BRACKETS - [ or ]
22 *
23 * Levels of parsing:
24 * * Entry - catches unexpected characters
25 * * Semicolon - ;
26 * * Set - :=
27 * * Conditionals (IF) - if-then-else-end, cond ? a :b
28 * * BoolOps (BO) - &, |, ^
29 * * CompOps (CO) - ==, !=, ===, !==, >, <, >=, <=
30 * * SumRel (SR) - +, -
31 * * MulRel (MR) - *, /, %
32 * * Pow (P) - **
33 * * BoolNeg (BN) - ! operation
34 * * SpecialOperators (SO) - in and like
35 * * Unarys (U) - plus and minus in cases like -5 or -(2 * +2)
36 * * ArrayElement (AE) - array[number]
37 * * Braces (B) - ( and )
38 * * Functions (F)
39 * * Atom (A) - return value
40 */
41class AFPToken {
42    public const TNONE = 'T_NONE';
43    public const TID = 'T_ID';
44    public const TKEYWORD = 'T_KEYWORD';
45    public const TSTRING = 'T_STRING';
46    public const TINT = 'T_INT';
47    public const TFLOAT = 'T_FLOAT';
48    public const TOP = 'T_OP';
49    public const TBRACE = 'T_BRACE';
50    public const TSQUAREBRACKET = 'T_SQUARE_BRACKET';
51    public const TCOMMA = 'T_COMMA';
52    public const TSTATEMENTSEPARATOR = 'T_STATEMENT_SEPARATOR';
53
54    public function __construct(
55        public readonly string $type = self::TNONE,
56        public readonly mixed $value = null,
57        public readonly int $pos = 0
58    ) {
59    }
60}