mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 09:43:08 +00:00
Add beforeSynthetic field for synthetic ")", "]", and "}" tokens
This CL updates SyntheticToken to have a new beforeSynthetic field and the fasta scanner to set that field for synthetic ")", "]", and "}" tokens. This makes it much more efficient for the parser to move a synthetic closer when the scanner has inserted it in a less than optimal location in the token stream. This CL also addresses a comment in Address comment in https://dart-review.googlesource.com/c/sdk/+/51561 Change-Id: I7f056ac25f2ca4cf5edb0ef4bce7f1e9dd76de9a Reviewed-on: https://dart-review.googlesource.com/52040 Commit-Queue: Dan Rubel <danrubel@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
0289071afe
commit
be741ba511
4 changed files with 41 additions and 4 deletions
|
@ -770,8 +770,7 @@ class Parser {
|
|||
next.setNext(leftParen);
|
||||
leftParen = openParen;
|
||||
}
|
||||
token = leftParen;
|
||||
token = parseDottedName(token);
|
||||
token = parseDottedName(leftParen);
|
||||
Token next = token.next;
|
||||
Token equalitySign;
|
||||
if (optional('==', next)) {
|
||||
|
|
|
@ -361,7 +361,7 @@ abstract class ArrayBasedScanner extends AbstractScanner {
|
|||
// v
|
||||
// EOF
|
||||
TokenType type = closeBraceInfoFor(begin);
|
||||
appendToken(new SyntheticToken(type, tokenStart));
|
||||
appendToken(new SyntheticToken(type, tokenStart)..beforeSynthetic = tail);
|
||||
begin.endGroup = tail;
|
||||
appendErrorToken(new UnmatchedToken(begin));
|
||||
}
|
||||
|
|
|
@ -492,6 +492,14 @@ class SimpleToken implements Token {
|
|||
@override
|
||||
int get charEnd => end;
|
||||
|
||||
@override
|
||||
Token get beforeSynthetic => null;
|
||||
|
||||
@override
|
||||
set beforeSynthetic(Token previous) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@override
|
||||
int get end => offset + length;
|
||||
|
||||
|
@ -581,6 +589,7 @@ class SimpleToken implements Token {
|
|||
Token setNext(Token token) {
|
||||
next = token;
|
||||
token.previous = this;
|
||||
token.beforeSynthetic = this;
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -711,6 +720,12 @@ class SyntheticStringToken extends StringToken {
|
|||
class SyntheticToken extends SimpleToken {
|
||||
SyntheticToken(TokenType type, int offset) : super(type, offset);
|
||||
|
||||
@override
|
||||
Token beforeSynthetic;
|
||||
|
||||
@override
|
||||
bool get isSynthetic => true;
|
||||
|
||||
@override
|
||||
int get length => 0;
|
||||
|
||||
|
@ -757,6 +772,18 @@ abstract class Token implements SyntacticEntity {
|
|||
*/
|
||||
int get charEnd;
|
||||
|
||||
/**
|
||||
* The token before this synthetic token,
|
||||
* or `null` if this is not a synthetic `)`, `]`, `}`, or `>` token.
|
||||
*/
|
||||
Token get beforeSynthetic;
|
||||
|
||||
/**
|
||||
* Set token before this synthetic `)`, `]`, `}`, or `>` token,
|
||||
* and ignored otherwise.
|
||||
*/
|
||||
set beforeSynthetic(Token previous);
|
||||
|
||||
@override
|
||||
int get end;
|
||||
|
||||
|
|
|
@ -727,7 +727,18 @@ class ScannerTest_Fasta_Direct extends ScannerTest_Fasta_Base {
|
|||
|
||||
@override
|
||||
Token scan(String source) {
|
||||
return createScanner(source, includeComments: true).tokenize();
|
||||
final Token first = createScanner(source, includeComments: true).tokenize();
|
||||
Token token = first;
|
||||
while (!token.isEof) {
|
||||
Token next = token.next;
|
||||
expect(token.next, next);
|
||||
expect(next.previous, token);
|
||||
if (next.isSynthetic && [')', ']', '}'].contains(next.lexeme)) {
|
||||
expect(next.beforeSynthetic, token);
|
||||
}
|
||||
token = next;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
void test_linestarts() {
|
||||
|
|
Loading…
Reference in a new issue