Skip to content

Commit 49e216d

Browse files
committed
wippity wip
1 parent 6a8fd4f commit 49e216d

16 files changed

+165
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ todo.md
1111
.env
1212
/storage/local-results
1313
/tests/snippets
14+
/storage/new-parsed
15+
storage/tree.txt

app/Contexts/Argument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public function type(): string
99
return 'argument';
1010
}
1111

12-
public function castToArray(): array
12+
public function toArray(): array
1313
{
14-
return [];
14+
return parent::toArray()['children'][0] ?? [];
1515
}
1616
}

app/Contexts/Arguments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public function type(): string
99
return 'arguments';
1010
}
1111

12-
public function castToArray(): array
12+
public function toArray(): array
1313
{
14-
return [];
14+
return parent::toArray()['children'];
1515
}
1616
}

app/Contexts/ArrayItem.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Contexts;
4+
5+
class ArrayItem extends BaseContext
6+
{
7+
public function type(): string
8+
{
9+
return 'array_item';
10+
}
11+
12+
public function castToArray(): array
13+
{
14+
$key = null;
15+
$value = null;
16+
17+
if (count($this->children) === 1) {
18+
[$value] = $this->children;
19+
} elseif (count($this->children) === 2) {
20+
[$key, $value] = $this->children;
21+
}
22+
23+
$this->children = [];
24+
25+
return [
26+
'key' => $key?->toArray(),
27+
'value' => $value?->toArray(),
28+
];
29+
}
30+
}

app/Contexts/ArrayValue.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Contexts;
4+
5+
class ArrayValue extends BaseContext
6+
{
7+
public function type(): string
8+
{
9+
return 'array';
10+
}
11+
}

app/Contexts/Assignment.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Contexts;
4+
5+
class Assignment extends BaseContext
6+
{
7+
public ?string $name = null;
8+
9+
public AssignmentValue $value;
10+
11+
public function init()
12+
{
13+
$this->value = new AssignmentValue;
14+
}
15+
16+
public function type(): string
17+
{
18+
return 'assignment';
19+
}
20+
21+
public function castToArray(): array
22+
{
23+
return [
24+
'name' => $this->name,
25+
'value' => $this->value->toArray(),
26+
];
27+
}
28+
}

app/Contexts/AssignmentValue.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Contexts;
4+
5+
class AssignmentValue extends BaseContext
6+
{
7+
public function type(): string
8+
{
9+
return 'assignment_value';
10+
}
11+
}

app/Contexts/BaseContext.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ abstract class BaseContext
1010

1111
protected bool $hasChildren = true;
1212

13-
abstract public function castToArray(): array;
14-
1513
abstract public function type(): string;
1614

15+
public function castToArray(): array
16+
{
17+
return [];
18+
}
19+
1720
public function __construct(protected $label = '')
1821
{
1922
if (method_exists($this, 'init')) {
@@ -52,10 +55,10 @@ public function touched(): bool
5255
public function toArray(): array
5356
{
5457
return array_merge(
55-
$this->castToArray(),
5658
[
5759
'type' => $this->type(),
5860
],
61+
$this->castToArray(),
5962
($this->label !== '') ? ['label' => $this->label] : [],
6063
($this->hasChildren) ? ['children' => array_map(fn($child) => $child->toArray(), $this->children)] : [],
6164
);

app/Contexts/Generic.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,4 @@ public function type(): string
99
{
1010
return 'generic';
1111
}
12-
13-
public function castToArray(): array
14-
{
15-
return [];
16-
}
1712
}

app/Contexts/Parameters.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,4 @@ public function type(): string
88
{
99
return 'parameters';
1010
}
11-
12-
public function castToArray(): array
13-
{
14-
return [];
15-
}
1611
}

0 commit comments

Comments
 (0)