phpast: goodbye

This commit is contained in:
Ryan Chandler 2022-08-11 17:14:31 +01:00
parent a2cad0b630
commit 0531ed39b9
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
38 changed files with 0 additions and 362 deletions

View File

@ -5,5 +5,4 @@ members = [
"trunk_value",
"trunk_interner",
"trunk_gc",
"phpast",
]

View File

@ -1,11 +0,0 @@
[package]
name = "phpast"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = "1.0.139"
serde_json = "1.0.82"
structopt = { version = "0.3.26", features = ["color"] }
trunk_lexer = { path = "../trunk_lexer" }
trunk_parser = { path = "../trunk_parser" }

View File

@ -1,4 +0,0 @@
<?php
$foo = new class {};
$bar = new class(1) {};

View File

@ -1,3 +0,0 @@
<?php
$foo['foo'];

View File

@ -1,7 +0,0 @@
<?php
[
1,
2,
3
];

View File

@ -1,3 +0,0 @@
<?php
$i = 1;

View File

@ -1,7 +0,0 @@
<?php
[
5 => 1,
6 => 2,
7 => 3,
];

View File

@ -1,3 +0,0 @@
<?php
! $foo;

View File

@ -1,10 +0,0 @@
<?php
class Foo
{
var $bar;
}
class Bar {
public $baz;
}

View File

@ -1,9 +0,0 @@
<?php
trait Foo {
}
class Bar {
use Foo;
}

View File

@ -1,3 +0,0 @@
<?php
class Foo {}

View File

@ -1,7 +0,0 @@
<?php
$long = function () {
};
$short = fn () => 1;

View File

@ -1,3 +0,0 @@
<?php
1 ?? 2 ?? 3;

View File

@ -1,10 +0,0 @@
<?php
/**
* This is my function.
*
* @return void
*/
function foo() {
}

View File

@ -1,17 +0,0 @@
<?php
enum Foo {
case Bar;
}
enum Bar: string {
case Baz = 'car';
}
enum Baz: int {
case Caz = 'boo';
}
enum Foo implements Bob {
}

View File

@ -1,6 +0,0 @@
<?php
$foo == $bar;
$foo === $bar;
$foo != $bar;
$foo !== $bar;

View File

@ -1,11 +0,0 @@
<?php
function fib(int $n) {
if ($n < 2) {
return $n;
}
return fib($n - 1) + fib($n - 2);
}
echo fib(30) . PHP_EOL;

View File

@ -1,4 +0,0 @@
<?php
final class Foo {}
abstract class Bar {}

View File

@ -1,5 +0,0 @@
<?php
for ($i = 0; $i < $j; $i += 1) {
}

View File

@ -1,9 +0,0 @@
<?php
foreach ($foo as $bar) {}
foreach ($foo as $bar => $baz) {}
foreach ($foo as $bar => [$baz, $bob]) {
}

View File

@ -1,32 +0,0 @@
<?php
class ClassConstant {
const FOO = 1;
}
class VarDec {
var $foo;
var string $bar;
}
class PropDefs {
public static $foo;
public string $bar;
public $baz = 100;
}
abstract class Methods {
public function foo() {
}
abstract public function bar(): string;
final public function boo() {
}
}
class VisibleClassConstant {
final protected const BAR = 2;
}

View File

@ -1,11 +0,0 @@
<?php
if($foo) {
return $foo;
} elseif($foo) {
return $foo;
} elseif($foo) {
return $foo;
} else {
return $foo;
}

View File

@ -1,11 +0,0 @@
<?php
interface Foo {}
interface Bar extends Foo {}
interface Car {}
interface Baz extends Bar, Car {}
interface Bob {
public function bar(): string;
function boo();
}

View File

@ -1,7 +0,0 @@
<?php
match ($expr) {
'foo' => 'bar',
'baz', 'car', 'bob' => 'foop',
default => null,
};

View File

@ -1,9 +0,0 @@
<?php
$foo->bar();
$foo->bar(1, 2, 3);
$foo->bar()->baz();
$foo->bar->baz();
$foo->bar()();

View File

@ -1,3 +0,0 @@
<?php
foo(name: 'bar', 'foo');

View File

@ -1,5 +0,0 @@
<?php
namespace Foo\Baz {
class Bar {}
}

View File

@ -1,7 +0,0 @@
<?php
class Foo {}
$foo = new Foo;
$bar = new Foo(123);

View File

@ -1,4 +0,0 @@
<?php
$foo->bar;
$foo->bar->baz;

View File

@ -1,3 +0,0 @@
<?php
function foo(): string {}

View File

@ -1,5 +0,0 @@
<?php
Schema::table($table, function (Blueprint $table) use ($columns) {
$table->dropColumn($columns);
});

View File

@ -1,11 +0,0 @@
<?php
switch ($foo) {
case 'foo':
break;
case 'bar':
case 'baz':
echo $foo;
default:
break;
}

View File

@ -1,10 +0,0 @@
<?php
trait Foo {}
trait Bar {
var $foo;
public function baz() {
}
}

View File

@ -1,7 +0,0 @@
<?php
try {
} catch (Exception | Throwable $e) {
}

View File

@ -1,17 +0,0 @@
<?php
function plain(string $b) {
}
function nullable(?string $f) {
}
function foo(int|float $bar) {
}
function intersection(Model&HasComments $model) {
}

View File

@ -1,3 +0,0 @@
<?php
function () use ($bar) {};

View File

@ -1,7 +0,0 @@
<?php
function foo(...$bar) {}
function bar(string ...$baz) {}
function baz($foo, $bar, ...$baz) {}

View File

@ -1,77 +0,0 @@
use std::{path::PathBuf, process::exit};
use serde_json::to_string;
use structopt::StructOpt;
use trunk_lexer::Lexer;
use trunk_parser::Parser;
#[derive(Debug, StructOpt)]
#[structopt(name = "phpast", about = "Generate an abstract syntax tree from a PHP file.")]
struct Args {
#[structopt(parse(from_os_str), help = "The input file to use.")]
file: Option<PathBuf>,
#[structopt(short, long, help = "Output the abstract syntax tree as JSON.")]
json: bool,
#[structopt(short, long, help = "Only execute the lexer on the source file.")]
lexer: bool,
#[structopt(short, long, help = "Provide a string to execute.")]
run: Option<String>,
#[structopt(short, long, help = "Dump tokens.")]
dump_tokens: bool,
#[structopt(short, long, help = "Print the AST.")]
print: bool,
}
fn main() {
let args = Args::from_args();
let input = if args.file.is_some() {
match std::fs::read_to_string(args.file.unwrap()) {
Ok(contents) => contents,
Err(e) => {
eprintln!("{}", e);
exit(1);
},
}
} else if args.run.is_some() {
args.run.unwrap()
} else {
panic!("boo!");
};
let mut lexer = Lexer::new(None);
let tokens = lexer.tokenize(&input[..]).unwrap();
if args.dump_tokens {
dbg!(&tokens);
}
if args.lexer {
return;
}
let mut parser = Parser::new(None);
let ast = match parser.parse(tokens) {
Ok(a) => a,
Err(e) => {
eprintln!("{}", e);
std::process::exit(1);
},
};
if args.json {
match to_string(&ast) {
Ok(json) => println!("{}", json),
Err(e) => {
eprintln!("Failed to generate JSON, error: {}", e);
exit(1);
}
};
} else if args.print {
println!("{:#?}", ast);
}
}