Skip to content

Commit

Permalink
Refactor code to work without lang.reflect.Package
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jul 30, 2023
1 parent 95b7da2 commit 963b04a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/php/lang/ast/Language.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use lang\ast\nodes\{Assignment, BinaryExpression, Literal, UnaryExpression};
use lang\ast\syntax\Extension;
use lang\reflect\Package;
use lang\{ClassLoader, XPClass};

/**
* Base class for input languages
Expand Down Expand Up @@ -155,8 +155,14 @@ public function statements($parse) {
* @return iterable
*/
public function extensions() {
foreach (Package::forName(strtr(strtolower(static::class), '\\', '.'))->getClasses() as $class) {
if ($class->isSubclassOf(Extension::class)) yield $class->newInstance();
$offset= -strlen(\xp::CLASS_FILE_EXT);
$cl= ClassLoader::getDefault();
$package= strtr(strtolower(static::class), '\\', '.');
foreach ($cl->packageContents($package) as $item) {
if (0 === substr_compare($item, \xp::CLASS_FILE_EXT, $offset)) {
$class= $cl->loadClass($package.'.'.substr($item, 0, $offset));
if ($class->isSubclassOf(Extension::class)) yield $class->newInstance();
}
}
}

Expand All @@ -179,7 +185,7 @@ public function parse($tokens, Scope $scope= null) {
*/
public static function named($name) {
if (!isset(self::$instance[$name])) {
self::$instance[$name]= Package::forName('lang.ast.syntax')->loadClass($name)->newInstance();
self::$instance[$name]= XPClass::forName('lang.ast.syntax.'.$name)->newInstance();
}
return self::$instance[$name];
}
Expand Down

0 comments on commit 963b04a

Please sign in to comment.