Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhibas committed Feb 23, 2024
1 parent dc66d97 commit 01a527b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Flagfile.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FF-feature-flat-on-off -> true
// you can return non-boolean in this example json. or empty json object json({})
FF-feature-json-variant -> json({"success": true})

// features are forced to start with FF- case-sensitive as it allows you later to find all flags through in codebase
// features are forced to start with FF- case-sensitive as
// it allows you later to find all flags through in codebase
FF-feature-name-specifics -> false

// you can have feature with multiple rules in it with default flag value returned in end
Expand Down
7 changes: 6 additions & 1 deletion src/parse_flagfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ use crate::{
parse::{parse, parse_boolean, ws},
};

// Dependency
// Flagfile -> Vec<Feature> -> Feature -> Vec<Rule> -> Rule -> Expr -> Return

#[derive(Debug, Clone)]
pub enum FlagReturn {
OnOff(bool),
Expand All @@ -30,7 +33,7 @@ pub enum Rule {

pub type FlagValue<'a> = HashMap<&'a str, Vec<Rule>>;

// Parses and throws away: // comment EOL
/// Parses and throws away: // comment EOL
fn parse_comment(i: &str) -> IResult<&str, ()> {
value((), pair(ws(tag("//")), is_not("\n\r")))(i)
}
Expand Down Expand Up @@ -75,9 +78,11 @@ fn parse_rule_expr(i: &str) -> IResult<&str, Rule> {
let parser = tuple((parse, ws(tag(":")), parse_return_val));
map(parser, |(e, _, v)| Rule::BoolExpressionValue(e, v))(i)
}

fn parse_rule_static(i: &str) -> IResult<&str, Rule> {
map(parse_return_val, |v| Rule::Value(v))(i)
}

fn parse_rules(i: &str) -> IResult<&str, Rule> {
alt((parse_rule_expr, parse_rule_static))(i)
}
Expand Down

0 comments on commit 01a527b

Please sign in to comment.