From efbcfd7f6c50c89083e5037b38ef6638208ba984 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Fri, 23 Jul 2021 17:07:03 +1000 Subject: [PATCH] Simply BLT grammar specification --- src/election.rs | 6 +----- src/parser/blt.pest | 6 ++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/election.rs b/src/election.rs index d7e4d22..20d67c8 100644 --- a/src/election.rs +++ b/src/election.rs @@ -80,8 +80,7 @@ impl Election { preferences: Vec::new(), }; - let ballot_preferences = ballot_pairs.next().unwrap().into_inner(); - for preference in ballot_preferences { + for preference in ballot_pairs { let preference: usize = preference.as_str().parse().unwrap(); ballot.preferences.push(preference - 1); } @@ -89,9 +88,6 @@ impl Election { election.ballots.push(ballot); } - // Zero line - main.next(); - // Read candidates for _ in 0..num_candidates { let string = main.next().expect("Expected candidate name"); diff --git a/src/parser/blt.pest b/src/parser/blt.pest index 0446d8c..468f9d4 100644 --- a/src/parser/blt.pest +++ b/src/parser/blt.pest @@ -3,7 +3,7 @@ main = { ~ header ~ NEWLINE* ~ withdrawn ~ NEWLINE* ~ ballot_list - ~ zero ~ NEWLINE* + ~ "0" ~ NEWLINE* ~ (string ~ NEWLINE*)+ ~ EOI } @@ -19,11 +19,9 @@ withdrawn_cand = @{ "-" ~ integer } ballot_list = { (ballot ~ NEWLINE*)* } ballot = { - number ~ ballot_preferences ~ (zero ~ NEWLINE? | NEWLINE) + number ~ integer* ~ ("0" ~ NEWLINE? | NEWLINE) } -ballot_preferences = { integer* } -zero = { "0" } integer = @{ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } decimal = @{ "0." ~ ASCII_DIGIT+ | integer ~ "." ~ ASCII_DIGIT+ } number = { decimal | integer }