Skip to content

Commit 17585cc

Browse files
committed
rustc: Extract comman parts of view parsing
1 parent 16462a7 commit 17585cc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/comp/syntax/parse/parser.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1630,8 +1630,8 @@ fn parse_block_no_value(p: parser) -> ast::blk {
16301630
// necessary, and this should take a qualifier.
16311631
// some blocks start with "#{"...
16321632
fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
1633-
let view_items = [], stmts = [], expr = none;
1634-
while is_word(p, "import") { view_items += [parse_view_item(p)]; }
1633+
let stmts = [], expr = none;
1634+
let view_items = parse_view_import_only(p);
16351635
while p.token != token::RBRACE {
16361636
alt p.token {
16371637
token::SEMI. {
@@ -2378,15 +2378,21 @@ fn is_view_item(p: parser) -> bool {
23782378
}
23792379

23802380
fn parse_view(p: parser) -> [@ast::view_item] {
2381-
let items: [@ast::view_item] = [];
2382-
while is_view_item(p) { items += [parse_view_item(p)]; }
2381+
parse_view_while(p, is_view_item)
2382+
}
2383+
2384+
fn parse_view_import_only(p: parser) -> [@ast::view_item] {
2385+
parse_view_while(p, bind is_word(_, "import"))
2386+
}
2387+
2388+
fn parse_view_while(p: parser, f: fn@(parser) -> bool) -> [@ast::view_item] {
2389+
let items = [];
2390+
while f(p) { items += [parse_view_item(p)]; }
23832391
ret items;
23842392
}
23852393

23862394
fn parse_native_view(p: parser) -> [@ast::view_item] {
2387-
let items: [@ast::view_item] = [];
2388-
while is_view_item(p) { items += [parse_view_item(p)]; }
2389-
ret items;
2395+
parse_view_while(p, is_view_item)
23902396
}
23912397

23922398
fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,

0 commit comments

Comments
 (0)