From 28b285764cd6d9b184584756177199d0f1c32ce3 Mon Sep 17 00:00:00 2001 From: John Clements Date: Tue, 23 Apr 2013 16:47:47 -0700 Subject: comments, helper function for tests, more informative error message --- src/libsyntax/parse/mod.rs | 7 ++++++- src/libsyntax/parse/parser.rs | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 0063c7ea876..9381358e161 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -354,6 +354,7 @@ mod test { use core::option::None; use core::int; use core::num::NumCast; + use core::path::Path; use codemap::{dummy_sp, CodeMap, span, BytePos, spanned}; use opt_vec; use ast; @@ -546,6 +547,10 @@ mod test { } + fn parser_done(p: Parser){ + assert_eq!(*p.token,token::EOF); + } + #[test] fn parse_ident_pat () { let parser = string_to_parser(@~"b"); assert_eq!(parser.parse_pat(false), @@ -560,7 +565,7 @@ mod test { None // no idea ), span: sp(0,1)}); - assert_eq!(*parser.token,token::EOF); + parser_done(parser); } #[test] fn parse_arg () { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 0afef442efc..c843698a1dc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1056,6 +1056,9 @@ pub impl Parser { } } + // matches lifetimes = ( lifetime ) | ( lifetime , lifetimes ) + // actually, it matches the empty one too, but putting that in there + // messes up the grammar.... fn parse_lifetimes(&self) -> OptVec { /*! * @@ -1081,7 +1084,8 @@ pub impl Parser { token::GT => { return res; } token::BINOP(token::SHR) => { return res; } _ => { - self.fatal(~"expected `,` or `>` after lifetime name"); + self.fatal(fmt!("expected `,` or `>` after lifetime name, got: %?", + *self.token)); } } } @@ -2741,6 +2745,11 @@ pub impl Parser { if self.eat_keyword(&~"once") { ast::Once } else { ast::Many } } + // matches optbounds = ( ( : ( boundseq )? )? ) + // where boundseq = ( bound + boundseq ) | bound + // and bound = ( 'static ) | ty + // you might want to insist on the boundseq having seen the colon, but + // that's not currently in place. fn parse_optional_ty_param_bounds(&self) -> @OptVec { if !self.eat(&token::COLON) { return @opt_vec::Empty; @@ -2801,6 +2810,7 @@ pub impl Parser { return @result; } + // matches typaram = IDENT optbounds fn parse_ty_param(&self) -> TyParam { let ident = self.parse_ident(); let bounds = self.parse_optional_ty_param_bounds(); -- cgit 1.4.1-3-g733a5