Repository navigation
Expand file tree
/
Copy pathclass-wp-parser-token.php
More file actions
79 lines (72 loc) · 1.6 KB
/
Copy pathclass-wp-parser-token.php
File metadata and controls
79 lines (72 loc) · 1.6 KB
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
78
79
<?php
/**
* A token, representing a leaf in the parse tree.
*
* This class represents a token that is consumed and recognized by WP_Parser.
* In a parse tree, a token represent a leaf, that is, a node without children.
* It is a simple generic container for a token ID and value, that can be used
* as a base class and extended for specific use cases.
*
* @access private
*/
class WP_Parser_Token {
/**
* Token ID represented as an integer constant.
*
* @var int $id
*/
public $id;
/**
* Byte offset in the input where the token begins.
*
* @var int
*/
public $start;
/**
* Byte length of the token in the input.
*
* @var int
*/
public $length;
/**
* Input bytes from which the token was parsed.
*
* @var string
*/
protected $input;
/**
* Constructor.
*
* @param int $id Token type.
* @param int $start Byte offset in the input where the token begins.
* @param int $length Byte length of the token in the input.
* @param string $input Input bytes from which the token was parsed.
*/
public function __construct(
int $id,
int $start,
int $length,
string $input
) {
$this->id = $id;
$this->start = $start;
$this->length = $length;
$this->input = $input;
}
/**
* Get the raw bytes of the token from the input.
*
* @return string The token bytes.
*/
public function get_bytes(): string {
return substr( $this->input, $this->start, $this->length );
}
/**
* Get the real unquoted value of the token.
*
* @return string The token value.
*/
public function get_value(): string {
return $this->get_bytes();
}
}