diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-07-27 19:14:46 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-07-27 19:14:46 -0700 |
| commit | e11e90f31cedabec1e84b505bbf64103c3421574 (patch) | |
| tree | 692e73ed8b212c77a3da24cb4366a574fcb31fa0 /src/libsyntax/parse | |
| parent | eabd233dcd208bc21ca0f8eea02d87d56e5314eb (diff) | |
| download | rust-e11e90f31cedabec1e84b505bbf64103c3421574.tar.gz rust-e11e90f31cedabec1e84b505bbf64103c3421574.zip | |
Make macro-system type and constructor names more uniform; more comments.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/common.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 40 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 44 |
3 files changed, 44 insertions, 42 deletions
diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index e35b762f972..7898cd64890 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -86,7 +86,7 @@ impl parser_common of parser_common for parser { fn parse_ident() -> ast::ident { alt copy self.token { token::IDENT(i, _) { self.bump(); ret self.get_str(i); } - token::ACTUALLY(token::w_ident(*)) { self.bug( + token::INTERPOLATED(token::nt_ident(*)) { self.bug( ~"ident interpolation not converted to real token"); } _ { self.fatal(~"expected ident, found `" + token_to_str(self.reader, self.token) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 51f6ae021cd..888bb256852 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3,7 +3,7 @@ import print::pprust::expr_to_str; import result::result; import either::{either, left, right}; import std::map::{hashmap, str_hash}; -import token::{can_begin_expr, is_ident, is_plain_ident, ACTUALLY}; +import token::{can_begin_expr, is_ident, is_plain_ident, INTERPOLATED}; import codemap::{span,fss_none}; import util::interner; import ast_util::{spanned, respan, mk_sp, ident_to_path, operator_prec}; @@ -39,15 +39,15 @@ import ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute, item_ty, lit, lit_, lit_bool, lit_float, lit_int, lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const, m_imm, m_mutbl, mac_, mac_aq, mac_ellipsis, - mac_invoc, mac_invoc_tt, mac_var, matcher, - method, mode, mt, mtc_bb, mtc_rep, mtc_tok, mul, mutability, neg, + mac_invoc, mac_invoc_tt, mac_var, matcher, match_nonterminal, + match_seq, match_tok, method, mode, mt, mul, mutability, neg, noreturn, not, pat, pat_box, pat_enum, pat_ident, pat_lit, pat_range, pat_rec, pat_tup, pat_uniq, pat_wild, path, private, proto, proto_any, proto_bare, proto_block, proto_box, proto_uniq, provided, public, pure_fn, purity, re_anon, re_named, region, rem, required, ret_style, return_val, shl, shr, stmt, stmt_decl, stmt_expr, stmt_semi, subtract, token_tree, trait_method, - trait_ref, tt_delim, tt_dotdotdot, tt_flat, tt_interpolate, ty, + trait_ref, tt_delim, tt_seq, tt_tok, tt_nonterminal, ty, ty_, ty_bot, ty_box, ty_field, ty_fn, ty_infer, ty_mac, ty_method, ty_nil, ty_param, ty_path, ty_ptr, ty_rec, ty_rptr, ty_tup, ty_u32, ty_uniq, ty_vec, ty_fixed_length, unchecked_blk, @@ -104,14 +104,14 @@ type item_info = (ident, item_, option<~[attribute]>); /* The expr situation is not as complex as I thought it would be. The important thing is to make sure that lookahead doesn't balk -at ACTUALLY tokens */ -macro_rules! maybe_whole_expr{ +at INTERPOLATED tokens */ +macro_rules! maybe_whole_expr { {$p:expr} => { alt copy $p.token { - ACTUALLY(token::w_expr(e)) { + INTERPOLATED(token::nt_expr(e)) { $p.bump(); ret pexpr(e); } - ACTUALLY(token::w_path(pt)) { + INTERPOLATED(token::nt_path(pt)) { $p.bump(); ret $p.mk_pexpr($p.span.lo, $p.span.lo, expr_path(pt)); @@ -122,7 +122,7 @@ macro_rules! maybe_whole_expr{ macro_rules! maybe_whole { {$p:expr, $constructor:path} => { alt copy $p.token { - ACTUALLY($constructor(x)) { $p.bump(); ret x; } + INTERPOLATED($constructor(x)) { $p.bump(); ret x; } _ {} }} } @@ -133,7 +133,7 @@ fn dummy() { /* we will need this to bootstrap maybe_whole! */ #macro[[#maybe_whole_path[p], alt p.token { - ACTUALLY(token::w_path(pt)) { p.bump(); ret pt; } + INTERPOLATED(token::nt_path(pt)) { p.bump(); ret pt; } _ {} }]]; } @@ -1090,7 +1090,7 @@ class parser { } } - fn parse_tt_flat(p: parser, delim_ok: bool) -> token_tree { + fn parse_tt_tok(p: parser, delim_ok: bool) -> token_tree { alt p.token { token::RPAREN | token::RBRACE | token::RBRACKET if !delim_ok { @@ -1110,14 +1110,14 @@ class parser { seq_sep_none(), |p| p.parse_token_tree()); let (s, z) = p.parse_sep_and_zerok(); - ret tt_dotdotdot(mk_sp(sp.lo ,p.span.hi), seq.node, s, z); + ret tt_seq(mk_sp(sp.lo ,p.span.hi), seq.node, s, z); } else { - ret tt_interpolate(sp, p.parse_ident()); + ret tt_nonterminal(sp, p.parse_ident()); } } _ { /* ok */ } } - let res = tt_flat(p.span, p.token); + let res = tt_tok(p.span, p.token); p.bump(); ret res; } @@ -1126,14 +1126,14 @@ class parser { token::LPAREN | token::LBRACE | token::LBRACKET { let ket = flip(self.token); tt_delim(vec::append( - ~[parse_tt_flat(self, true)], + ~[parse_tt_tok(self, true)], vec::append( self.parse_seq_to_before_end( ket, seq_sep_none(), |p| p.parse_token_tree()), - ~[parse_tt_flat(self, true)]))) + ~[parse_tt_tok(self, true)]))) } - _ { parse_tt_flat(self, false) } + _ { parse_tt_tok(self, false) } }; } @@ -1177,17 +1177,17 @@ class parser { self.fatal(~"repetition body must be nonempty"); } let (sep, zerok) = self.parse_sep_and_zerok(); - mtc_rep(ms, sep, zerok, name_idx_lo, *name_idx) + match_seq(ms, sep, zerok, name_idx_lo, *name_idx) } else { let bound_to = self.parse_ident(); self.expect(token::COLON); let nt_name = self.parse_ident(); - let m = mtc_bb(bound_to, nt_name, *name_idx); + let m = match_nonterminal(bound_to, nt_name, *name_idx); *name_idx += 1u; m } } else { - let m = mtc_tok(self.token); + let m = match_tok(self.token); self.bump(); m }; diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a39b74eaca3..51d5d52ebe8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -79,7 +79,7 @@ enum token { UNDERSCORE, /* For interpolation */ - ACTUALLY(whole_nt), + INTERPOLATED(nonterminal), DOC_COMMENT(str_num), EOF, @@ -87,17 +87,17 @@ enum token { #[auto_serialize] /// For interpolation during macro expansion. -enum whole_nt { - w_item(@ast::item), - w_block(ast::blk), - w_stmt(@ast::stmt), - w_pat( @ast::pat), - w_expr(@ast::expr), - w_ty( @ast::ty), - w_ident(str_num, bool), - w_path(@ast::path), - w_tt( @ast::token_tree), //needs @ed to break a circularity - w_mtcs(~[ast::matcher]) +enum nonterminal { + nt_item(@ast::item), + nt_block(ast::blk), + nt_stmt(@ast::stmt), + nt_pat( @ast::pat), + nt_expr(@ast::expr), + nt_ty( @ast::ty), + nt_ident(str_num, bool), + nt_path(@ast::path), + nt_tt( @ast::token_tree), //needs @ed to break a circularity + nt_matchers(~[ast::matcher]) } fn binop_to_str(o: binop) -> ~str { @@ -184,14 +184,14 @@ fn to_str(in: interner<@~str>, t: token) -> ~str { /* Other */ DOC_COMMENT(s) { *interner::get(in, s) } EOF { ~"<eof>" } - ACTUALLY(w_nt) { + INTERPOLATED(nt) { ~"an interpolated " + - alt w_nt { - w_item(*) { ~"item" } w_block(*) { ~"block" } - w_stmt(*) { ~"statement" } w_pat(*) { ~"pattern" } - w_expr(*) { ~"expression" } w_ty(*) { ~"type" } - w_ident(*) { ~"identifier" } w_path(*) { ~"path" } - w_tt(*) { ~"tt" } w_mtcs(*) { ~"matcher sequence" } + alt nt { + nt_item(*) { ~"item" } nt_block(*) { ~"block" } + nt_stmt(*) { ~"statement" } nt_pat(*) { ~"pattern" } + nt_expr(*) { ~"expression" } nt_ty(*) { ~"type" } + nt_ident(*) { ~"identifier" } nt_path(*) { ~"path" } + nt_tt(*) { ~"tt" } nt_matchers(*) { ~"matcher sequence" } } } } @@ -219,8 +219,10 @@ pure fn can_begin_expr(t: token) -> bool { BINOP(OR) { true } // in lambda syntax OROR { true } // in lambda syntax MOD_SEP { true } - ACTUALLY(w_expr(*)) | ACTUALLY(w_ident(*)) | ACTUALLY(w_block(*)) - | ACTUALLY(w_path(*)) { true } + INTERPOLATED(nt_expr(*)) + | INTERPOLATED(nt_ident(*)) + | INTERPOLATED(nt_block(*)) + | INTERPOLATED(nt_path(*)) { true } _ { false } } } |
