Skip to content

Commit 457bfbf

Browse files
committed
syntax: allowed tab as separator for dashed-blocks
1 parent 5715e17 commit 457bfbf

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

src/Neon/Parser.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,14 @@ private function parseBlock(string $indent, bool $onlyBullets = false): Node
8686
} elseif ($item->key !== null && $this->tokens->isNext('-')) { // special dash subblock
8787
$item->value = $this->parseBlock($indent, onlyBullets: true);
8888
}
89-
} elseif ($item->key === null) {
90-
$item->value = $this->parseBlock($indent . ' '); // open new block after dash
91-
89+
} elseif ($item->key === null) { // open new block after dash
90+
$save = $this->tokens->getPos();
91+
try {
92+
$item->value = $this->parseBlock($indent . "\t");
93+
} catch (Exception) {
94+
$this->tokens->seek($save);
95+
$item->value = $this->parseBlock($indent . ' ');
96+
}
9297
} elseif ($this->tokens->isNext()) {
9398
$item->value = $this->parseValue();
9499
if ($this->tokens->isNext() && !$this->tokens->isNext(Token::Newline)) {

src/Neon/TokenStream.php

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public function getPos(): int
2929
}
3030

3131

32+
public function seek(int $position): void
33+
{
34+
$this->pos = $position;
35+
}
36+
37+
3238
/** @return Token[] */
3339
public function getTokens(): array
3440
{

tests/Neon/Decoder.array.phpt

+51
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,57 @@ Assert::same(
170170
);
171171

172172

173+
Assert::same(
174+
[
175+
[
176+
'a' => 'b',
177+
'c' => 'd',
178+
],
179+
],
180+
Neon::decode(<<<'XX'
181+
- a: b
182+
c: d
183+
XX),
184+
);
185+
186+
187+
Assert::same(
188+
[
189+
[
190+
'a' => 'b',
191+
[
192+
'c' => 'd',
193+
['e' => 'f'],
194+
],
195+
],
196+
],
197+
Neon::decode(<<<'XX'
198+
- a: b
199+
- c: d
200+
- e: f
201+
XX),
202+
);
203+
204+
205+
Assert::same(
206+
[
207+
[
208+
'a' => 'b',
209+
[
210+
'c' => 'd',
211+
'e' => 'f',
212+
],
213+
],
214+
],
215+
Neon::decode(<<<'XX'
216+
- a: b
217+
- c: d
218+
e: f
219+
XX),
220+
);
221+
222+
223+
173224
Assert::same(
174225
[
175226
'root' => [['key1' => null, 'key3' => 123]],

tests/Neon/fixtures/Parser.nodes.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ third:
1818
b: 2
1919

2020
-
21-
- c
21+
- c
2222

2323
dash subblock:
2424
- a

tests/Neon/fixtures/Parser.nodes.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ Nette\Neon\Node\BlockArrayNode
467467
| | key: null
468468
| | value: Nette\Neon\Node\BlockArrayNode
469469
| | | code: '- c'
470-
| | | indentation: ' '
470+
| | | indentation: '\t '
471471
| | | items: array (1)
472472
| | | | 0 => Nette\Neon\Node\ArrayItemNode
473473
| | | | | code: '- c'

0 commit comments

Comments
 (0)