-
Notifications
You must be signed in to change notification settings - Fork 803
/
Copy pathLexer.php
140 lines (122 loc) · 3.79 KB
/
Lexer.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Parle;
use JetBrains\PhpStorm\Immutable;
/**
* Single state lexer class.
*
* Lexemes can be defined on the fly.
* If the particular lexer instance is meant to be used with Parle\Parser, the token IDs need to be taken from there.
* Otherwise, arbitrary token IDs can be supplied. This lexer can give a certain performance advantage over Parle\RLexer,
* if no multiple states are required. Note, that Parle\RParser is not compatible with this lexer.
*
* @see Parser
* @package Parle
*/
class Lexer
{
/* Constants */
public const ICASE = 1;
public const DOT_NOT_LF = 2;
public const DOT_NOT_CRLF = 4;
public const SKIP_WS = 8;
public const MATCH_ZERO_LEN = 16;
/* Properties */
/**
* @var bool Start of input flag.
*/
public $bol = false;
/**
* @var int Lexer flags.
*/
public $flags = 0;
/**
* @var int Current lexer state, readonly.
*/
#[Immutable]
public $state = 0;
/**
* @var int Position of the latest token match, readonly.
*/
#[Immutable]
public $marker = 0;
/**
* @var int Current input offset, readonly.
*/
#[Immutable]
public $cursor = 0;
/* Methods */
/**
* Processes the next rule and prepares the resulting token data.
*
* @link https://php.net/manual/en/parle-lexer.advance.php
* @return void
*/
public function advance(): void {}
/**
* Finalize the lexer rule set
*
* Rules, previously added with Parle\Lexer::push() are finalized.
* This method call has to be done after all the necessary rules was pushed.
* The rule set becomes read only. The lexing can begin.
*
* @see Lexer::push()
* @link https://php.net/manual/en/parle-lexer.build.php
* @return void
*/
public function build(): void {}
/**
* Define token callback
*
* Define a callback to be invoked once lexer encounters a particular token.
*
* @link https://php.net/manual/en/parle-lexer.callout.php
* @param int $id Token id.
* @param callable $callback Callable to be invoked. The callable doesn't receive any arguments and its return value is ignored.
* @return void
*/
public function callout(int $id, callable $callback): void {}
/**
* Consume the data for lexing.
*
* @link https://php.net/manual/en/parle-lexer.consume.php
* @param string $data Data to be lexed.
* @return void
*/
public function consume(string $data): void {}
/**
* Dump the current state machine to stdout.
*
* @link https://php.net/manual/en/parle-lexer.dump.php
* @return void
*/
public function dump(): void {}
/**
* Retrieve the current token.
*
* @return Token
*/
public function getToken(): Token {}
/**
* Insert a regex macro, that can be later used as a shortcut and included in other regular expressions.
*
* @see https://php.net/manual/en/parle-lexer.insertmacro.php
* @param string $name Name of the macros.
* @param string $regex Regular expression.
* @return void
*/
public function insertMacro(string $name, string $regex): void {}
/**
* Push a pattern for lexeme recognition.
*
* @param string $regex Regular expression used for token matching.
* @param int $id Token id. If the lexer instance is meant to be used standalone, this can be an arbitrary number. If the lexer instance is going to be passed to the parser, it has to be an id returned by Parle\Parser::tokenid().
* @return void
*/
public function push(string $regex, int $id): void {}
/**
* Reset lexing optionally supplying the desired offset.
*
* @param int $pos Reset position.
*/
public function reset(int $pos): void {}
}