mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
Remove serde dependency
This commit is contained in:
parent
447b1be197
commit
d803e53a0a
@ -5,6 +5,3 @@ edition = "2021"
|
|||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
serde = { version = "1.0.139", features = ["derive"] }
|
|
||||||
|
@ -2,14 +2,12 @@ use std::cmp::{Eq, PartialEq};
|
|||||||
use std::fmt::{Debug, Formatter, Result};
|
use std::fmt::{Debug, Formatter, Result};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
/// A wrapper for Vec<u8> that provides a human-readable Debug impl and
|
/// A wrapper for Vec<u8> that provides a human-readable Debug impl and
|
||||||
/// a few other conveniences.
|
/// a few other conveniences.
|
||||||
///
|
///
|
||||||
/// The Trunk lexer and parser work mainly with byte strings because
|
/// The Trunk lexer and parser work mainly with byte strings because
|
||||||
/// valid PHP code is not required to be valid UTF-8.
|
/// 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>);
|
pub struct ByteString(pub(crate) Vec<u8>);
|
||||||
|
|
||||||
impl ByteString {
|
impl ByteString {
|
||||||
|
@ -6,8 +6,6 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.139", features = ["derive"] }
|
|
||||||
serde_json = "1.0.82"
|
|
||||||
trunk_lexer = { path = "../trunk_lexer" }
|
trunk_lexer = { path = "../trunk_lexer" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use serde::Serialize;
|
|
||||||
use trunk_lexer::{ByteString, TokenKind};
|
use trunk_lexer::{ByteString, TokenKind};
|
||||||
|
|
||||||
pub type Block = Vec<Statement>;
|
pub type Block = Vec<Statement>;
|
||||||
pub type Program = Block;
|
pub type Program = Block;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
Plain(ByteString),
|
Plain(ByteString),
|
||||||
Nullable(ByteString),
|
Nullable(ByteString),
|
||||||
@ -13,7 +12,7 @@ pub enum Type {
|
|||||||
Void,
|
Void,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub struct Identifier {
|
pub struct Identifier {
|
||||||
pub name: ByteString,
|
pub name: ByteString,
|
||||||
}
|
}
|
||||||
@ -38,7 +37,7 @@ impl From<&[u8]> for Identifier {
|
|||||||
|
|
||||||
pub type ParamList = Vec<Param>;
|
pub type ParamList = Vec<Param>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Param {
|
pub struct Param {
|
||||||
pub name: Expression,
|
pub name: Expression,
|
||||||
pub r#type: Option<Type>,
|
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 {
|
pub enum PropertyFlag {
|
||||||
Public,
|
Public,
|
||||||
Protected,
|
Protected,
|
||||||
@ -91,7 +90,7 @@ impl From<TokenKind> for PropertyFlag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum MethodFlag {
|
pub enum MethodFlag {
|
||||||
Final,
|
Final,
|
||||||
Abstract,
|
Abstract,
|
||||||
@ -115,7 +114,7 @@ impl From<TokenKind> for MethodFlag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum ClassFlag {
|
pub enum ClassFlag {
|
||||||
Final,
|
Final,
|
||||||
Abstract,
|
Abstract,
|
||||||
@ -131,20 +130,20 @@ impl From<TokenKind> for ClassFlag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum UseKind {
|
pub enum UseKind {
|
||||||
Normal,
|
Normal,
|
||||||
Function,
|
Function,
|
||||||
Const,
|
Const,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct StaticVar {
|
pub struct StaticVar {
|
||||||
pub var: Expression,
|
pub var: Expression,
|
||||||
pub default: Option<Expression>,
|
pub default: Option<Expression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum IncludeKind {
|
pub enum IncludeKind {
|
||||||
Include,
|
Include,
|
||||||
IncludeOnce,
|
IncludeOnce,
|
||||||
@ -164,7 +163,7 @@ impl From<&TokenKind> for IncludeKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Statement {
|
pub enum Statement {
|
||||||
InlineHtml(ByteString),
|
InlineHtml(ByteString),
|
||||||
Static {
|
Static {
|
||||||
@ -307,13 +306,13 @@ pub enum Statement {
|
|||||||
Noop,
|
Noop,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct DeclareItem {
|
pub struct DeclareItem {
|
||||||
pub key: Identifier,
|
pub key: Identifier,
|
||||||
pub value: Expression,
|
pub value: Expression,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum CastKind {
|
pub enum CastKind {
|
||||||
String,
|
String,
|
||||||
Object,
|
Object,
|
||||||
@ -341,26 +340,26 @@ impl From<&TokenKind> for CastKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum BackedEnumType {
|
pub enum BackedEnumType {
|
||||||
String,
|
String,
|
||||||
Int,
|
Int,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Case {
|
pub struct Case {
|
||||||
pub condition: Option<Expression>,
|
pub condition: Option<Expression>,
|
||||||
pub body: Block,
|
pub body: Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Catch {
|
pub struct Catch {
|
||||||
pub types: Vec<Identifier>,
|
pub types: Vec<Identifier>,
|
||||||
pub var: Option<Expression>,
|
pub var: Option<Expression>,
|
||||||
pub body: Block,
|
pub body: Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum ConstFlag {
|
pub enum ConstFlag {
|
||||||
Final,
|
Final,
|
||||||
Public,
|
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 struct Use {
|
||||||
pub name: Identifier,
|
pub name: Identifier,
|
||||||
pub alias: Option<Identifier>,
|
pub alias: Option<Identifier>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Expression {
|
pub enum Expression {
|
||||||
Static,
|
Static,
|
||||||
ErrorSuppress {
|
ErrorSuppress {
|
||||||
@ -516,37 +515,37 @@ pub enum Expression {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Arg {
|
pub struct Arg {
|
||||||
pub name: Option<ByteString>,
|
pub name: Option<ByteString>,
|
||||||
pub value: Expression,
|
pub value: Expression,
|
||||||
pub unpack: bool,
|
pub unpack: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct ClosureUse {
|
pub struct ClosureUse {
|
||||||
pub var: Expression,
|
pub var: Expression,
|
||||||
pub by_ref: bool,
|
pub by_ref: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct MatchArm {
|
pub struct MatchArm {
|
||||||
pub conditions: Option<Vec<Expression>>,
|
pub conditions: Option<Vec<Expression>>,
|
||||||
pub body: Expression,
|
pub body: Expression,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum MagicConst {
|
pub enum MagicConst {
|
||||||
Dir,
|
Dir,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ArrayItem {
|
pub struct ArrayItem {
|
||||||
pub key: Option<Expression>,
|
pub key: Option<Expression>,
|
||||||
pub value: Expression,
|
pub value: Expression,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Serialize)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum InfixOp {
|
pub enum InfixOp {
|
||||||
Add,
|
Add,
|
||||||
Sub,
|
Sub,
|
||||||
@ -606,7 +605,7 @@ impl From<TokenKind> for InfixOp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ElseIf {
|
pub struct ElseIf {
|
||||||
pub condition: Expression,
|
pub condition: Expression,
|
||||||
pub body: Block,
|
pub body: Block,
|
||||||
|
Loading…
Reference in New Issue
Block a user