syntax: Eliminate token::POUND_LT, POUND_LBRACE

Use lookahead in the parser
This commit is contained in:
Brian Anderson 2012-04-22 15:15:18 -07:00
parent 92b2113583
commit 7321c17171
3 changed files with 9 additions and 16 deletions

View File

@ -357,12 +357,7 @@ fn next_token_inner(rdr: reader) -> token::token {
'[' { rdr.bump(); ret token::LBRACKET; }
']' { rdr.bump(); ret token::RBRACKET; }
'@' { rdr.bump(); ret token::AT; }
'#' {
rdr.bump();
if rdr.curr == '<' { rdr.bump(); ret token::POUND_LT; }
if rdr.curr == '{' { rdr.bump(); ret token::POUND_LBRACE; }
ret token::POUND;
}
'#' { rdr.bump(); ret token::POUND; }
'~' { rdr.bump(); ret token::TILDE; }
':' {
rdr.bump();

View File

@ -710,7 +710,8 @@ fn parse_bottom_expr(p: parser) -> pexpr {
parse_expr, p);
hi = p.span.hi;
ex = ast::expr_vec(es, mutbl);
} else if p.token == token::POUND_LT {
} else if p.token == token::POUND && p.look_ahead(1u) == token::LT {
p.bump();
p.bump();
let ty = parse_ty(p, false);
expect(p, token::GT);
@ -718,7 +719,8 @@ fn parse_bottom_expr(p: parser) -> pexpr {
/* hack: early return to take advantage of specialized function */
ret pexpr(mk_mac_expr(p, lo, p.span.hi,
ast::mac_embed_type(ty)));
} else if p.token == token::POUND_LBRACE {
} else if p.token == token::POUND && p.look_ahead(1u) == token::LBRACE {
p.bump();
p.bump();
let blk = ast::mac_embed_block(
parse_block_tail(p, lo, ast::default_blk));
@ -726,6 +728,10 @@ fn parse_bottom_expr(p: parser) -> pexpr {
} else if p.token == token::ELLIPSIS {
p.bump();
ret pexpr(mk_mac_expr(p, lo, p.span.hi, ast::mac_ellipsis));
} else if p.token == token::POUND {
let ex_ext = parse_syntax_ext(p);
hi = ex_ext.span.hi;
ex = ex_ext.node;
} else if eat_word(p, "bind") {
let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
let es =
@ -733,10 +739,6 @@ fn parse_bottom_expr(p: parser) -> pexpr {
parse_expr_or_hole, p);
hi = es.span.hi;
ex = ast::expr_bind(e, es.node);
} else if p.token == token::POUND {
let ex_ext = parse_syntax_ext(p);
hi = ex_ext.span.hi;
ex = ex_ext.node;
} else if eat_word(p, "fail") {
if can_begin_expr(p.token) {
let e = parse_expr(p);

View File

@ -53,8 +53,6 @@ enum token {
LBRACE,
RBRACE,
POUND,
POUND_LBRACE,
POUND_LT,
DOLLAR_LPAREN,
DOLLAR_NUM(uint),
@ -124,8 +122,6 @@ fn to_str(in: interner<str>, t: token) -> str {
LBRACE { ret "{"; }
RBRACE { ret "}"; }
POUND { ret "#"; }
POUND_LBRACE { ret "#{"; }
POUND_LT { ret "#<"; }
DOLLAR_LPAREN { ret "$("; }
DOLLAR_NUM(u) {