Ensure interpretations are in a predictable order in conflict messages

This commit is contained in:
Max Brunsfeld 2019-02-08 17:11:44 -08:00
parent a7206b1b8b
commit e579e09569
7 changed files with 17 additions and 19 deletions

View file

@ -443,13 +443,10 @@ impl<'a> ParseTableBuilder<'a> {
.unwrap();
write!(&mut msg, "Possible interpretations:\n\n").unwrap();
let interpretions = conflicting_items
let mut interpretions = conflicting_items
.iter()
.enumerate()
.map(|(i, item)| {
.map(|item| {
let mut line = String::new();
write!(&mut line, " {}:", i + 1).unwrap();
for preceding_symbol in preceding_symbols
.iter()
.take(preceding_symbols.len() - item.step_index as usize)
@ -505,8 +502,9 @@ impl<'a> ParseTableBuilder<'a> {
.map(|i| i.0.chars().count())
.max()
.unwrap();
for (line, prec_suffix) in interpretions {
interpretions.sort_unstable();
for (i, (line, prec_suffix)) in interpretions.into_iter().enumerate() {
write!(&mut msg, " {}:", i + 1).unwrap();
msg += &line;
if let Some(prec_suffix) = prec_suffix {
for _ in line.chars().count()..max_interpretation_length {

View file

@ -4,8 +4,8 @@ Unresolved conflict for symbol sequence:
Possible interpretations:
1: expression '+' (math_operation expression '+' expression)
2: (math_operation expression '+' expression) • '+' …
1: (math_operation expression '+' expression) • '+' …
2: expression '+' (math_operation expression '+' expression)
Possible resolutions:

View file

@ -4,8 +4,8 @@ Unresolved conflict for symbol sequence:
Possible interpretations:
1: '[' (array_type_repeat1 identifier) • identifier …
2: '[' (array_repeat1 identifier) • identifier …
1: '[' (array_repeat1 identifier) • identifier …
2: '[' (array_type_repeat1 identifier) • identifier …
Possible resolutions:

View file

@ -4,8 +4,8 @@ Unresolved conflict for symbol sequence:
Possible interpretations:
1: _program_start '[' (array_type_repeat1 identifier) • identifier …
2: _program_start '[' (array_repeat1 identifier) • identifier …
1: _program_start '[' (array_repeat1 identifier) • identifier …
2: _program_start '[' (array_type_repeat1 identifier) • identifier …
Possible resolutions:

View file

@ -4,9 +4,9 @@ Unresolved conflict for symbol sequence:
Possible interpretations:
1: expression '+' (product expression • '*' expression) (precedence: 1, associativity: Left)
1: (sum expression '+' expression) • '*' … (precedence: 0, associativity: Left)
2: expression '+' (other_thing expression • '*' '*') (precedence: -1, associativity: Left)
3: (sum expression '+' expression) • '*' … (precedence: 0, associativity: Left)
3: expression '+' (product expression • '*' expression) (precedence: 1, associativity: Left)
Possible resolutions:

View file

@ -4,8 +4,8 @@ Unresolved conflict for symbol sequence:
Possible interpretations:
1: (unary_b '!' expression) • '<' … (precedence: 2)
2: (unary_a '!' expression) • '<' … (precedence: 2)
1: (unary_a '!' expression) • '<' … (precedence: 2)
2: (unary_b '!' expression) • '<' … (precedence: 2)
Possible resolutions:

View file

@ -4,8 +4,8 @@ Unresolved conflict for symbol sequence:
Possible interpretations:
1: identifier (function_call identifier • block) (precedence: 0, associativity: Right)
2: identifier (expression identifier) • '{' …
1: identifier (expression identifier) • '{' …
2: identifier (function_call identifier • block) (precedence: 0, associativity: Right)
Possible resolutions: