Remove serde dependency

This commit is contained in:
Evan Shaw 2022-09-13 22:24:31 +12:00
parent 447b1be197
commit d803e53a0a
4 changed files with 26 additions and 34 deletions

View File

@ -5,6 +5,3 @@ edition = "2021"
[lib]
doctest = false
[dependencies]
serde = { version = "1.0.139", features = ["derive"] }

View File

@ -2,14 +2,12 @@ use std::cmp::{Eq, PartialEq};
use std::fmt::{Debug, Formatter, Result};
use std::ops::Deref;
use serde::Serialize;
/// A wrapper for Vec<u8> that provides a human-readable Debug impl and
/// a few other conveniences.
///
/// The Trunk lexer and parser work mainly with byte strings because
/// valid PHP code is not required to be valid UTF-8.
#[derive(Clone, Eq, PartialEq, Serialize)]
#[derive(Clone, Eq, PartialEq)]
pub struct ByteString(pub(crate) Vec<u8>);
impl ByteString {

View File

@ -6,8 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.139", features = ["derive"] }
serde_json = "1.0.82"
trunk_lexer = { path = "../trunk_lexer" }
[lib]

View File

@ -1,10 +1,9 @@
use serde::Serialize;
use trunk_lexer::{ByteString, TokenKind};
pub type Block = Vec<Statement>;
pub type Program = Block;
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum Type {
Plain(ByteString),
Nullable(ByteString),
@ -13,7 +12,7 @@ pub enum Type {
Void,
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct Identifier {
pub name: ByteString,
}
@ -38,7 +37,7 @@ impl From<&[u8]> for Identifier {
pub type ParamList = Vec<Param>;
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub struct Param {
pub name: Expression,
pub r#type: Option<Type>,
@ -71,7 +70,7 @@ impl From<&[u8]> for Param {
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum PropertyFlag {
Public,
Protected,
@ -91,7 +90,7 @@ impl From<TokenKind> for PropertyFlag {
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum MethodFlag {
Final,
Abstract,
@ -115,7 +114,7 @@ impl From<TokenKind> for MethodFlag {
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ClassFlag {
Final,
Abstract,
@ -131,20 +130,20 @@ impl From<TokenKind> for ClassFlag {
}
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum UseKind {
Normal,
Function,
Const,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub struct StaticVar {
pub var: Expression,
pub default: Option<Expression>,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub enum IncludeKind {
Include,
IncludeOnce,
@ -164,7 +163,7 @@ impl From<&TokenKind> for IncludeKind {
}
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub enum Statement {
InlineHtml(ByteString),
Static {
@ -307,13 +306,13 @@ pub enum Statement {
Noop,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub struct DeclareItem {
pub key: Identifier,
pub value: Expression,
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum CastKind {
String,
Object,
@ -341,26 +340,26 @@ impl From<&TokenKind> for CastKind {
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BackedEnumType {
String,
Int,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub struct Case {
pub condition: Option<Expression>,
pub body: Block,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub struct Catch {
pub types: Vec<Identifier>,
pub var: Option<Expression>,
pub body: Block,
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ConstFlag {
Final,
Public,
@ -380,13 +379,13 @@ impl From<TokenKind> for ConstFlag {
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Use {
pub name: Identifier,
pub alias: Option<Identifier>,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub enum Expression {
Static,
ErrorSuppress {
@ -516,37 +515,37 @@ pub enum Expression {
},
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub struct Arg {
pub name: Option<ByteString>,
pub value: Expression,
pub unpack: bool,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub struct ClosureUse {
pub var: Expression,
pub by_ref: bool,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Clone)]
pub struct MatchArm {
pub conditions: Option<Vec<Expression>>,
pub body: Expression,
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum MagicConst {
Dir,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub struct ArrayItem {
pub key: Option<Expression>,
pub value: Expression,
}
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum InfixOp {
Add,
Sub,
@ -606,7 +605,7 @@ impl From<TokenKind> for InfixOp {
}
}
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub struct ElseIf {
pub condition: Expression,
pub body: Block,