File: AFPToken.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (77 lines) | stat: -rw-r--r-- 1,954 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace MediaWiki\Extension\AbuseFilter\Parser;

/**
 * Abuse filter parser.
 * Copyright © Victor Vasiliev, 2008.
 * Based on ideas by Andrew Garrett
 * Distributed under GNU GPL v2 terms.
 *
 * Types of token:
 * * T_NONE - special-purpose token
 * * T_BRACE  - ( or )
 * * T_COMMA - ,
 * * T_OP - operator like + or ^
 * * T_NUMBER - number
 * * T_STRING - string, in "" or ''
 * * T_KEYWORD - keyword
 * * T_ID - identifier
 * * T_STATEMENT_SEPARATOR - ;
 * * T_SQUARE_BRACKETS - [ or ]
 *
 * Levels of parsing:
 * * Entry - catches unexpected characters
 * * Semicolon - ;
 * * Set - :=
 * * Conditionals (IF) - if-then-else-end, cond ? a :b
 * * BoolOps (BO) - &, |, ^
 * * CompOps (CO) - ==, !=, ===, !==, >, <, >=, <=
 * * SumRel (SR) - +, -
 * * MulRel (MR) - *, /, %
 * * Pow (P) - **
 * * BoolNeg (BN) - ! operation
 * * SpecialOperators (SO) - in and like
 * * Unarys (U) - plus and minus in cases like -5 or -(2 * +2)
 * * ArrayElement (AE) - array[number]
 * * Braces (B) - ( and )
 * * Functions (F)
 * * Atom (A) - return value
 */
class AFPToken {
	public const TNONE = 'T_NONE';
	public const TID = 'T_ID';
	public const TKEYWORD = 'T_KEYWORD';
	public const TSTRING = 'T_STRING';
	public const TINT = 'T_INT';
	public const TFLOAT = 'T_FLOAT';
	public const TOP = 'T_OP';
	public const TBRACE = 'T_BRACE';
	public const TSQUAREBRACKET = 'T_SQUARE_BRACKET';
	public const TCOMMA = 'T_COMMA';
	public const TSTATEMENTSEPARATOR = 'T_STATEMENT_SEPARATOR';

	/**
	 * @var string One of the T* constant from this class
	 */
	public $type;
	/**
	 * @var mixed|null The actual value of the token
	 */
	public $value;
	/**
	 * @var int The code offset where this token is found
	 */
	public $pos;

	/**
	 * @param string $type
	 * @param mixed|null $value
	 * @param int $pos
	 */
	public function __construct( $type = self::TNONE, $value = null, $pos = 0 ) {
		$this->type = $type;
		$this->value = $value;
		$this->pos = $pos;
	}
}