Simply BLT grammar specification

This commit is contained in:
RunasSudo 2021-07-23 17:07:03 +10:00
parent 4312bf89f6
commit efbcfd7f6c
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 3 additions and 9 deletions

View File

@ -80,8 +80,7 @@ impl<N: Number> Election<N> {
preferences: Vec::new(), preferences: Vec::new(),
}; };
let ballot_preferences = ballot_pairs.next().unwrap().into_inner(); for preference in ballot_pairs {
for preference in ballot_preferences {
let preference: usize = preference.as_str().parse().unwrap(); let preference: usize = preference.as_str().parse().unwrap();
ballot.preferences.push(preference - 1); ballot.preferences.push(preference - 1);
} }
@ -89,9 +88,6 @@ impl<N: Number> Election<N> {
election.ballots.push(ballot); election.ballots.push(ballot);
} }
// Zero line
main.next();
// Read candidates // Read candidates
for _ in 0..num_candidates { for _ in 0..num_candidates {
let string = main.next().expect("Expected candidate name"); let string = main.next().expect("Expected candidate name");

View File

@ -3,7 +3,7 @@ main = {
~ header ~ NEWLINE* ~ header ~ NEWLINE*
~ withdrawn ~ NEWLINE* ~ withdrawn ~ NEWLINE*
~ ballot_list ~ ballot_list
~ zero ~ NEWLINE* ~ "0" ~ NEWLINE*
~ (string ~ NEWLINE*)+ ~ (string ~ NEWLINE*)+
~ EOI ~ EOI
} }
@ -19,11 +19,9 @@ withdrawn_cand = @{ "-" ~ integer }
ballot_list = { (ballot ~ NEWLINE*)* } ballot_list = { (ballot ~ NEWLINE*)* }
ballot = { ballot = {
number ~ ballot_preferences ~ (zero ~ NEWLINE? | NEWLINE) number ~ integer* ~ ("0" ~ NEWLINE? | NEWLINE)
} }
ballot_preferences = { integer* }
zero = { "0" }
integer = @{ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } integer = @{ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* }
decimal = @{ "0." ~ ASCII_DIGIT+ | integer ~ "." ~ ASCII_DIGIT+ } decimal = @{ "0." ~ ASCII_DIGIT+ | integer ~ "." ~ ASCII_DIGIT+ }
number = { decimal | integer } number = { decimal | integer }