Simply BLT grammar specification
This commit is contained in:
parent
4312bf89f6
commit
efbcfd7f6c
@ -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");
|
||||||
|
@ -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 }
|
||||||
|
Loading…
Reference in New Issue
Block a user