(index<- )        ./libsyntax/parse/classify.rs

    git branch:    * master           5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
    modified:    Fri May  9 13:02:28 2014
  1  // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
  2  // file at the top-level directory of this distribution and at
  3  // http://rust-lang.org/COPYRIGHT.
  4  //
  5  // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6  // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7  // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8  // option. This file may not be copied, modified, or distributed
  9  // except according to those terms.
 10  
 11  //! Routines the parser uses to classify AST nodes
 12  
 13  // Predicates on exprs and stmts that the pretty-printer and parser use
 14  
 15  use ast;
 16  
 17  // does this expression require a semicolon to be treated
 18  // as a statement? The negation of this: 'can this expression
 19  // be used as a statement without a semicolon' -- is used
 20  // as an early-bail-out in the parser so that, for instance,
 21  // 'if true {...} else {...}
 22  //  |x| 5 '
 23  // isn't parsed as (if true {...} else {...} | x) | 5
 24  pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool {
 25      match e.node {
 26          ast::ExprIf(..)
 27          | ast::ExprMatch(..)
 28          | ast::ExprBlock(_)
 29          | ast::ExprWhile(..)
 30          | ast::ExprLoop(..)
 31          | ast::ExprForLoop(..) => false,
 32          _ => true
 33      }
 34  }
 35  
 36  pub fn expr_is_simple_block(e: @ast::Expr) -> bool {
 37      match e.node {
 38          ast::ExprBlock(block) => block.rules == ast::DefaultBlock,
 39        _ => false
 40      }
 41  }
 42  
 43  // this statement requires a semicolon after it.
 44  // note that in one case (stmt_semi), we've already
 45  // seen the semicolon, and thus don't need another.
 46  pub fn stmt_ends_with_semi(stmt: &ast::Stmt) -> bool {
 47      return match stmt.node {
 48          ast::StmtDecl(d, _) => {
 49              match d.node {
 50                  ast::DeclLocal(_) => true,
 51                  ast::DeclItem(_) => false
 52              }
 53          }
 54          ast::StmtExpr(e, _) => { expr_requires_semi_to_be_stmt(e) }
 55          ast::StmtSemi(..) => { false }
 56          ast::StmtMac(..) => { false }
 57      }
 58  }


libsyntax/parse/classify.rs:45:52-45:52 -fn- definition:
// seen the semicolon, and thus don't need another.
pub fn stmt_ends_with_semi(stmt: &ast::Stmt) -> bool {
    return match stmt.node {
references:- 3
libsyntax/parse/parser.rs:
3343:                             if classify::stmt_ends_with_semi(stmt) {
3344:                                 self.commit_stmt_expecting(stmt, token::SEMI);
libsyntax/print/pprust.rs:
1009:         }
1010:         if parse::classify::stmt_ends_with_semi(st) {
1011:             try!(word(&mut self.s, ";"));


libsyntax/parse/classify.rs:35:1-35:1 -fn- definition:
pub fn expr_is_simple_block(e: @ast::Expr) -> bool {
    match e.node {
        ast::ExprBlock(block) => block.rules == ast::DefaultBlock,
references:- 2
libsyntax/parse/parser.rs:
2583:             let require_comma =
2584:                 !classify::expr_is_simple_block(expr)
2585:                 && self.token != token::RBRACE;
libsyntax/print/pprust.rs:
1335:                     }
1336:                     if !expr_is_simple_block(expr)
1337:                         && i < len - 1 {


libsyntax/parse/classify.rs:23:54-23:54 -fn- definition:
// isn't parsed as (if true {...} else {...} | x) | 5
pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool {
    match e.node {
references:- 2
53:         }
54:         ast::StmtExpr(e, _) => { expr_requires_semi_to_be_stmt(e) }
55:         ast::StmtSemi(..) => { false }
libsyntax/parse/parser.rs:
3206:         return self.restriction == RESTRICT_STMT_EXPR &&
3207:             !classify::expr_requires_semi_to_be_stmt(e);
3208:     }