From 9ee1a63e99f067601815f069490028c50493c342 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 27 Jul 2021 22:51:46 -0700 Subject: [PATCH] Deduplicate recipe parsing (#923) --- src/parser.rs | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 16446ec..74a6486 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -322,35 +322,21 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { break; } else if self.next_is(Identifier) { match Keyword::from_lexeme(next.lexeme()) { - Some(Keyword::Alias) => - if self.next_are(&[Identifier, Identifier, Equals]) { - return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)); - } else if self.next_are(&[Identifier, Identifier, ColonEquals]) { - items.push(Item::Alias(self.parse_alias()?)); - } else { - let doc = pop_doc_comment(&mut items, eol_since_last_comment); - items.push(Item::Recipe(self.parse_recipe(doc, false)?)); - }, - Some(Keyword::Export) => - if self.next_are(&[Identifier, Identifier, Equals]) { - return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)); - } else if self.next_are(&[Identifier, Identifier, ColonEquals]) { - self.presume_keyword(Keyword::Export)?; - items.push(Item::Assignment(self.parse_assignment(true)?)); - } else { - let doc = pop_doc_comment(&mut items, eol_since_last_comment); - items.push(Item::Recipe(self.parse_recipe(doc, false)?)); - }, - Some(Keyword::Set) => + Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, Equals]) => + return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)), + Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, ColonEquals]) => + items.push(Item::Alias(self.parse_alias()?)), + Some(Keyword::Export) if self.next_are(&[Identifier, Identifier, Equals]) => + return Err(self.get(2)?.error(CompileErrorKind::DeprecatedEquals)), + Some(Keyword::Export) if self.next_are(&[Identifier, Identifier, ColonEquals]) => { + self.presume_keyword(Keyword::Export)?; + items.push(Item::Assignment(self.parse_assignment(true)?)); + }, + Some(Keyword::Set) if self.next_are(&[Identifier, Identifier, ColonEquals]) || self.next_are(&[Identifier, Identifier, Eol]) - || self.next_are(&[Identifier, Identifier, Eof]) - { - items.push(Item::Set(self.parse_set()?)); - } else { - let doc = pop_doc_comment(&mut items, eol_since_last_comment); - items.push(Item::Recipe(self.parse_recipe(doc, false)?)); - }, + || self.next_are(&[Identifier, Identifier, Eof]) => + items.push(Item::Set(self.parse_set()?)), _ => if self.next_are(&[Identifier, Equals]) { return Err(self.get(1)?.error(CompileErrorKind::DeprecatedEquals));