1 | <?php |
||
16 | class Lexer |
||
17 | { |
||
18 | private static $CONDITON = 0; |
||
19 | private static $VALUE = 1; |
||
20 | |||
21 | 354 | public function readString($string) |
|
22 | { |
||
23 | 354 | $tokens = Tokenizer::tokenize($string); |
|
24 | 354 | if (empty($tokens)) { |
|
25 | 1 | return null; |
|
26 | } |
||
27 | 353 | return $this->readForm(new Reader($tokens)); |
|
28 | } |
||
29 | |||
30 | 353 | private function readForm(Reader $reader) |
|
31 | { |
||
32 | 353 | switch ($reader->peek()) { |
|
33 | 353 | case '(': |
|
34 | 332 | $reader->next(); |
|
35 | 332 | $collection = new ListType(); |
|
36 | 332 | return $this->readCollection($reader, $collection, ')'); |
|
37 | 353 | case ')': |
|
38 | 1 | throw new Exception('Unexpected )'); |
|
39 | 352 | case '[': |
|
40 | 57 | $reader->next(); |
|
41 | 57 | $collection = new VectorType(); |
|
42 | 57 | return $this->readCollection($reader, $collection, ']'); |
|
43 | 352 | case ']': |
|
44 | 1 | throw new Exception('Unexpected ]'); |
|
45 | 351 | case '{': |
|
46 | 33 | $reader->next(); |
|
47 | 33 | $hash = new HashType(); |
|
48 | 33 | return $this->readHash($reader, $hash); |
|
49 | 351 | case '}': |
|
50 | 2 | throw new Exception('Unexpected }'); |
|
51 | default: |
||
52 | 350 | $form = $this->readAtom($reader->peek()); |
|
53 | 350 | $reader->next(); |
|
54 | 350 | return $form; |
|
55 | } |
||
56 | } |
||
57 | |||
58 | 335 | private function readCollection(Reader $reader, $collection, $end) |
|
69 | |||
70 | 33 | private function readHash(Reader $reader, $hash) |
|
87 | |||
88 | 350 | private function readAtom($token) |
|
89 | { |
||
99 | |||
100 | 350 | private function tokenTestList($token) |
|
111 | } |
||
112 |