cl-ast: Rearrange
This commit is contained in:
parent
6108d66b0a
commit
c5e817f1e5
@ -325,12 +325,26 @@ pub enum ExprKind {
|
|||||||
/// An empty expression: `(` `)`
|
/// An empty expression: `(` `)`
|
||||||
#[default]
|
#[default]
|
||||||
Empty,
|
Empty,
|
||||||
|
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
||||||
|
Tuple(Tuple),
|
||||||
|
/// A [Struct creation](Structor) expression: [Path] `{` ([Fielder] `,`)* [Fielder]? `}`
|
||||||
|
Structor(Structor),
|
||||||
|
/// An [Array] literal: `[` [`Expr`] (`,` [`Expr`])\* `]`
|
||||||
|
Array(Array),
|
||||||
|
/// An Array literal constructed with [repeat syntax](ArrayRep)
|
||||||
|
/// `[` [Expr] `;` [Literal] `]`
|
||||||
|
ArrayRep(ArrayRep),
|
||||||
|
/// An address-of expression: `&` `mut`? [`Expr`]
|
||||||
|
AddrOf(AddrOf),
|
||||||
/// A backtick-quoted expression
|
/// A backtick-quoted expression
|
||||||
Quote(Quote),
|
Quote(Quote),
|
||||||
/// A local bind instruction, `let` [`Sym`] `=` [`Expr`]
|
/// A [Literal]: 0x42, 1e123, 2.4, "Hello"
|
||||||
Let(Let),
|
Literal(Literal),
|
||||||
/// A [Match] expression: `match` [Expr] `{` ([MatchArm] `,`)* [MatchArm]? `}`
|
/// A [Grouping](Group) expression `(` [`Expr`] `)`
|
||||||
Match(Match),
|
Group(Group),
|
||||||
|
/// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}`
|
||||||
|
Block(Block),
|
||||||
|
|
||||||
/// An [Assign]ment expression: [`Expr`] (`=` [`Expr`])\+
|
/// An [Assign]ment expression: [`Expr`] (`=` [`Expr`])\+
|
||||||
Assign(Assign),
|
Assign(Assign),
|
||||||
/// A [Modify]-assignment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
|
/// A [Modify]-assignment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
|
||||||
@ -339,31 +353,18 @@ pub enum ExprKind {
|
|||||||
Binary(Binary),
|
Binary(Binary),
|
||||||
/// A [Unary] expression: [`UnaryKind`]\* [`Expr`]
|
/// A [Unary] expression: [`UnaryKind`]\* [`Expr`]
|
||||||
Unary(Unary),
|
Unary(Unary),
|
||||||
/// A [Cast] expression: [`Expr`] `as` [`Ty`]
|
|
||||||
Cast(Cast),
|
|
||||||
/// A [Member] access expression: [`Expr`] [`MemberKind`]\*
|
/// A [Member] access expression: [`Expr`] [`MemberKind`]\*
|
||||||
Member(Member),
|
Member(Member),
|
||||||
/// An Array [Index] expression: a[10, 20, 30]
|
/// An Array [Index] expression: a[10, 20, 30]
|
||||||
Index(Index),
|
Index(Index),
|
||||||
/// A [Struct creation](Structor) expression: [Path] `{` ([Fielder] `,`)* [Fielder]? `}`
|
/// A [Cast] expression: [`Expr`] `as` [`Ty`]
|
||||||
Structor(Structor),
|
Cast(Cast),
|
||||||
/// A [path expression](Path): `::`? [PathPart] (`::` [PathPart])*
|
/// A [path expression](Path): `::`? [PathPart] (`::` [PathPart])*
|
||||||
Path(Path),
|
Path(Path),
|
||||||
/// A [Literal]: 0x42, 1e123, 2.4, "Hello"
|
/// A local bind instruction, `let` [`Sym`] `=` [`Expr`]
|
||||||
Literal(Literal),
|
Let(Let),
|
||||||
/// An [Array] literal: `[` [`Expr`] (`,` [`Expr`])\* `]`
|
/// A [Match] expression: `match` [Expr] `{` ([MatchArm] `,`)* [MatchArm]? `}`
|
||||||
Array(Array),
|
Match(Match),
|
||||||
/// An Array literal constructed with [repeat syntax](ArrayRep)
|
|
||||||
/// `[` [Expr] `;` [Literal] `]`
|
|
||||||
ArrayRep(ArrayRep),
|
|
||||||
/// An address-of expression: `&` `mut`? [`Expr`]
|
|
||||||
AddrOf(AddrOf),
|
|
||||||
/// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}`
|
|
||||||
Block(Block),
|
|
||||||
/// A [Grouping](Group) expression `(` [`Expr`] `)`
|
|
||||||
Group(Group),
|
|
||||||
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
|
||||||
Tuple(Tuple),
|
|
||||||
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
||||||
While(While),
|
While(While),
|
||||||
/// An [If] expression: `if` [`Expr`] [`Block`] [`Else`]?
|
/// An [If] expression: `if` [`Expr`] [`Block`] [`Else`]?
|
||||||
@ -378,47 +379,82 @@ pub enum ExprKind {
|
|||||||
Continue,
|
Continue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Tuple {
|
||||||
|
pub exprs: Vec<Expr>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A [Struct creation](Structor) expression: [Path] `{` ([Fielder] `,`)* [Fielder]? `}`
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Structor {
|
||||||
|
pub to: Path,
|
||||||
|
pub init: Vec<Fielder>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A [Struct field initializer] expression: [Sym] (`=` [Expr])?
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Fielder {
|
||||||
|
pub name: Sym,
|
||||||
|
pub init: Option<Box<Expr>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An [Array] literal: `[` [`Expr`] (`,` [`Expr`])\* `]`
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Array {
|
||||||
|
pub values: Vec<Expr>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An Array literal constructed with [repeat syntax](ArrayRep)
|
||||||
|
/// `[` [Expr] `;` [Literal] `]`
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct ArrayRep {
|
||||||
|
pub value: Box<Expr>,
|
||||||
|
pub repeat: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An address-of expression: `&` `mut`? [`Expr`]
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct AddrOf {
|
||||||
|
pub mutable: Mutability,
|
||||||
|
pub expr: Box<Expr>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A cast expression: [`Expr`] `as` [`Ty`]
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Cast {
|
||||||
|
pub head: Box<Expr>,
|
||||||
|
pub ty: Ty,
|
||||||
|
}
|
||||||
|
|
||||||
/// A backtick-quoted subexpression-literal
|
/// A backtick-quoted subexpression-literal
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Quote {
|
pub struct Quote {
|
||||||
pub quote: Box<Expr>,
|
pub quote: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A local variable declaration [Stmt]
|
/// A [Literal]: 0x42, 1e123, 2.4, "Hello"
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Let {
|
pub enum Literal {
|
||||||
pub mutable: Mutability,
|
Bool(bool),
|
||||||
pub name: Pattern,
|
Char(char),
|
||||||
pub ty: Option<Box<Ty>>,
|
Int(u128),
|
||||||
pub init: Option<Box<Expr>>,
|
Float(u64),
|
||||||
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [Pattern] meta-expression (any [`ExprKind`] that fits pattern rules)
|
/// A [Grouping](Group) expression `(` [`Expr`] `)`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum Pattern {
|
pub struct Group {
|
||||||
Name(Sym),
|
pub expr: Box<Expr>,
|
||||||
Literal(Literal),
|
|
||||||
Rest(Option<Box<Pattern>>),
|
|
||||||
Ref(Mutability, Box<Pattern>),
|
|
||||||
RangeExc(Box<Pattern>, Box<Pattern>),
|
|
||||||
RangeInc(Box<Pattern>, Box<Pattern>),
|
|
||||||
Tuple(Vec<Pattern>),
|
|
||||||
Array(Vec<Pattern>),
|
|
||||||
Struct(Path, Vec<(Sym, Option<Pattern>)>),
|
|
||||||
TupleStruct(Path, Vec<Pattern>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A `match` expression: `match` `{` ([MatchArm] `,`)* [MatchArm]? `}`
|
/// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Match {
|
pub struct Block {
|
||||||
pub scrutinee: Box<Expr>,
|
pub stmts: Vec<Stmt>,
|
||||||
pub arms: Vec<MatchArm>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A single arm of a [Match] expression: [`Pattern`] `=>` [`Expr`]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct MatchArm(pub Pattern, pub Expr);
|
|
||||||
|
|
||||||
/// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
|
/// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Assign {
|
pub struct Assign {
|
||||||
@ -503,13 +539,6 @@ pub enum UnaryKind {
|
|||||||
Tilde,
|
Tilde,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A cast expression: [`Expr`] `as` [`Ty`]
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Cast {
|
|
||||||
pub head: Box<Expr>,
|
|
||||||
pub ty: Ty,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A [Member] access expression: [`Expr`] [`MemberKind`]\*
|
/// A [Member] access expression: [`Expr`] [`MemberKind`]\*
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Member {
|
pub struct Member {
|
||||||
@ -532,67 +561,39 @@ pub struct Index {
|
|||||||
pub indices: Vec<Expr>,
|
pub indices: Vec<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [Literal]: 0x42, 1e123, 2.4, "Hello"
|
/// A local variable declaration [Stmt]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum Literal {
|
pub struct Let {
|
||||||
Bool(bool),
|
pub mutable: Mutability,
|
||||||
Char(char),
|
pub name: Pattern,
|
||||||
Int(u128),
|
pub ty: Option<Box<Ty>>,
|
||||||
Float(u64),
|
|
||||||
String(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A [Struct creation](Structor) expression: [Path] `{` ([Fielder] `,`)* [Fielder]? `}`
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Structor {
|
|
||||||
pub to: Path,
|
|
||||||
pub init: Vec<Fielder>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A [Struct field initializer] expression: [Sym] (`=` [Expr])?
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Fielder {
|
|
||||||
pub name: Sym,
|
|
||||||
pub init: Option<Box<Expr>>,
|
pub init: Option<Box<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An [Array] literal: `[` [`Expr`] (`,` [`Expr`])\* `]`
|
/// A `match` expression: `match` `{` ([MatchArm] `,`)* [MatchArm]? `}`
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Array {
|
pub struct Match {
|
||||||
pub values: Vec<Expr>,
|
pub scrutinee: Box<Expr>,
|
||||||
|
pub arms: Vec<MatchArm>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An Array literal constructed with [repeat syntax](ArrayRep)
|
/// A single arm of a [Match] expression: [`Pattern`] `=>` [`Expr`]
|
||||||
/// `[` [Expr] `;` [Literal] `]`
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct ArrayRep {
|
pub struct MatchArm(pub Pattern, pub Expr);
|
||||||
pub value: Box<Expr>,
|
|
||||||
pub repeat: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An address-of expression: `&` `mut`? [`Expr`]
|
/// A [Pattern] meta-expression (any [`ExprKind`] that fits pattern rules)
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct AddrOf {
|
pub enum Pattern {
|
||||||
pub mutable: Mutability,
|
Name(Sym),
|
||||||
pub expr: Box<Expr>,
|
Literal(Literal),
|
||||||
}
|
Rest(Option<Box<Pattern>>),
|
||||||
|
Ref(Mutability, Box<Pattern>),
|
||||||
/// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}`
|
RangeExc(Box<Pattern>, Box<Pattern>),
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
RangeInc(Box<Pattern>, Box<Pattern>),
|
||||||
pub struct Block {
|
Tuple(Vec<Pattern>),
|
||||||
pub stmts: Vec<Stmt>,
|
Array(Vec<Pattern>),
|
||||||
}
|
Struct(Path, Vec<(Sym, Option<Pattern>)>),
|
||||||
|
TupleStruct(Path, Vec<Pattern>),
|
||||||
/// A [Grouping](Group) expression `(` [`Expr`] `)`
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Group {
|
|
||||||
pub expr: Box<Expr>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Tuple {
|
|
||||||
pub exprs: Vec<Expr>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user