From e4f270da1769ca3b768491e04d6dc53b569bc46c Mon Sep 17 00:00:00 2001 From: John Date: Thu, 18 Apr 2024 20:22:08 -0500 Subject: [PATCH] cl-ast: Re-order items for aesthetic reasons --- cl-ast/src/lib.rs | 49 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/cl-ast/src/lib.rs b/cl-ast/src/lib.rs index e74e026..bfa69db 100644 --- a/cl-ast/src/lib.rs +++ b/cl-ast/src/lib.rs @@ -33,6 +33,20 @@ pub enum Visibility { Public, } +// TODO: Capture token? +/// A name +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct Identifier(pub String); + +/// A [Literal]: 0x42, 1e123, 2.4, "Hello" +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub enum Literal { + Bool(bool), + Char(char), + Int(u128), + String(String), +} + /// A list of [Item]s #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct File { @@ -271,11 +285,6 @@ pub enum PathPart { Ident(Identifier), } -// TODO: Capture token? -/// A name -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct Identifier(pub String); - /// An abstract statement, and associated metadata #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Stmt { @@ -284,13 +293,6 @@ pub struct Stmt { pub semi: Semi, } -/// Whether or not a [Stmt] is followed by a semicolon -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum Semi { - Terminated, - Unterminated, -} - /// Whether the [Stmt] is a [Let], [Item], or [Expr] statement #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum StmtKind { @@ -300,6 +302,13 @@ pub enum StmtKind { Expr(Box), } +/// Whether or not a [Stmt] is followed by a semicolon +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub enum Semi { + Terminated, + Unterminated, +} + /// A local variable declaration [Stmt] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Let { @@ -317,8 +326,11 @@ pub struct Expr { } /// Any of the different [Expr]essions -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)] pub enum ExprKind { + /// An empty expression: `(` `)` + #[default] + Empty, /// An [Assign]ment expression: [`Expr`] ([`AssignKind`] [`Expr`])\+ Assign(Assign), /// A [Binary] expression: [`Expr`] ([`BinaryKind`] [`Expr`])\+ @@ -340,8 +352,6 @@ pub enum ExprKind { AddrOf(AddrOf), /// A [Block] expression: `{` [`Stmt`]\* [`Expr`]? `}` Block(Block), - /// An empty expression: `(` `)` - Empty, /// A [Grouping](Group) expression `(` [`Expr`] `)` Group(Group), /// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)` @@ -445,15 +455,6 @@ pub struct Index { pub indices: Vec, } -/// A [Literal]: 0x42, 1e123, 2.4, "Hello" -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum Literal { - Bool(bool), - Char(char), - Int(u128), - String(String), -} - /// An [Array] literal: `[` [`Expr`] (`,` [`Expr`])\* `]` #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Array {