|
8 | 8 | */ |
9 | 9 | namespace nicoSWD\Rules\AST; |
10 | 10 |
|
11 | | -use nicoSWD\Rules\Constants; |
12 | | -use nicoSWD\Rules\Exceptions\ParserException; |
13 | | -use nicoSWD\Rules\Tokens\BaseToken; |
14 | 11 | use nicoSWD\Rules\Tokens\TokenArray; |
15 | | -use nicoSWD\Rules\Tokens\TokenComma; |
16 | 12 |
|
17 | 13 | /** |
18 | 14 | * Class NodeArray |
|
21 | 17 | final class NodeArray extends BaseNode |
22 | 18 | { |
23 | 19 | /** |
24 | | - * @return BaseToken |
25 | | - * @throws ParserException |
| 20 | + * @return \nicoSWD\Rules\Tokens\BaseToken |
| 21 | + * @throws \nicoSWD\Rules\Exceptions\ParserException |
26 | 22 | */ |
27 | 23 | public function getNode() |
28 | 24 | { |
29 | 25 | $stack = $this->ast->getStack(); |
30 | 26 | $offset = $stack->current()->getOffset(); |
31 | | - $commaExpected = \false; |
32 | | - $items = []; |
33 | | - |
34 | | - do { |
35 | | - $stack->next(); |
36 | | - |
37 | | - if (!$current = $stack->current()) { |
38 | | - throw new ParserException(sprintf( |
39 | | - 'Unexpected end of string. Expected "]"' |
40 | | - )); |
41 | | - } |
42 | | - |
43 | | - $value = $current->getValue(); |
44 | | - |
45 | | - if ($current->getGroup() === Constants::GROUP_VALUE) { |
46 | | - if ($commaExpected) { |
47 | | - throw new ParserException(sprintf( |
48 | | - 'Unexpected value at position %d on line %d', |
49 | | - $current->getPosition(), |
50 | | - $current->getLine() |
51 | | - )); |
52 | | - } |
53 | | - |
54 | | - $commaExpected = \true; |
55 | | - $items[] = $value; |
56 | | - } elseif ($current instanceof TokenComma) { |
57 | | - if (!$commaExpected) { |
58 | | - throw new ParserException(sprintf( |
59 | | - 'Unexpected token "," at position %d on line %d', |
60 | | - $current->getPosition(), |
61 | | - $current->getLine() |
62 | | - )); |
63 | | - } |
64 | | - |
65 | | - $commaExpected = \false; |
66 | | - } elseif ($value === ']') { |
67 | | - break; |
68 | | - } elseif (!$this->isIgnoredToken($current)) { |
69 | | - throw new ParserException(sprintf( |
70 | | - 'Unexpected token "%s" at position %d on line %d', |
71 | | - $current->getOriginalValue(), |
72 | | - $current->getPosition(), |
73 | | - $current->getLine() |
74 | | - )); |
75 | | - } |
76 | | - } while ($stack->valid()); |
77 | | - |
78 | | - if (!$commaExpected && !empty($items)) { |
79 | | - throw new ParserException(sprintf( |
80 | | - 'Unexpected token "," at position %d on line %d', |
81 | | - $current->getPosition(), |
82 | | - $current->getLine() |
83 | | - )); |
84 | | - } |
85 | | - |
86 | | - $token = new TokenArray($items, $offset, $stack); |
| 27 | + $token = new TokenArray($this->getCommaSeparatedValues(']'), $offset, $stack); |
87 | 28 |
|
88 | 29 | while ($this->hasMethodCall()) { |
89 | | - $token = $this->getMethod($token)->call($this->getFunctionArgs()); |
| 30 | + $token = $this->getMethod($token)->call($this->getCommaSeparatedValues()); |
90 | 31 | } |
91 | 32 |
|
92 | 33 | return $token; |
|
0 commit comments