Enable more indexing expressions.

This commit is contained in:
Stephen Chung
2020-03-05 20:28:03 +08:00
parent c9395049e2
commit 883f08c026
4 changed files with 230 additions and 123 deletions

View File

@@ -132,16 +132,24 @@ impl std::fmt::Display for EvalAltResult {
write!(f, "{}: {} < 0 ({})", desc, index, pos)
}
Self::ErrorArrayBounds(max, _, pos) if *max == 0 => write!(f, "{} ({})", desc, pos),
Self::ErrorArrayBounds(max, index, pos) => {
write!(f, "{} (max {}): {} ({})", desc, max - 1, index, pos)
}
Self::ErrorArrayBounds(max, index, pos) => write!(
f,
"Array index {} is out of bounds: max {} elements ({})",
index,
max - 1,
pos
),
Self::ErrorStringBounds(_, index, pos) if *index < 0 => {
write!(f, "{}: {} < 0 ({})", desc, index, pos)
}
Self::ErrorStringBounds(max, _, pos) if *max == 0 => write!(f, "{} ({})", desc, pos),
Self::ErrorStringBounds(max, index, pos) => {
write!(f, "{} (max {}): {} ({})", desc, max - 1, index, pos)
}
Self::ErrorStringBounds(max, index, pos) => write!(
f,
"String index {} is out of bounds: max {} characters ({})",
index,
max - 1,
pos
),
}
}
}