-
Notifications
You must be signed in to change notification settings - Fork 27
/
Lexer.php
69 lines (61 loc) · 2.05 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
<?php
/*
* This file is part of the Yosymfony\Toml package.
*
* (c) YoSymfony <https://github.com/yosymfony>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Yosymfony\Toml;
use Yosymfony\ParserUtils\BasicLexer;
use Yosymfony\ParserUtils\LexerInterface;
use Yosymfony\ParserUtils\TokenStream;
/**
* Lexer for Toml strings.
*
* @author Victor Puertas <[email protected]>
*/
class Lexer implements LexerInterface
{
private $basicLexer;
/**
* Constructor
*/
public function __construct()
{
$this->basicLexer = new BasicLexer([
'/^(=)/' => 'T_EQUAL',
'/^(true|false)/' => 'T_BOOLEAN',
'/^(\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{6})?(Z|-\d{2}:\d{2})?)?)/' => 'T_DATE_TIME',
'/^([+-]?((((\d_?)+[\.]?(\d_?)*)[eE][+-]?(\d_?)+)|((\d_?)+[\.](\d_?)+)))/' => 'T_FLOAT',
'/^([+-]?(\d_?)+)/' => 'T_INTEGER',
'/^(""")/' => 'T_3_QUOTATION_MARK',
'/^(")/' => 'T_QUOTATION_MARK',
"/^(''')/" => 'T_3_APOSTROPHE',
"/^(')/" => 'T_APOSTROPHE',
'/^(#)/' => 'T_HASH',
'/^(\s+)/' => 'T_SPACE',
'/^(\[)/' => 'T_LEFT_SQUARE_BRAKET',
'/^(\])/' => 'T_RIGHT_SQUARE_BRAKET',
'/^(\{)/' => 'T_LEFT_CURLY_BRACE',
'/^(\})/' => 'T_RIGHT_CURLY_BRACE',
'/^(,)/' => 'T_COMMA',
'/^(\.)/' => 'T_DOT',
'/^([-A-Z_a-z0-9]+)/' => 'T_UNQUOTED_KEY',
'/^(\\\(b|t|n|f|r|"|\\\\|u[0-9AaBbCcDdEeFf]{4,4}|U[0-9AaBbCcDdEeFf]{8,8}))/' => 'T_ESCAPED_CHARACTER',
'/^(\\\)/' => 'T_ESCAPE',
'/^([\x{20}-\x{21}\x{23}-\x{26}\x{28}-\x{5A}\x{5E}-\x{10FFFF}]+)/u' => 'T_BASIC_UNESCAPED',
]);
$this->basicLexer
->generateNewlineTokens()
->generateEosToken();
}
/**
* {@inheritdoc}
*/
public function tokenize(string $input) : TokenStream
{
return $this->basicLexer->tokenize($input);
}
}