Skip to content

Commit 7321c17

Browse files
committed
syntax: Eliminate token::POUND_LT, POUND_LBRACE
Use lookahead in the parser
1 parent 92b2113 commit 7321c17

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/librustsyntax/parse/lexer.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,7 @@ fn next_token_inner(rdr: reader) -> token::token {
357357
'[' { rdr.bump(); ret token::LBRACKET; }
358358
']' { rdr.bump(); ret token::RBRACKET; }
359359
'@' { rdr.bump(); ret token::AT; }
360-
'#' {
361-
rdr.bump();
362-
if rdr.curr == '<' { rdr.bump(); ret token::POUND_LT; }
363-
if rdr.curr == '{' { rdr.bump(); ret token::POUND_LBRACE; }
364-
ret token::POUND;
365-
}
360+
'#' { rdr.bump(); ret token::POUND; }
366361
'~' { rdr.bump(); ret token::TILDE; }
367362
':' {
368363
rdr.bump();

src/librustsyntax/parse/parser.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,33 +710,35 @@ fn parse_bottom_expr(p: parser) -> pexpr {
710710
parse_expr, p);
711711
hi = p.span.hi;
712712
ex = ast::expr_vec(es, mutbl);
713-
} else if p.token == token::POUND_LT {
713+
} else if p.token == token::POUND && p.look_ahead(1u) == token::LT {
714+
p.bump();
714715
p.bump();
715716
let ty = parse_ty(p, false);
716717
expect(p, token::GT);
717718

718719
/* hack: early return to take advantage of specialized function */
719720
ret pexpr(mk_mac_expr(p, lo, p.span.hi,
720721
ast::mac_embed_type(ty)));
721-
} else if p.token == token::POUND_LBRACE {
722+
} else if p.token == token::POUND && p.look_ahead(1u) == token::LBRACE {
723+
p.bump();
722724
p.bump();
723725
let blk = ast::mac_embed_block(
724726
parse_block_tail(p, lo, ast::default_blk));
725727
ret pexpr(mk_mac_expr(p, lo, p.span.hi, blk));
726728
} else if p.token == token::ELLIPSIS {
727729
p.bump();
728730
ret pexpr(mk_mac_expr(p, lo, p.span.hi, ast::mac_ellipsis));
731+
} else if p.token == token::POUND {
732+
let ex_ext = parse_syntax_ext(p);
733+
hi = ex_ext.span.hi;
734+
ex = ex_ext.node;
729735
} else if eat_word(p, "bind") {
730736
let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
731737
let es =
732738
parse_seq(token::LPAREN, token::RPAREN, seq_sep(token::COMMA),
733739
parse_expr_or_hole, p);
734740
hi = es.span.hi;
735741
ex = ast::expr_bind(e, es.node);
736-
} else if p.token == token::POUND {
737-
let ex_ext = parse_syntax_ext(p);
738-
hi = ex_ext.span.hi;
739-
ex = ex_ext.node;
740742
} else if eat_word(p, "fail") {
741743
if can_begin_expr(p.token) {
742744
let e = parse_expr(p);

src/librustsyntax/parse/token.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ enum token {
5353
LBRACE,
5454
RBRACE,
5555
POUND,
56-
POUND_LBRACE,
57-
POUND_LT,
5856

5957
DOLLAR_LPAREN,
6058
DOLLAR_NUM(uint),
@@ -124,8 +122,6 @@ fn to_str(in: interner<str>, t: token) -> str {
124122
LBRACE { ret "{"; }
125123
RBRACE { ret "}"; }
126124
POUND { ret "#"; }
127-
POUND_LBRACE { ret "#{"; }
128-
POUND_LT { ret "#<"; }
129125

130126
DOLLAR_LPAREN { ret "$("; }
131127
DOLLAR_NUM(u) {

0 commit comments

Comments
 (0)