Skip to content

Commit af3a192

Browse files
committed
wipppp
1 parent 49e216d commit af3a192

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+998
-364
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ todo.md
1313
/tests/snippets
1414
/storage/new-parsed
1515
storage/tree.txt
16+
/storage/logs

app/Contexts/BaseContext.php renamed to app/Contexts/AbstractContext.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
namespace App\Contexts;
44

5-
abstract class BaseContext
5+
abstract class AbstractContext
66
{
77
public $children = [];
88

99
protected array $freshObject;
1010

1111
protected bool $hasChildren = true;
1212

13+
protected ?AbstractContext $parent = null;
14+
1315
abstract public function type(): string;
1416

1517
public function castToArray(): array
@@ -31,17 +33,34 @@ protected function freshArray()
3133
return $this->toArray();
3234
}
3335

34-
public function initNew(BaseContext $newContext)
36+
public function initNew(AbstractContext $newContext)
3537
{
36-
// if ($this->pristine()) {
37-
// return $this;
38-
// }
38+
$newContext->parent = $this;
3939

4040
$this->children[] = $newContext;
4141

4242
return $newContext;
4343
}
4444

45+
public function searchForVar(string $name): AssignmentValue | string | null
46+
{
47+
if ($this instanceof ClosureValue) {
48+
foreach ($this->parameters->children as $param) {
49+
if ($param->name === $name) {
50+
return $param->types[0] ?? null;
51+
}
52+
}
53+
}
54+
55+
foreach ($this->children as $child) {
56+
if ($child instanceof Assignment && $child->name === $name) {
57+
return $child->value;
58+
}
59+
}
60+
61+
return $this->parent?->searchForVar($name) ?? null;
62+
}
63+
4564
public function pristine(): bool
4665
{
4766
return $this->freshObject === $this->freshArray();

app/Contexts/Argument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Contexts;
44

5-
class Argument extends BaseContext
5+
class Argument extends AbstractContext
66
{
77
public function type(): string
88
{

app/Contexts/Arguments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Contexts;
44

5-
class Arguments extends BaseContext
5+
class Arguments extends AbstractContext
66
{
77
public function type(): string
88
{

app/Contexts/ArrayItem.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
namespace App\Contexts;
44

5-
class ArrayItem extends BaseContext
5+
use Illuminate\Support\Arr;
6+
7+
class ArrayItem extends AbstractContext
68
{
79
public function type(): string
810
{
911
return 'array_item';
1012
}
1113

14+
public function toArray(): array
15+
{
16+
return Arr::except(parent::toArray(), ['children', 'type']);
17+
}
18+
1219
public function castToArray(): array
1320
{
1421
$key = null;
@@ -20,8 +27,6 @@ public function castToArray(): array
2027
[$key, $value] = $this->children;
2128
}
2229

23-
$this->children = [];
24-
2530
return [
2631
'key' => $key?->toArray(),
2732
'value' => $value?->toArray(),

app/Contexts/ArrayValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Contexts;
44

5-
class ArrayValue extends BaseContext
5+
class ArrayValue extends AbstractContext
66
{
77
public function type(): string
88
{

app/Contexts/Assignment.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace App\Contexts;
44

5-
class Assignment extends BaseContext
5+
class Assignment extends AbstractContext
66
{
77
public ?string $name = null;
88

99
public AssignmentValue $value;
1010

11+
protected bool $hasChildren = false;
12+
1113
public function init()
1214
{
1315
$this->value = new AssignmentValue;

app/Contexts/AssignmentValue.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,29 @@
22

33
namespace App\Contexts;
44

5-
class AssignmentValue extends BaseContext
5+
class AssignmentValue extends AbstractContext
66
{
77
public function type(): string
88
{
99
return 'assignment_value';
1010
}
11+
12+
public function toArray(): array
13+
{
14+
return parent::toArray()['children'];
15+
}
16+
17+
public function getValue()
18+
{
19+
$child = $this->children[0] ?? null;
20+
21+
if ($child) {
22+
return [
23+
'name' => $child->name,
24+
'type' => $child->type(),
25+
];
26+
}
27+
28+
return null;
29+
}
1130
}

app/Contexts/Generic.php renamed to app/Contexts/Base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace App\Contexts;
44

5-
class Generic extends BaseContext
5+
class Base extends AbstractContext
66
{
77

88
public function type(): string
99
{
10-
return 'generic';
10+
return 'base';
1111
}
1212
}

app/Contexts/ClassDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Contexts;
44

5-
class ClassDefinition extends BaseContext
5+
class ClassDefinition extends AbstractContext
66
{
77
public ?string $name = null;
88

0 commit comments

Comments
 (0)