refactor: remove old code

This commit is contained in:
Araozu 2024-08-26 16:25:20 -05:00
parent 974c380eaf
commit 6965eda6a7
13 changed files with 56 additions and 105 deletions

View File

@ -1,7 +1,4 @@
use crate::{
codegen::Transpilable,
php_ast::{php_ast_2::PSimpleAssignment, PhpAssignmentExpression},
};
use crate::{codegen::Transpilable, php_ast::PSimpleAssignment};
impl Transpilable for PSimpleAssignment<'_> {
fn transpile(&self) -> String {
@ -14,10 +11,6 @@ impl Transpilable for PSimpleAssignment<'_> {
#[cfg(test)]
mod tests {
use crate::{
codegen::Transpilable,
php_ast::{PhpAssignmentExpression, PhpPrimaryExpression, PhpSimpleAssignment},
};
/*
#[test]

View File

@ -1,4 +1,4 @@
use crate::{codegen::Transpilable, php_ast::php_ast_2::PExpresssion};
use crate::{codegen::Transpilable, php_ast::PExpresssion};
use PExpresssion::*;
mod assignment;

View File

@ -1,7 +1,4 @@
use crate::{
codegen::Transpilable,
php_ast::{php_ast_2::PPrimary, PhpPrimaryExpression},
};
use crate::{codegen::Transpilable, php_ast::PPrimary};
impl Transpilable for PPrimary<'_> {
fn transpile(&self) -> String {
@ -17,7 +14,6 @@ impl Transpilable for PPrimary<'_> {
#[cfg(test)]
mod tests {
use crate::{codegen::Transpilable, php_ast::PhpPrimaryExpression};
/*
#[test]

View File

@ -1,4 +1,4 @@
use crate::{codegen::Transpilable, php_ast::php_ast_2::PFunctionCall};
use crate::{codegen::Transpilable, php_ast::PFunctionCall};
impl Transpilable for PFunctionCall<'_> {
fn transpile(&self) -> String {

View File

@ -1,7 +1,4 @@
use super::Transpilable;
use crate::php_ast::PhpExpression;
mod expression;
mod function;
pub mod statement;
pub mod statement_list;
mod function;

View File

@ -1,7 +1,4 @@
use crate::{
codegen::Transpilable,
php_ast::{php_ast_2::PStatement, PhpStatement},
};
use crate::{codegen::Transpilable, php_ast::PStatement};
impl Transpilable for PStatement<'_> {
fn transpile(&self) -> String {
@ -16,13 +13,6 @@ impl Transpilable for PStatement<'_> {
#[cfg(test)]
mod tests {
use crate::{
codegen::Transpilable,
php_ast::{
PhpAssignmentExpression, PhpExpression, PhpExpressionList, PhpPrimaryExpression,
PhpStatement,
},
};
/*
#[test]

View File

@ -1,7 +1,4 @@
use crate::{
codegen::Transpilable,
php_ast::{php_ast_2::PFile, PhpAst},
};
use crate::{codegen::Transpilable, php_ast::PFile};
impl Transpilable for PFile<'_> {
fn transpile(&self) -> String {
@ -17,13 +14,7 @@ impl Transpilable for PFile<'_> {
#[cfg(test)]
mod tests {
use crate::{
codegen::Transpilable,
php_ast::{
php_ast_2::PFile, PhpAssignmentExpression, PhpAst, PhpExpression, PhpPrimaryExpression,
PhpStatement,
},
};
use crate::{codegen::Transpilable, php_ast::PFile};
#[test]
fn should_transpile_empty_file() {

View File

@ -1,5 +1,3 @@
use crate::codegen::Transpilable;
/// This AST implements a subset of the PHP AST as defined
/// by https://phplang.org/spec/19-grammar.html#syntactic-grammar
///
@ -7,56 +5,59 @@ use crate::codegen::Transpilable;
/// THP
pub mod transformers;
pub mod php_ast_2;
type TranspilableBox<'a> = Box<(dyn Transpilable + 'a)>;
/// Represents `statement-list` on the grammar,
/// and thus a whole PHP source file
pub struct PhpAst<'a> {
pub statements: Vec<TranspilableBox<'a>>,
/// A single PHP source code file
pub struct PFile<'a> {
pub statements: Vec<PStatement<'a>>,
}
/// https://phplang.org/spec/19-grammar.html#grammar-statement
/// A PHP statement
pub enum PStatement<'a> {
ExpressionStatement(PExpressionStatement<'a>),
}
/// A statement composed of a single expression,
/// whose value is discarded
///
/// Not fully implemented
/// ## Examples
///
/// statement:
/// echo-statement
pub enum PhpStatement<'a> {
PhpEchoStatement(PhpExpressionList<'a>),
PhpExpressionStatement(PhpExpression<'a>),
/// ```php
/// 10;
/// "hello";
/// ```
pub type PExpressionStatement<'a> = PExpresssion<'a>;
/// A generic PHP expression
pub enum PExpresssion<'a> {
FunctionCall(PFunctionCall<'a>),
Primary(PPrimary<'a>),
/// This comes from a THP binding
Assignment(PSimpleAssignment<'a>),
}
pub struct PhpExpressionList<'a> {
pub expressions: Vec<PhpExpression<'a>>,
pub struct PSimpleAssignment<'a> {
pub variable: &'a String,
pub assignment: Box<PExpresssion<'a>>,
}
pub enum PhpExpression<'a> {
Assignment(PhpAssignmentExpression<'a>),
/// A function call as an expression
pub struct PFunctionCall<'a> {
/// Arbitrary expressions that compute into
/// a function not supported
pub function_name: &'a String,
pub arguments: Vec<PExpresssion<'a>>,
}
pub enum PhpAssignmentExpression<'a> {
Primary(PhpPrimaryExpression<'a>),
SimpleAssignment(PhpSimpleAssignment<'a>),
}
pub struct PhpSimpleAssignment<'a> {
pub variable: String,
pub assignment: TranspilableBox<'a>,
}
/// https://phplang.org/spec/19-grammar.html#grammar-primary-expression
///
/// primary-expression:
/// literal
/// variable
pub enum PhpPrimaryExpression<'a> {
/// A Primary expression: literals and variables
pub enum PPrimary<'a> {
IntegerLiteral(&'a String),
FloatingLiteral(&'a String),
StringLiteral(&'a String),
/// https://phplang.org/spec/19-grammar.html#grammar-variable
///
/// Supports only variable -> callable-variable -> simple-variable -> variable-name
///
/// This is a $variable
Variable(&'a String),
/// This is a symbol, e.g. a function name
Symbol(&'a String),
}

View File

@ -1,10 +1,5 @@
use super::super::PhpExpression;
use crate::{
codegen::Transpilable,
php_ast::{
php_ast_2::{PExpresssion, PFunctionCall, PPrimary},
PhpAssignmentExpression, PhpPrimaryExpression,
},
php_ast::{PExpresssion, PPrimary},
syntax::ast::Expression,
};
@ -36,9 +31,7 @@ impl<'a> PHPTransformable<'a> for Expression<'_> {
PExpresssion::FunctionCall(fn_call_expr)
}
Expression::Identifier(i) => {
PExpresssion::Primary(PPrimary::Variable(&i.value))
}
Expression::Identifier(i) => PExpresssion::Primary(PPrimary::Variable(&i.value)),
_ => todo!("transformation for expression: {:?}", self),
}
}

View File

@ -1,5 +1,5 @@
use crate::{
php_ast::php_ast_2::PFunctionCall,
php_ast::PFunctionCall,
syntax::ast::{functions::FunctionCall, Expression},
};
@ -11,7 +11,9 @@ impl<'a> PHPTransformable<'a> for FunctionCall<'a> {
fn into_php_ast(&'a self) -> Self::Item {
let function_expr = match *self.function {
Expression::Identifier(i) => &i.value,
_ => panic!("Cannot use an arbitrary expression as a function, only identifiers (for now)"),
_ => panic!(
"Cannot use an arbitrary expression as a function, only identifiers (for now)"
),
};
let expressions: Vec<_> = self

View File

@ -1,9 +1,7 @@
use crate::codegen::Transpilable;
pub mod expression;
pub mod functions;
pub mod module_ast;
pub mod statement;
pub mod functions;
/// Implemented by AST nodes that can be transformed to PHP
pub trait PHPTransformable<'a> {

View File

@ -1,10 +1,5 @@
use super::super::PhpAst;
use crate::codegen::Transpilable;
use crate::php_ast::php_ast_2::{PFile, PStatement};
use crate::php_ast::{
PhpAssignmentExpression, PhpExpression, PhpExpressionList, PhpPrimaryExpression, PhpStatement,
};
use crate::syntax::ast::{Expression, ModuleAST, ModuleMembers};
use crate::php_ast::{PFile, PStatement};
use crate::syntax::ast::{ModuleAST, ModuleMembers};
use super::PHPTransformable;

View File

@ -1,10 +1,5 @@
use super::super::PhpStatement;
use crate::{
codegen::Transpilable,
php_ast::{
php_ast_2::{PExpresssion, PSimpleAssignment, PStatement},
PhpAssignmentExpression, PhpExpression, PhpSimpleAssignment,
},
php_ast::{PExpresssion, PSimpleAssignment, PStatement},
syntax::ast::Statement,
};