rustc: Extract comman parts of view parsing
This commit is contained in:
parent
16462a77b0
commit
17585cc47e
@ -1630,8 +1630,8 @@ fn parse_block_no_value(p: parser) -> ast::blk {
|
|||||||
// necessary, and this should take a qualifier.
|
// necessary, and this should take a qualifier.
|
||||||
// some blocks start with "#{"...
|
// some blocks start with "#{"...
|
||||||
fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
|
fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
|
||||||
let view_items = [], stmts = [], expr = none;
|
let stmts = [], expr = none;
|
||||||
while is_word(p, "import") { view_items += [parse_view_item(p)]; }
|
let view_items = parse_view_import_only(p);
|
||||||
while p.token != token::RBRACE {
|
while p.token != token::RBRACE {
|
||||||
alt p.token {
|
alt p.token {
|
||||||
token::SEMI. {
|
token::SEMI. {
|
||||||
@ -2378,15 +2378,21 @@ fn is_view_item(p: parser) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_view(p: parser) -> [@ast::view_item] {
|
fn parse_view(p: parser) -> [@ast::view_item] {
|
||||||
let items: [@ast::view_item] = [];
|
parse_view_while(p, is_view_item)
|
||||||
while is_view_item(p) { items += [parse_view_item(p)]; }
|
}
|
||||||
|
|
||||||
|
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;
|
ret items;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_native_view(p: parser) -> [@ast::view_item] {
|
fn parse_native_view(p: parser) -> [@ast::view_item] {
|
||||||
let items: [@ast::view_item] = [];
|
parse_view_while(p, is_view_item)
|
||||||
while is_view_item(p) { items += [parse_view_item(p)]; }
|
|
||||||
ret items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,
|
fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user