diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-12 12:39:38 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-12 12:49:00 +0200 |
| commit | ca1df2b111584be938c870a9805ed148e068d824 (patch) | |
| tree | 0bffabbe71810e66b3b2b3ffeceed218260d286a /src/comp/syntax/parse | |
| parent | 5bc424e4ea8580f03bbd10e3fa241dfc72c3412c (diff) | |
Pretty-print for new arg-mode syntax
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/eval.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/parse/lexer.rs | 13 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 29 | ||||
| -rw-r--r-- | src/comp/syntax/parse/token.rs | 3 |
4 files changed, 31 insertions, 22 deletions
diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index 147f1b9453e..d525425dda7 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -26,8 +26,8 @@ type ctx = cfg: ast::crate_cfg}; fn eval_crate_directives(cx: ctx, cdirs: [@ast::crate_directive], prefix: str, - view_items: &mutable [@ast::view_item], - items: &mutable [@ast::item]) { + &view_items: [@ast::view_item], + &items: [@ast::item]) { for sub_cdir: @ast::crate_directive in cdirs { eval_crate_directive(cx, sub_cdir, prefix, view_items, items); } @@ -42,8 +42,8 @@ fn eval_crate_directives_to_mod(cx: ctx, cdirs: [@ast::crate_directive], } fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str, - view_items: &mutable [@ast::view_item], - items: &mutable [@ast::item]) { + &view_items: [@ast::view_item], + &items: [@ast::item]) { alt cdir.node { ast::cdir_src_mod(id, file_opt, attrs) { let file_path = id + ".rs"; diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index c5a9eefdec2..287b7fc1d39 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -363,6 +363,7 @@ fn next_token_inner(rdr: reader) -> token::token { + // One-byte tokens. '?' { rdr.bump(); @@ -404,6 +405,7 @@ fn next_token_inner(rdr: reader) -> token::token { + // Multi-byte tokens. '=' { rdr.bump(); @@ -579,14 +581,13 @@ fn consume_non_eol_whitespace(rdr: reader) { } } -fn push_blank_line_comment(rdr: reader, comments: &mutable [cmnt]) { +fn push_blank_line_comment(rdr: reader, &comments: [cmnt]) { log ">>> blank-line comment"; let v: [str] = []; comments += [{style: blank_line, lines: v, pos: rdr.get_chpos()}]; } -fn consume_whitespace_counting_blank_lines(rdr: reader, - comments: &mutable [cmnt]) { +fn consume_whitespace_counting_blank_lines(rdr: reader, &comments: [cmnt]) { while is_whitespace(rdr.curr()) && !rdr.is_eof() { if rdr.get_col() == 0u && rdr.curr() == '\n' { push_blank_line_comment(rdr, comments); @@ -617,8 +618,7 @@ fn all_whitespace(s: str, begin: uint, end: uint) -> bool { ret true; } -fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: str, - col: uint) { +fn trim_whitespace_prefix_and_push_line(&lines: [str], s: str, col: uint) { let s1; if all_whitespace(s, 0u, col) { if col < str::byte_len(s) { @@ -679,8 +679,7 @@ fn peeking_at_comment(rdr: reader) -> bool { rdr.curr() == '/' && rdr.next() == '*'; } -fn consume_comment(rdr: reader, code_to_the_left: bool, - comments: &mutable [cmnt]) { +fn consume_comment(rdr: reader, code_to_the_left: bool, &comments: [cmnt]) { log ">>> consume comment"; if rdr.curr() == '/' && rdr.next() == '/' { comments += [read_line_comments(rdr, code_to_the_left)]; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index b6abb899135..1b3126e833a 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -323,7 +323,7 @@ fn parse_proto(p: parser) -> ast::proto { } else { unexpected(p, p.peek()); } } -fn parse_ty_obj(p: parser, hi: &mutable uint) -> ast::ty_ { +fn parse_ty_obj(p: parser, &hi: uint) -> ast::ty_ { fn parse_method_sig(p: parser) -> ast::ty_method { let flo = p.get_lo_pos(); let proto: ast::proto = parse_proto(p); @@ -585,9 +585,7 @@ fn parse_arg_mode(p: parser) -> ast::mode { ret ast::by_mut_ref; } else if eat(p, token::BINOP(token::MINUS)) { ret ast::by_move; - } else { - ret ast::by_ref; - } + } else { ret ast::by_ref; } } fn parse_arg(p: parser) -> ast::arg { @@ -827,7 +825,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr { expect(p, token::RBRACE); ex = ast::expr_rec(fields, base); } else if p.peek() == token::BINOP(token::OR) || - p.peek() == token::OROR { + p.peek() == token::OROR { ret parse_fn_block_expr(p); } else { let blk = parse_block_tail(p, lo, ast::checked); @@ -1380,6 +1378,7 @@ fn parse_initializer(p: parser) -> option::t<ast::initializer> { + // Now that the the channel is the first argument to receive, // combining it with an initializer doesn't really make sense. // case (token::RECV) { @@ -1642,6 +1641,7 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { + // We should not be calling this on a cdir. ast::stmt_crate_directive(cdir) { fail; @@ -1773,12 +1773,14 @@ fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) -> } fn parse_fn_block_decl(p: parser) -> ast::fn_decl { - let inputs = if p.peek() == token::OROR { - p.bump(); [] - } else { - parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), - some(token::COMMA), parse_fn_block_arg, p).node - }; + let inputs = + if p.peek() == token::OROR { + p.bump();; + [] + } else { + parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), + some(token::COMMA), parse_fn_block_arg, p).node + }; ret {inputs: inputs, output: @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer), purity: ast::impure_fn, @@ -2269,6 +2271,7 @@ fn parse_rest_import_name(p: parser, first: ast::ident, + //the lexer can't tell the different kinds of stars apart ) : token::BINOP(token::STAR.) { glob = true; @@ -2278,6 +2281,7 @@ fn parse_rest_import_name(p: parser, first: ast::ident, + token::LBRACE. { fn parse_import_ident(p: parser) -> ast::import_ident { let lo = p.get_lo_pos(); @@ -2297,6 +2301,7 @@ fn parse_rest_import_name(p: parser, first: ast::ident, + _ { p.fatal("expecting an identifier, or '*'"); } @@ -2460,6 +2465,7 @@ fn parse_crate_directive(p: parser, first_outer_attr: [ast::attribute]) -> + // mod x = "foo.rs"; token::SEMI. { let hi = p.get_hi_pos(); @@ -2470,6 +2476,7 @@ fn parse_crate_directive(p: parser, first_outer_attr: [ast::attribute]) -> + // mod x = "foo_dir" { ...directives... } token::LBRACE. { p.bump(); diff --git a/src/comp/syntax/parse/token.rs b/src/comp/syntax/parse/token.rs index 2846d3945dd..7e7f7e2652c 100644 --- a/src/comp/syntax/parse/token.rs +++ b/src/comp/syntax/parse/token.rs @@ -119,6 +119,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Structural symbols */ AT. { ret "@"; @@ -146,6 +147,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Literals */ LIT_INT(i) { ret int::to_str(i, 10u); @@ -174,6 +176,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Name components */ IDENT(s, _) { ret interner::get::<str>(*r.get_interner(), s); |
