cleanup insert synthetic identifier

Change-Id: Ia7f2a94664f25ac51c0876d0c3317b78e5c2f63c
Reviewed-on: https://dart-review.googlesource.com/64780
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
This commit is contained in:
danrubel 2018-07-12 22:22:29 +00:00 committed by commit-bot@chromium.org
parent af27e106ee
commit 55921ed4bd
2 changed files with 18 additions and 18 deletions

View file

@ -1083,10 +1083,7 @@ class Parser {
new SyntheticKeywordToken(Keyword.WITH, withKeyword.charOffset);
rewriter.insertTokenAfter(token, withKeyword);
if (!isValidTypeReference(withKeyword.next)) {
rewriter.insertTokenAfter(
withKeyword,
new SyntheticStringToken(
TokenType.IDENTIFIER, '', withKeyword.charOffset));
rewriter.insertSyntheticIdentifier(withKeyword);
}
}
listener.beginMixinApplication(withKeyword);
@ -1872,10 +1869,7 @@ class Parser {
Token next = token.next;
reportRecoverableError(messageOnToken ?? next,
message ?? context.recoveryTemplate.withArguments(next));
Token identifier =
new SyntheticStringToken(TokenType.IDENTIFIER, '', next.charOffset, 0);
rewriter.insertTokenAfter(token, identifier);
return token.next;
return rewriter.insertSyntheticIdentifier(token);
}
/// Parse a simple identifier at the given [token], and return the identifier
@ -2308,10 +2302,7 @@ class Parser {
next, fasta.templateExpectedButGot.withArguments('.'));
rewriter.insertTokenAfter(
token, new SyntheticToken(TokenType.PERIOD, next.offset));
token = token.next;
rewriter.insertTokenAfter(token,
new SyntheticStringToken(TokenType.IDENTIFIER, '', next.offset));
token = token.next;
token = rewriter.insertSyntheticIdentifier(token.next);
next = token.next;
}
// Fall through to recovery

View file

@ -55,20 +55,29 @@ class TokenStreamRewriter {
next = next.setNext(new SyntheticToken(TokenType.CLOSE_PAREN, offset));
leftParen.endGroup = next;
next.setNext(token.next);
// A no-op rewriter could skip this step.
token.setNext(leftParen);
return leftParen;
}
/// Insert a synthetic identifier after [token] and return the new identifier.
Token insertSyntheticIdentifier(Token token) {
Token identifier = new SyntheticStringToken(
TokenType.IDENTIFIER, '', token.next.charOffset, 0)
..setNext(token.next);
return insertToken(
token,
new SyntheticStringToken(
TokenType.IDENTIFIER, '', token.next.charOffset, 0));
}
// A no-op rewriter could simply return the synthetic identifier here.
/// Insert [newToken] after [token] and return [newToken].
Token insertToken(Token token, Token newToken) {
newToken.setNext(token.next);
token.setNext(identifier);
return identifier;
// A no-op rewriter could skip this step.
token.setNext(newToken);
return newToken;
}
/// Insert the chain of tokens starting at the [insertedToken] immediately