Debian Codegraph @

extensions/AbuseFilter/includes/Parser/AFPToken.php

raw symbols SCIP
1 <?php
2
3 namespace 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 */
41 class 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 /**
55 * @var string One of the T* constant from this class
56 */
57 public $type;
58 /**
59 * @var mixed|null The actual value of the token
60 */
61 public $value;
62 /**
63 * @var int The code offset where this token is found
64 */
65 public $pos;
66
67 /**
68 * @param string $type
69 * @param mixed|null $value
70 * @param int $pos
71 */
72 public function __construct( $type = self::TNONE, $value = null, $pos = 0 ) {
73 $this->type = $type;
74 $this->value = $value;
75 $this->pos = $pos;
76 }
77 }