@@ -6,7 +6,7 @@ use crate::ext::base::{SyntaxExtension, SyntaxExtensionKind};
66use crate :: ext:: expand:: { AstFragment , AstFragmentKind } ;
77use crate :: ext:: mbe;
88use crate :: ext:: mbe:: macro_check;
9- use crate :: ext:: mbe:: macro_parser:: { parse, parse_failure_msg } ;
9+ use crate :: ext:: mbe:: macro_parser:: parse;
1010use crate :: ext:: mbe:: macro_parser:: { Error , Failure , Success } ;
1111use crate :: ext:: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , NamedParseResult } ;
1212use crate :: ext:: mbe:: transcribe:: transcribe;
@@ -15,6 +15,7 @@ use crate::parse::parser::Parser;
1515use crate :: parse:: token:: TokenKind :: * ;
1616use crate :: parse:: token:: { self , NtTT , Token } ;
1717use crate :: parse:: { Directory , ParseSess } ;
18+ use crate :: print:: pprust;
1819use crate :: symbol:: { kw, sym, Symbol } ;
1920use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
2021
@@ -1176,3 +1177,15 @@ impl TokenTree {
11761177 parse ( cx. parse_sess ( ) , tts, mtch, Some ( directory) , true )
11771178 }
11781179}
1180+
1181+ /// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For
1182+ /// other tokens, this is "unexpected token...".
1183+ fn parse_failure_msg ( tok : & Token ) -> String {
1184+ match tok. kind {
1185+ token:: Eof => "unexpected end of macro invocation" . to_string ( ) ,
1186+ _ => format ! (
1187+ "no rules expected the token `{}`" ,
1188+ pprust:: token_to_string( tok) ,
1189+ ) ,
1190+ }
1191+ }
0 commit comments