diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-05 01:17:07 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-06 14:04:02 +0300 |
| commit | aa6fba98ae717d6090cdd5d0569114adfc825680 (patch) | |
| tree | bbc8aed18256400f2873cddccc7a5553e993d408 /src/libsyntax/ext/tt | |
| parent | c0c57acd7b8061697d196fd800a7ff3151c37f38 (diff) | |
| download | rust-aa6fba98ae717d6090cdd5d0569114adfc825680.tar.gz rust-aa6fba98ae717d6090cdd5d0569114adfc825680.zip | |
syntax: Use `Token` in `Parser`
Diffstat (limited to 'src/libsyntax/ext/tt')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 16 |
2 files changed, 16 insertions, 17 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 6acdffedd6b..4f681a77ed3 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -273,7 +273,7 @@ pub enum ParseResult<T> { Success(T), /// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected /// end of macro invocation. Otherwise, it indicates that no rules expected the given token. - Failure(syntax_pos::Span, TokenKind, &'static str), + Failure(Token, &'static str), /// Fatal error (malformed macro?). Abort compilation. Error(syntax_pos::Span, String), } @@ -701,7 +701,7 @@ pub fn parse( parser.span, ) { Success(_) => {} - Failure(sp, tok, t) => return Failure(sp, tok, t), + Failure(token, msg) => return Failure(token, msg), Error(sp, msg) => return Error(sp, msg), } @@ -727,13 +727,13 @@ pub fn parse( "ambiguity: multiple successful parses".to_string(), ); } else { + let span = if parser.span.is_dummy() { + parser.span + } else { + sess.source_map().next_point(parser.span) + }; return Failure( - if parser.span.is_dummy() { - parser.span - } else { - sess.source_map().next_point(parser.span) - }, - token::Eof, + Token { kind: token::Eof, span }, "missing tokens in macro arguments", ); } @@ -771,7 +771,6 @@ pub fn parse( // then there is a syntax error. else if bb_items.is_empty() && next_items.is_empty() { return Failure( - parser.span, parser.token.clone(), "no rules expected this token in macro call", ); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 703ad0053a0..05e921b1bfd 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -190,10 +190,10 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>, arm_span, }) } - Failure(sp, tok, t) => if sp.lo() >= best_fail_spot.lo() { - best_fail_spot = sp; - best_fail_tok = Some(tok); - best_fail_text = Some(t); + Failure(token, msg) => if token.span.lo() >= best_fail_spot.lo() { + best_fail_spot = token.span; + best_fail_tok = Some(token.kind); + best_fail_text = Some(msg); }, Error(err_sp, ref msg) => { cx.span_fatal(err_sp.substitute_dummy(sp), &msg[..]) @@ -288,11 +288,11 @@ pub fn compile( let argument_map = match parse(sess, body.stream(), &argument_gram, None, true) { Success(m) => m, - Failure(sp, tok, t) => { - let s = parse_failure_msg(tok); - let sp = sp.substitute_dummy(def.span); + Failure(token, msg) => { + let s = parse_failure_msg(token.kind); + let sp = token.span.substitute_dummy(def.span); let mut err = sess.span_diagnostic.struct_span_fatal(sp, &s); - err.span_label(sp, t); + err.span_label(sp, msg); err.emit(); FatalError.raise(); } |
