Skip to content

Commit

Permalink
start note parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Dec 9, 2023
1 parent ae6bda2 commit 85a914f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
47 changes: 28 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,39 +114,41 @@ where
if parsing && line.is_empty() {
parsing = false;
if let Some(rule) = current_rule.take() {
// Order rule is handled separately
if let RuleKind::Order(_o) = rule {
orders.push(current_order.to_owned());
current_order.clear();
} else {
rules.push(rule);
}
} else {
// todo error
// error and abort
panic!("Parsing error: unknown empty new line");
}
current_order.clear();

continue;
}

// HANDLE RULE START
// start order parsing
let mut r_line = line;
if !parsing {
if line == "[Order]" {
parsing = true;
if r_line.starts_with("[Order") {
current_rule = Some(RuleKind::Order(Order::default()));
continue;
} else if line == "[Note]" {
parsing = true;
r_line = r_line["[Order".len()..].to_owned();
} else if r_line.starts_with("[Note") {
current_rule = Some(RuleKind::Note(Note::default()));
continue;
} else if line == "[Conflict]" {
parsing = true;
r_line = r_line["[Note".len()..].to_owned();
} else if r_line.starts_with("[Conflict") {
current_rule = Some(RuleKind::Conflict(Conflict::default()));
continue;
} else if line == "[Requires]" {
parsing = true;
r_line = r_line["[Conflict".len()..].to_owned();
} else if r_line.starts_with("[Requires") {
current_rule = Some(RuleKind::Requires(Requires::default()));
continue;
r_line = r_line["[Requires".len()..].to_owned();
} else {
// unknown rule
panic!("Parsing error: unknown rule");
}
parsing = true;
}

// HANDLE RULE PARSE
Expand All @@ -156,15 +158,22 @@ where
match current_rule {
RuleKind::Order(_o) => {
// order is just a list of names
current_order.push(line)
// TODO in-line names?
current_order.push(r_line)
}
RuleKind::Note(_n) => {
// parse rule
// first line is the comment
// Syntax: [Note optional-message] expr-1 expr-2 ... expr-N
// TODO alternative:
// [Note]
// message
// A.esp

// subsequent line is archive name
// subsequent lines are archive names

// handle more lines
// parse expressions

todo!()
}
RuleKind::Conflict(_c) => {
todo!()
Expand Down
23 changes: 23 additions & 0 deletions tests/cmop/rules_note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Note]
message
a

[Note message]
a
mod with spaces.archive
c

[Note message] a b c

[Note message] a "mod with spaces.archive" "c"

[Note message]
[ALL A.archive [NOT X.archive]]
[ANY B.archive 7.archive]
[ALL C.archive elephant.archive potato.archive]

[Note]
message
[ALL A.archive [NOT X.archive]]
[ANY B.archive 7.archive]
[ALL C.archive elephant.archive potato.archive]
3 changes: 0 additions & 3 deletions tests/cmop/rules_warnings.txt

This file was deleted.

13 changes: 11 additions & 2 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ mod unit_tests {

#[test]
fn test_parse_rules() {
let rules_path = "./tests/cmop/rules_order.txt";
assert!(parse_rules(rules_path).is_ok(), "rules parsing failed")
assert!(
parse_rules("./tests/cmop/rules_order.txt").is_ok(),
"rules parsing failed"
);

assert!(
parse_rules("./tests/cmop/rules_note.txt").is_ok(),
"rules parsing failed"
);

// TODO add other rules
}

#[test]
Expand Down

0 comments on commit 85a914f

Please sign in to comment.