Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 5... Zeile 5...
5
namespace Doctrine\Common\Lexer;
5
namespace Doctrine\Common\Lexer;
Zeile 6... Zeile 6...
6
 
6
 
7
use ReflectionClass;
7
use ReflectionClass;
Zeile 8... Zeile -...
8
use UnitEnum;
-
 
9
 
8
use UnitEnum;
10
use function get_class;
9
 
11
use function implode;
10
use function implode;
12
use function preg_split;
11
use function preg_split;
Zeile 25... Zeile 24...
25
 */
24
 */
26
abstract class AbstractLexer
25
abstract class AbstractLexer
27
{
26
{
28
    /**
27
    /**
29
     * Lexer original input string.
28
     * Lexer original input string.
30
     *
-
 
31
     * @var string
-
 
32
     */
29
     */
33
    private $input;
30
    private string $input;
Zeile 34... Zeile 31...
34
 
31
 
35
    /**
32
    /**
36
     * Array of scanned tokens.
33
     * Array of scanned tokens.
37
     *
34
     *
38
     * @var list<Token<T, V>>
35
     * @var list<Token<T, V>>
39
     */
36
     */
Zeile 40... Zeile 37...
40
    private $tokens = [];
37
    private array $tokens = [];
41
 
38
 
42
    /**
-
 
43
     * Current lexer position in input string.
-
 
44
     *
39
    /**
45
     * @var int
40
     * Current lexer position in input string.
Zeile 46... Zeile 41...
46
     */
41
     */
47
    private $position = 0;
42
    private int $position = 0;
48
 
-
 
49
    /**
-
 
50
     * Current peek of current lexer position.
43
 
51
     *
44
    /**
Zeile 52... Zeile 45...
52
     * @var int
45
     * Current peek of current lexer position.
53
     */
46
     */
54
    private $peek = 0;
47
    private int $peek = 0;
55
 
48
 
56
    /**
49
    /**
57
     * The next token in the input.
50
     * The next token in the input.
58
     *
51
     *
Zeile 59... Zeile 52...
59
     * @var mixed[]|null
52
     * @var mixed[]|null
60
     * @psalm-var Token<T, V>|null
53
     * @psalm-var Token<T, V>|null
61
     */
54
     */
62
    public $lookahead;
55
    public Token|null $lookahead;
63
 
56
 
64
    /**
57
    /**
65
     * The last matched/seen token.
58
     * The last matched/seen token.
Zeile 66... Zeile 59...
66
     *
59
     *
67
     * @var mixed[]|null
60
     * @var mixed[]|null
68
     * @psalm-var Token<T, V>|null
-
 
69
     */
-
 
70
    public $token;
61
     * @psalm-var Token<T, V>|null
71
 
62
     */
Zeile 72... Zeile 63...
72
    /**
63
    public Token|null $token;
73
     * Composed regex for input parsing.
64
 
74
     *
65
    /**
75
     * @var string|null
66
     * Composed regex for input parsing.
Zeile 84... Zeile 75...
84
     *
75
     *
85
     * @param string $input The input to be tokenized.
76
     * @param string $input The input to be tokenized.
86
     *
77
     *
87
     * @return void
78
     * @return void
88
     */
79
     */
89
    public function setInput($input)
80
    public function setInput(string $input)
90
    {
81
    {
91
        $this->input  = $input;
82
        $this->input  = $input;
92
        $this->tokens = [];
83
        $this->tokens = [];
Zeile 93... Zeile 84...
93
 
84
 
Zeile 123... Zeile 114...
123
     *
114
     *
124
     * @param int $position Position to place the lexical scanner.
115
     * @param int $position Position to place the lexical scanner.
125
     *
116
     *
126
     * @return void
117
     * @return void
127
     */
118
     */
128
    public function resetPosition($position = 0)
119
    public function resetPosition(int $position = 0)
129
    {
120
    {
130
        $this->position = $position;
121
        $this->position = $position;
131
    }
122
    }
Zeile 132... Zeile 123...
132
 
123
 
133
    /**
124
    /**
134
     * Retrieve the original lexer's input until a given position.
125
     * Retrieve the original lexer's input until a given position.
135
     *
-
 
136
     * @param int $position
-
 
137
     *
126
     *
138
     * @return string
127
     * @return string
139
     */
128
     */
140
    public function getInputUntilPosition($position)
129
    public function getInputUntilPosition(int $position)
141
    {
130
    {
142
        return substr($this->input, 0, $position);
131
        return substr($this->input, 0, $position);
Zeile 143... Zeile 132...
143
    }
132
    }
Zeile 149... Zeile 138...
149
     *
138
     *
150
     * @return bool
139
     * @return bool
151
     *
140
     *
152
     * @psalm-assert-if-true !=null $this->lookahead
141
     * @psalm-assert-if-true !=null $this->lookahead
153
     */
142
     */
154
    public function isNextToken($type)
143
    public function isNextToken(int|string|UnitEnum $type)
155
    {
144
    {
156
        return $this->lookahead !== null && $this->lookahead->isA($type);
145
        return $this->lookahead !== null && $this->lookahead->isA($type);
157
    }
146
    }
Zeile 158... Zeile 147...
158
 
147
 
Zeile 192... Zeile 181...
192
     *
181
     *
193
     * @param T $type The token type to skip until.
182
     * @param T $type The token type to skip until.
194
     *
183
     *
195
     * @return void
184
     * @return void
196
     */
185
     */
197
    public function skipUntil($type)
186
    public function skipUntil(int|string|UnitEnum $type)
198
    {
187
    {
199
        while ($this->lookahead !== null && ! $this->lookahead->isA($type)) {
188
        while ($this->lookahead !== null && ! $this->lookahead->isA($type)) {
200
            $this->moveNext();
189
            $this->moveNext();
201
        }
190
        }
202
    }
191
    }
Zeile 203... Zeile 192...
203
 
192
 
204
    /**
193
    /**
205
     * Checks if given value is identical to the given token.
194
     * Checks if given value is identical to the given token.
206
     *
-
 
207
     * @param string     $value
-
 
208
     * @param int|string $token
-
 
209
     *
195
     *
210
     * @return bool
196
     * @return bool
211
     */
197
     */
212
    public function isA($value, $token)
198
    public function isA(string $value, int|string|UnitEnum $token)
213
    {
199
    {
214
        return $this->getType($value) === $token;
200
        return $this->getType($value) === $token;
Zeile 215... Zeile 201...
215
    }
201
    }
Zeile 248... Zeile 234...
248
     *
234
     *
249
     * @param string $input A query string.
235
     * @param string $input A query string.
250
     *
236
     *
251
     * @return void
237
     * @return void
252
     */
238
     */
253
    protected function scan($input)
239
    protected function scan(string $input)
254
    {
240
    {
255
        if (! isset($this->regex)) {
241
        if (! isset($this->regex)) {
256
            $this->regex = sprintf(
242
            $this->regex = sprintf(
257
                '/(%s)|%s/%s',
243
                '/(%s)|%s/%s',
258
                implode(')|(', $this->getCatchablePatterns()),
244
                implode(')|(', $this->getCatchablePatterns()),
259
                implode('|', $this->getNonCatchablePatterns()),
245
                implode('|', $this->getNonCatchablePatterns()),
260
                $this->getModifiers()
246
                $this->getModifiers(),
261
            );
247
            );
262
        }
248
        }
Zeile 263... Zeile 249...
263
 
249
 
264
        $flags   = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
250
        $flags   = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
Zeile 275... Zeile 261...
275
            $type       = $this->getType($firstMatch);
261
            $type       = $this->getType($firstMatch);
Zeile 276... Zeile 262...
276
 
262
 
277
            $this->tokens[] = new Token(
263
            $this->tokens[] = new Token(
278
                $firstMatch,
264
                $firstMatch,
279
                $type,
265
                $type,
280
                $match[1]
266
                $match[1],
281
            );
267
            );
282
        }
268
        }
Zeile 283... Zeile 269...
283
    }
269
    }
Zeile 287... Zeile 273...
287
     *
273
     *
288
     * @param T $token
274
     * @param T $token
289
     *
275
     *
290
     * @return int|string
276
     * @return int|string
291
     */
277
     */
292
    public function getLiteral($token)
278
    public function getLiteral(int|string|UnitEnum $token)
293
    {
279
    {
294
        if ($token instanceof UnitEnum) {
280
        if ($token instanceof UnitEnum) {
295
            return get_class($token) . '::' . $token->name;
281
            return $token::class . '::' . $token->name;
296
        }
282
        }
Zeile 297... Zeile 283...
297
 
283
 
Zeile 298... Zeile 284...
298
        $className = static::class;
284
        $className = static::class;
Zeile 334... Zeile 320...
334
    abstract protected function getNonCatchablePatterns();
320
    abstract protected function getNonCatchablePatterns();
Zeile 335... Zeile 321...
335
 
321
 
336
    /**
322
    /**
337
     * Retrieve token type. Also processes the token value if necessary.
323
     * Retrieve token type. Also processes the token value if necessary.
338
     *
-
 
339
     * @param string $value
-
 
340
     *
324
     *
341
     * @return T|null
325
     * @return T|null
342
     *
326
     *
343
     * @param-out V $value
327
     * @param-out V $value
344
     */
328
     */
345
    abstract protected function getType(&$value);
329
    abstract protected function getType(string &$value);