summary refs log tree commit diff
path: root/src/comp/syntax/parse
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-15 16:25:31 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-15 16:25:31 -0800
commit17585cc47ec7c4ffc9d14f33473c4238b6680e88 (patch)
tree09bc645e6ab84035dcb1ba2d36d8928bc87cc5e1 /src/comp/syntax/parse
parent16462a77b0014356f75e5da60c787604371dd903 (diff)
rustc: Extract comman parts of view parsing
Diffstat (limited to 'src/comp/syntax/parse')
-rw-r--r--src/comp/syntax/parse/parser.rs20
1 files 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,