Repository: casey/just
File: src/parser.rs (Rust)

Code before:
      return Ok(true);
    }

    let identifier = self.expect(Identifier)?;

    let value = if Keyword::True == identifier.lexeme() {
      true
    } else if Keyword::False == identifier.lexeme() {
      false
    } else {
      return Err(identifier.error(CompileErrorKind::ExpectedKeyword {
        expected: vec![Keyword::True, Keyword::False],
        found: identifier,
      }));
    };

    Ok(value)
  }

  /// Parse a setting
  fn parse_set(&mut self) -> CompileResult<'src, Set<'src>> {
    self.presume_keyword(Keyword::Set)?;
    let name = Name::from_identifier(self.presume(Identifier)?);
    let lexeme = name.lexeme();

    let set_bool: Option<Setting> = if Keyword::AllowDuplicateRecipes == lexeme {
        Some(Setting::AllowDuplicateRecipes(self.parse_set_bool()?))
    } else if Keyword::DotenvLoad == lexeme {
        Some(Setting::DotenvLoad(self.parse_set_bool()?))
    } else if Keyword::Export == lexeme {
        Some(Setting::Export(self.parse_set_bool()?))
    } else if Keyword::IgnoreRecipeComments == lexeme {
        Some(Setting::IgnoreRecipeComments(self.parse_set_bool()?))
    } else if Keyword::PositionalArguments == lexeme {
        Some(Setting::PositionalArguments(self.parse_set_bool()?))
    } else if Keyword::WindowsPowershell == lexeme {
        Some(Setting::WindowsPowerShell(self.parse_set_bool()?))
    } else {
        None
    };

    if let Some(value) = set_bool {
        return Ok(Set {
            value, name
        });
    }

    self.expect(ColonEquals)?;

    if name.lexeme() == Keyword::Shell.lexeme() {
      Ok(Set {

Review comment (refactor):
This is a nice refactor, imo, but I think you could take it one more step if you wanted and turn this into a `match` expression instead of a series of `if/else`.

Just looking around out of curiosity and going to throw my 2 cents in (feel free to take it or leave it).

Code after:

    Ok(lines)
  }

  /// Parse a boolean setting value
  fn parse_set_bool(&mut self) -> CompileResult<'src, bool> {
    if !self.accepted(ColonEquals)? {
      return Ok(true);
    }

    let identifier = self.expect(Identifier)?;

    let value = if Keyword::True == identifier.lexeme() {
      true
    } else if Keyword::False == identifier.lexeme() {
      false
    } else {
      return Err(identifier.error(CompileErrorKind::ExpectedKeyword {
        expected: vec![Keyword::True, Keyword::False],
        found: identifier,
      }));
    };

    Ok(value)
  }

  /// Parse a setting
  fn parse_set(&mut self) -> CompileResult<'src, Set<'src>> {
    self.presume_keyword(Keyword::Set)?;
    let name = Name::from_identifier(self.presume(Identifier)?);
    let lexeme = name.lexeme();

    let set_bool: Option<Setting> = match Keyword::from_lexeme(lexeme) {
      Some(kw) => match kw {
        Keyword::AllowDuplicateRecipes => {
          Some(Setting::AllowDuplicateRecipes(self.parse_set_bool()?))
        }
        Keyword::DotenvLoad => Some(Setting::DotenvLoad(self.parse_set_bool()?)),
        Keyword::IgnoreComments => Some(Setting::IgnoreComments(self.parse_set_bool()?)),
        Keyword::Export => Some(Setting::Export(self.parse_set_bool()?)),
        Keyword::PositionalArguments => Some(Setting::PositionalArguments(self.parse_set_bool()?)),
        Keyword::WindowsPowershell => Some(Setting::WindowsPowerShell(self.parse_set_bool()?)),
        _ => None,
      },
      None => None,
    };

    if let Some(value) = set_bool {
      return Ok(Set { name, value });
    }