|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -use ast::{self, TokenTree}; |
| 11 | +use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Path, Stmt, TokenTree, Ty}; |
12 | 12 | use codemap::Span;
|
13 | 13 | use ext::base::ExtCtxt;
|
14 | 14 | use ext::base;
|
15 | 15 | use ext::build::AstBuilder;
|
| 16 | +use parse::parser::{Parser, PathParsingMode}; |
16 | 17 | use parse::token::*;
|
17 | 18 | use parse::token;
|
18 | 19 | use ptr::P;
|
@@ -329,6 +330,52 @@ pub mod rt {
|
329 | 330 | }
|
330 | 331 | }
|
331 | 332 |
|
| 333 | +// These panicking parsing functions are used by the quote_*!() syntax extensions, |
| 334 | +// but shouldn't be used otherwise. |
| 335 | +pub fn parse_expr_panic(parser: &mut Parser) -> P<Expr> { |
| 336 | + panictry!(parser.parse_expr()) |
| 337 | +} |
| 338 | + |
| 339 | +pub fn parse_item_panic(parser: &mut Parser) -> Option<P<Item>> { |
| 340 | + panictry!(parser.parse_item()) |
| 341 | +} |
| 342 | + |
| 343 | +pub fn parse_pat_panic(parser: &mut Parser) -> P<Pat> { |
| 344 | + panictry!(parser.parse_pat()) |
| 345 | +} |
| 346 | + |
| 347 | +pub fn parse_arm_panic(parser: &mut Parser) -> Arm { |
| 348 | + panictry!(parser.parse_arm()) |
| 349 | +} |
| 350 | + |
| 351 | +pub fn parse_ty_panic(parser: &mut Parser) -> P<Ty> { |
| 352 | + panictry!(parser.parse_ty()) |
| 353 | +} |
| 354 | + |
| 355 | +pub fn parse_stmt_panic(parser: &mut Parser) -> Option<P<Stmt>> { |
| 356 | + panictry!(parser.parse_stmt()) |
| 357 | +} |
| 358 | + |
| 359 | +pub fn parse_attribute_panic(parser: &mut Parser, permit_inner: bool) -> ast::Attribute { |
| 360 | + panictry!(parser.parse_attribute(permit_inner)) |
| 361 | +} |
| 362 | + |
| 363 | +pub fn parse_arg_panic(parser: &mut Parser) -> Arg { |
| 364 | + panictry!(parser.parse_arg()) |
| 365 | +} |
| 366 | + |
| 367 | +pub fn parse_block_panic(parser: &mut Parser) -> P<Block> { |
| 368 | + panictry!(parser.parse_block()) |
| 369 | +} |
| 370 | + |
| 371 | +pub fn parse_meta_item_panic(parser: &mut Parser) -> P<ast::MetaItem> { |
| 372 | + panictry!(parser.parse_meta_item()) |
| 373 | +} |
| 374 | + |
| 375 | +pub fn parse_path_panic(parser: &mut Parser, mode: PathParsingMode) -> ast::Path { |
| 376 | + panictry!(parser.parse_path(mode)) |
| 377 | +} |
| 378 | + |
332 | 379 | pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
|
333 | 380 | sp: Span,
|
334 | 381 | tts: &[TokenTree])
|
@@ -864,8 +911,10 @@ fn expand_parse_call(cx: &ExtCtxt,
|
864 | 911 | cx.expr_ident(sp, id_ext("new_parser_from_tts")),
|
865 | 912 | vec!(parse_sess_call(), cfg_call(), tts_expr));
|
866 | 913 |
|
867 |
| - let expr = cx.expr_method_call(sp, new_parser_call, id_ext(parse_method), |
868 |
| - arg_exprs); |
| 914 | + let path = vec![id_ext("syntax"), id_ext("ext"), id_ext("quote"), id_ext(parse_method)]; |
| 915 | + let mut args = vec![cx.expr_mut_addr_of(sp, new_parser_call)]; |
| 916 | + args.extend(arg_exprs); |
| 917 | + let expr = cx.expr_call_global(sp, path, args); |
869 | 918 |
|
870 | 919 | if parse_method == "parse_attribute" {
|
871 | 920 | expand_wrapper(cx, sp, cx_expr, expr, &[&["syntax", "ext", "quote", "rt"],
|
|
0 commit comments