Skip to content

Commit

Permalink
Deduplicate recipe parsing (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jul 28, 2021
1 parent ce0376c commit 9ee1a63
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 9ee1a63

Please sign in to comment.