From 17585cc47ec7c4ffc9d14f33473c4238b6680e88 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 15 Jan 2012 16:25:31 -0800 Subject: [PATCH] rustc: Extract comman parts of view parsing --- src/comp/syntax/parse/parser.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 30f2ab6d371..b52b02a3323 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1630,8 +1630,8 @@ fn parse_block_no_value(p: parser) -> ast::blk { // necessary, and this should take a qualifier. // some blocks start with "#{"... fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk { - let view_items = [], stmts = [], expr = none; - while is_word(p, "import") { view_items += [parse_view_item(p)]; } + let stmts = [], expr = none; + let view_items = parse_view_import_only(p); while p.token != token::RBRACE { alt p.token { token::SEMI. { @@ -2378,15 +2378,21 @@ fn is_view_item(p: parser) -> bool { } fn parse_view(p: parser) -> [@ast::view_item] { - let items: [@ast::view_item] = []; - while is_view_item(p) { items += [parse_view_item(p)]; } + parse_view_while(p, is_view_item) +} + +fn parse_view_import_only(p: parser) -> [@ast::view_item] { + parse_view_while(p, bind is_word(_, "import")) +} + +fn parse_view_while(p: parser, f: fn@(parser) -> bool) -> [@ast::view_item] { + let items = []; + while f(p) { items += [parse_view_item(p)]; } ret items; } fn parse_native_view(p: parser) -> [@ast::view_item] { - let items: [@ast::view_item] = []; - while is_view_item(p) { items += [parse_view_item(p)]; } - ret items; + parse_view_while(p, is_view_item) } fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,