cl-parser: Rearrange to match cl-ast
Also reorder `Let` in the AST
This commit is contained in:
		| @@ -258,7 +258,6 @@ pub enum TyKind { | |||||||
|     Tuple(TyTuple), |     Tuple(TyTuple), | ||||||
|     Ref(TyRef), |     Ref(TyRef), | ||||||
|     Fn(TyFn), |     Fn(TyFn), | ||||||
|     // TODO: slice, array types |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /// An array of [`T`](Ty) | /// An array of [`T`](Ty) | ||||||
| @@ -334,16 +333,6 @@ pub enum Semi { | |||||||
|     Unterminated, |     Unterminated, | ||||||
| } | } | ||||||
|  |  | ||||||
| /// A local variable declaration [Stmt] |  | ||||||
| #[derive(Clone, Debug, PartialEq, Eq, Hash)] |  | ||||||
| pub struct Let { |  | ||||||
|     pub mutable: Mutability, |  | ||||||
|     pub name: Sym, |  | ||||||
|     pub ty: Option<Box<Ty>>, |  | ||||||
|     pub init: Option<Box<Expr>>, |  | ||||||
|     pub tail: Option<Box<Expr>>, |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /// An expression, the beating heart of the language | /// An expression, the beating heart of the language | ||||||
| #[derive(Clone, Debug, PartialEq, Eq, Hash)] | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||||||
| pub struct Expr { | pub struct Expr { | ||||||
| @@ -406,6 +395,16 @@ pub enum ExprKind { | |||||||
|     Continue, |     Continue, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /// A local variable declaration [Stmt] | ||||||
|  | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||||||
|  | pub struct Let { | ||||||
|  |     pub mutable: Mutability, | ||||||
|  |     pub name: Sym, | ||||||
|  |     pub ty: Option<Box<Ty>>, | ||||||
|  |     pub init: Option<Box<Expr>>, | ||||||
|  |     pub tail: Option<Box<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 { | ||||||
|   | |||||||
| @@ -404,23 +404,6 @@ mod display { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     impl Display for Let { |  | ||||||
|         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |  | ||||||
|             let Self { mutable, name, ty, init, tail } = self; |  | ||||||
|             write!(f, "let {mutable}{name}")?; |  | ||||||
|             if let Some(value) = ty { |  | ||||||
|                 write!(f, ": {value}")?; |  | ||||||
|             } |  | ||||||
|             if let Some(value) = init { |  | ||||||
|                 write!(f, " = {value}")?; |  | ||||||
|             } |  | ||||||
|             if let Some(value) = tail { |  | ||||||
|                 write!(f, ";\n{value}")?; |  | ||||||
|             } |  | ||||||
|             Ok(()) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     impl Display for Expr { |     impl Display for Expr { | ||||||
|         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|             self.kind.fmt(f) |             self.kind.fmt(f) | ||||||
| @@ -458,6 +441,23 @@ mod display { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     impl Display for Let { | ||||||
|  |         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  |             let Self { mutable, name, ty, init, tail } = self; | ||||||
|  |             write!(f, "let {mutable}{name}")?; | ||||||
|  |             if let Some(value) = ty { | ||||||
|  |                 write!(f, ": {value}")?; | ||||||
|  |             } | ||||||
|  |             if let Some(value) = init { | ||||||
|  |                 write!(f, " = {value}")?; | ||||||
|  |             } | ||||||
|  |             if let Some(value) = tail { | ||||||
|  |                 write!(f, ";\n{value}")?; | ||||||
|  |             } | ||||||
|  |             Ok(()) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     impl Display for Assign { |     impl Display for Assign { | ||||||
|         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|             let Self { parts } = self; |             let Self { parts } = self; | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user