Clarify which errors are format string errors

There were a few ambiguous error messages which look like they could have
cropped up from either the rust compiler for the format string parser. To
differentiate, the prefix 'invalid format string' is now added in front of all
format string errors.

cc #9970
This commit is contained in:
Alex Crichton 2013-11-05 17:59:40 -08:00
parent 7fb583be7b
commit 2fc337a7d6

View File

@ -180,7 +180,7 @@ fn next(&mut self) -> Option<Piece<'self>> {
} }
Some((_, '}')) if self.depth == 0 => { Some((_, '}')) if self.depth == 0 => {
self.cur.next(); self.cur.next();
self.err(~"unmatched `}` found"); self.err("unmatched `}` found");
None None
} }
Some((_, '}')) | None => { None } Some((_, '}')) | None => { None }
@ -204,8 +204,8 @@ pub fn new<'a>(s: &'a str) -> Parser<'a> {
/// Notifies of an error. The message doesn't actually need to be of type /// Notifies of an error. The message doesn't actually need to be of type
/// ~str, but I think it does when this eventually uses conditions so it /// ~str, but I think it does when this eventually uses conditions so it
/// might as well start using it now. /// might as well start using it now.
fn err(&self, msg: ~str) { fn err(&self, msg: &str) {
parse_error::cond.raise(msg); parse_error::cond.raise("invalid format string: " + msg);
} }
/// Optionally consumes the specified character. If the character is not at /// Optionally consumes the specified character. If the character is not at
@ -230,11 +230,11 @@ fn must_consume(&mut self, c: char) {
self.cur.next(); self.cur.next();
} }
Some((_, other)) => { Some((_, other)) => {
parse_error::cond.raise( self.err(
format!("expected `{}` but found `{}`", c, other)); format!("expected `{}` but found `{}`", c, other));
} }
None => { None => {
parse_error::cond.raise( self.err(
format!("expected `{}` but string was terminated", c)); format!("expected `{}` but string was terminated", c));
} }
} }
@ -267,7 +267,7 @@ fn escape(&mut self) -> char {
c c
} }
None => { None => {
self.err(~"expected an escape sequence, but format string was \ self.err("expected an escape sequence, but format string was \
terminated"); terminated");
' ' ' '
} }
@ -411,7 +411,7 @@ fn method(&mut self) -> Option<~Method<'self>> {
Some(self.plural()) Some(self.plural())
} }
"" => { "" => {
self.err(~"expected method after comma"); self.err("expected method after comma");
return None; return None;
} }
method => { method => {
@ -430,7 +430,7 @@ fn select(&mut self) -> ~Method<'self> {
self.ws(); self.ws();
let selector = self.word(); let selector = self.word();
if selector == "" { if selector == "" {
self.err(~"cannot have an empty selector"); self.err("cannot have an empty selector");
break break
} }
self.must_consume('{'); self.must_consume('{');
@ -440,7 +440,7 @@ fn select(&mut self) -> ~Method<'self> {
self.must_consume('}'); self.must_consume('}');
if selector == "other" { if selector == "other" {
if !other.is_none() { if !other.is_none() {
self.err(~"multiple `other` statements in `select"); self.err("multiple `other` statements in `select");
} }
other = Some(pieces); other = Some(pieces);
} else { } else {
@ -456,7 +456,7 @@ fn select(&mut self) -> ~Method<'self> {
let other = match other { let other = match other {
Some(arm) => { arm } Some(arm) => { arm }
None => { None => {
self.err(~"`select` statement must provide an `other` case"); self.err("`select` statement must provide an `other` case");
~[] ~[]
} }
}; };
@ -488,7 +488,7 @@ fn plural(&mut self) -> ~Method<'self> {
match self.integer() { match self.integer() {
Some(i) => { offset = Some(i); } Some(i) => { offset = Some(i); }
None => { None => {
self.err(~"offset must be an integer"); self.err("offset must be an integer");
} }
} }
} }
@ -506,7 +506,7 @@ fn plural(&mut self) -> ~Method<'self> {
match self.integer() { match self.integer() {
Some(i) => Right(i), Some(i) => Right(i),
None => { None => {
self.err(~"plural `=` selectors must be followed by an \ self.err("plural `=` selectors must be followed by an \
integer"); integer");
Right(0) Right(0)
} }
@ -538,7 +538,7 @@ fn plural(&mut self) -> ~Method<'self> {
self.must_consume('}'); self.must_consume('}');
if isother { if isother {
if !other.is_none() { if !other.is_none() {
self.err(~"multiple `other` statements in `select"); self.err("multiple `other` statements in `select");
} }
other = Some(pieces); other = Some(pieces);
} else { } else {
@ -554,7 +554,7 @@ fn plural(&mut self) -> ~Method<'self> {
let other = match other { let other = match other {
Some(arm) => { arm } Some(arm) => { arm }
None => { None => {
self.err(~"`plural` statement must provide an `other` case"); self.err("`plural` statement must provide an `other` case");
~[] ~[]
} }
}; };