Skip to content

syntax: Shrink enum Token and enum nonterminal #8420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,18 @@ pub fn parse_nt(p: &Parser, name: &str) -> nonterminal {
Some(i) => token::nt_item(i),
None => p.fatal("expected an item keyword")
},
"block" => token::nt_block(p.parse_block()),
"block" => token::nt_block(~p.parse_block()),
"stmt" => token::nt_stmt(p.parse_stmt(~[])),
"pat" => token::nt_pat(p.parse_pat()),
"expr" => token::nt_expr(p.parse_expr()),
"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
"ty" => token::nt_ty(~p.parse_ty(false /* no need to disambiguate*/)),
// this could be handled like a token, since it is one
"ident" => match *p.token {
token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) }
_ => p.fatal(~"expected ident, found "
+ token::to_str(get_ident_interner(), p.token))
},
"path" => token::nt_path(p.parse_path_with_tps(false)),
"path" => token::nt_path(~p.parse_path_with_tps(false)),
"attr" => token::nt_attr(@p.parse_attribute(false)),
"tt" => {
*p.quote_depth += 1u; //but in theory, non-quoted tts might be useful
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
/* sidestep the interpolation tricks for ident because
(a) idents can be in lots of places, so it'd be a pain
(b) we actually can, since it's a token. */
matched_nonterminal(nt_ident(sn,b)) => {
matched_nonterminal(nt_ident(~sn,b)) => {
r.cur_span = sp; r.cur_tok = IDENT(sn,b);
r.stack.idx += 1u;
return ret_val;
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ macro_rules! maybe_whole_expr (
Some($p.mk_expr(
($p).span.lo,
($p).span.hi,
expr_path(/* bad */ (*pt).clone())))
expr_path(/* bad */ (**pt).clone())))
}
_ => None
};
Expand Down Expand Up @@ -235,8 +235,8 @@ macro_rules! maybe_whole (
_ => None
};
match __found__ {
Some(INTERPOLATED(token::$constructor(x))) => {
return (~[], x.clone())
Some(INTERPOLATED(token::$constructor(ref x))) => {
return (~[], (**x).clone())
}
_ => {}
}
Expand Down Expand Up @@ -939,7 +939,7 @@ impl Parser {
// Useless second parameter for compatibility with quasiquote macros.
// Bleh!
pub fn parse_ty(&self, _: bool) -> Ty {
maybe_whole!(self, nt_ty);
maybe_whole!(deref self, nt_ty);

let lo = self.span.lo;

Expand Down Expand Up @@ -1293,7 +1293,7 @@ impl Parser {

// parse a path that doesn't have type parameters attached
pub fn parse_path_without_tps(&self) -> ast::Path {
maybe_whole!(self, nt_path);
maybe_whole!(deref self, nt_path);
let (ids,is_global,sp) = self.parse_path();
ast::Path { span: sp,
global: is_global,
Expand All @@ -1306,7 +1306,7 @@ impl Parser {
before_tps: Option<&fn()>) -> ast::Path {
debug!("parse_path_with_tps(colons=%b)", colons);

maybe_whole!(self, nt_path);
maybe_whole!(deref self, nt_path);
let lo = self.span.lo;
let path = self.parse_path_without_tps();
if colons && !self.eat(&token::MOD_SEP) {
Expand Down Expand Up @@ -3100,7 +3100,7 @@ impl Parser {

// parse a block. No inner attrs are allowed.
pub fn parse_block(&self) -> Block {
maybe_whole!(self, nt_block);
maybe_whole!(deref self, nt_block);

let lo = self.span.lo;
if self.eat_keyword(keywords::Unsafe) {
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ pub enum Token {
/// For interpolation during macro expansion.
pub enum nonterminal {
nt_item(@ast::item),
nt_block(ast::Block),
nt_block(~ast::Block),
nt_stmt(@ast::stmt),
nt_pat( @ast::pat),
nt_expr(@ast::expr),
nt_ty( ast::Ty),
nt_ident(ast::ident, bool),
nt_ty( ~ast::Ty),
nt_ident(~ast::ident, bool),
nt_attr(@ast::Attribute), // #[foo]
nt_path( ast::Path),
nt_path(~ast::Path),
nt_tt( @ast::token_tree), //needs @ed to break a circularity
nt_matchers(~[ast::matcher])
}
Expand Down