1 | <?php |
||
8 | class Tokenizer { |
||
9 | private $str; |
||
10 | const NAME = 1; |
||
11 | const STRING = 2; |
||
12 | const STRING2 = 3; |
||
13 | const OPEN_BRACKET = 4; |
||
14 | const CLOSE_BRACKET = 5; |
||
15 | const OPEN_SQUARE_BRACKET = 6; |
||
16 | const CLOSE_SQUARE_BRACKET = 7; |
||
17 | const CONCAT = 8; |
||
18 | const ARG = 9; |
||
19 | const WHITESPACE = 10; |
||
20 | const DOT = 11; |
||
21 | const NUMERIC = 12; |
||
22 | const EQUALS = 13; |
||
23 | const NOT = 14; |
||
24 | const OPEN_BRACE = 15; |
||
25 | const CLOSE_BRACE = 16; |
||
26 | const BOOL = 17; |
||
27 | |||
28 | public $chars = [ |
||
29 | '"' => self::STRING, |
||
30 | '\'' => self::STRING2, |
||
31 | '(' => self::OPEN_BRACKET, |
||
32 | ')' => self::CLOSE_BRACKET, |
||
33 | '[' => self::OPEN_SQUARE_BRACKET, |
||
34 | ']' => self::CLOSE_SQUARE_BRACKET, |
||
35 | '+' => self::CONCAT, |
||
36 | ',' => self::ARG, |
||
37 | '.' => self::DOT, |
||
38 | '!' => self::NOT, |
||
39 | '=' => self::EQUALS, |
||
40 | '{' => self::OPEN_BRACE, |
||
41 | '}' => self::CLOSE_BRACE, |
||
42 | ' ' => self::WHITESPACE, |
||
43 | "\n" => self::WHITESPACE, |
||
44 | "\r" => self::WHITESPACE, |
||
45 | "\t" => self::WHITESPACE |
||
46 | ]; |
||
47 | |||
48 | public function __construct($str) { |
||
51 | |||
52 | public function getTokens() { |
||
65 | |||
66 | private function doSimpleTokens(&$tokens, $char) { |
||
71 | |||
72 | private function doLiterals(&$tokens, $char, &$i) { |
||
85 | |||
86 | private function doBrackets(&$tokens, $char, $i) { |
||
102 | |||
103 | private function doStrings(&$tokens, $char, $i) { |
||
113 | |||
114 | private function extractString($pos) { |
||
121 | |||
122 | private function extractBrackets($open, $startBracket = '(', $closeBracket = ')') { |
||
129 | |||
130 | private function identifyChar($chr) { |
||
134 | |||
135 | private function getChar($num) { |
||
140 | } |
||
141 |