From 83694988c312427e8340fd9dbe2e00085feee991 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 16 Apr 2024 20:40:02 -0500 Subject: [PATCH] cl-ast: Let Ty handle the complexities of VariantKind::Tuple's type list --- cl-ast/src/ast_impl.rs | 2 +- cl-ast/src/lib.rs | 2 +- cl-parser/src/parser.rs | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cl-ast/src/ast_impl.rs b/cl-ast/src/ast_impl.rs index 1d57d58..de679a4 100644 --- a/cl-ast/src/ast_impl.rs +++ b/cl-ast/src/ast_impl.rs @@ -251,7 +251,7 @@ mod display { match self { VariantKind::Plain => Ok(()), VariantKind::CLike(n) => write!(f, " = {n}"), - VariantKind::Tuple(v) => delimit(separate(v, ", "), INLINE_PARENS)(f), + VariantKind::Tuple(v) => v.fmt(f), VariantKind::Struct(v) => delimit(separate(v, ", "), INLINE_BRACES)(f), } } diff --git a/cl-ast/src/lib.rs b/cl-ast/src/lib.rs index 25560ed..ce05dce 100644 --- a/cl-ast/src/lib.rs +++ b/cl-ast/src/lib.rs @@ -197,7 +197,7 @@ pub struct Variant { pub enum VariantKind { Plain, CLike(u128), - Tuple(Vec), + Tuple(Ty), Struct(Vec), } diff --git a/cl-parser/src/parser.rs b/cl-parser/src/parser.rs index 327a47c..0871124 100644 --- a/cl-parser/src/parser.rs +++ b/cl-parser/src/parser.rs @@ -565,11 +565,15 @@ impl<'t> Parser<'t> { /// Parses a [tuple-like](VariantKind::Tuple) [`enum`](Enum) [Variant] pub fn variantkind_tuple(&mut self) -> PResult { const PARSING: Parsing = Parsing::VariantKind; - Ok(VariantKind::Tuple(delim( - sep(Self::ty, Punct::Comma, Punct::RParen, PARSING), - PARENS, - PARSING, - )(self)?)) + let tup = self.ty()?; + if !matches!(tup.kind, TyKind::Tuple(_) | TyKind::Empty) { + Err(self.error( + ErrorKind::ExpectedParsing { want: Parsing::TyTuple }, + PARSING, + ))? + } + + Ok(VariantKind::Tuple(tup)) } pub fn parse_impl(&mut self) -> PResult {