Deduplicate recipe parsing (#923)

This commit is contained in:
Casey Rodarmor 2021-07-27 22:51:46 -07:00 committed by GitHub
parent ce0376cfdf
commit 9ee1a63e99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));