Parse #operator symbol literals with Fasta.

R=paulberry@google.com, ahe@google.com
BUG=

Review-Url: https://codereview.chromium.org/2735623002 .
This commit is contained in:
Konstantin Shcheglov
2017-03-06 07:47:46 -08:00
parent 82685eacbf
commit be521515fe
3 changed files with 22 additions and 15 deletions
@@ -667,12 +667,6 @@ class ExpressionParserTest_Fasta extends FastaParserTestCase
super.test_parseSuperConstructorInvocation_unnamed();
}
@override
@failingTest
void test_parseSymbolLiteral_operator() {
super.test_parseSymbolLiteral_operator();
}
@override
@failingTest
void test_parseSymbolLiteral_void() {
@@ -149,8 +149,14 @@ class AstBuilder extends ScopeListener {
void handleIdentifier(Token token, IdentifierContext context) {
debugEvent("handleIdentifier");
String name = token.value;
SimpleIdentifier identifier = ast.simpleIdentifier(toAnalyzerToken(token));
analyzer.Token analyzerToken = toAnalyzerToken(token);
if (context.inSymbol) {
push(analyzerToken);
return;
}
SimpleIdentifier identifier = ast.simpleIdentifier(analyzerToken);
if (context.inLibraryOrPartOfDeclaration) {
if (!context.isContinuation) {
push([identifier]);
@@ -166,6 +172,7 @@ class AstBuilder extends ScopeListener {
push(ast.enumConstantDeclaration(comment, metadata, identifier));
} else {
if (context.isScopeReference) {
String name = token.value;
Builder builder = scope.lookup(name, token.charOffset, uri);
if (builder != null) {
Element element = elementStore[builder];
@@ -263,6 +270,11 @@ class AstBuilder extends ScopeListener {
push(receiver);
}
void handleOperator(Token token) {
debugEvent("Operator");
push(toAnalyzerToken(token));
}
void handleBinaryExpression(Token token) {
debugEvent("BinaryExpression");
if (identical(".", token.stringValue) ||
@@ -487,13 +499,9 @@ class AstBuilder extends ScopeListener {
push(ast.mapLiteralEntry(key, toAnalyzerToken(colon), value));
}
void endLiteralSymbol(Token hashToken, int identifierCount) {
void endLiteralSymbol(Token hashToken, int tokenCount) {
debugEvent("LiteralSymbol");
List<analyzer.Token> components = new List<analyzer.Token>(identifierCount);
for (int i = identifierCount - 1; i >= 0; i--) {
SimpleIdentifier identifier = pop();
components[i] = identifier.token;
}
List<analyzer.Token> components = popList(tokenCount);
push(ast.symbolLiteral(toAnalyzerToken(hashToken), components));
}
@@ -200,12 +200,13 @@ class IdentifierContext {
/// Identifier is the start of a reference occurring in a literal symbol (e.g.
/// `foo` in `#foo`).
static const literalSymbol =
const IdentifierContext._('literalSymbol', isScopeReference: true);
const IdentifierContext._('literalSymbol', inSymbol: true);
/// Identifier is part of a reference occurring in a literal symbol, but it's
/// not the first identifier of the reference (e.g. `foo` in `#prefix.foo`).
static const literalSymbolContinuation = const IdentifierContext._(
'literalSymbolContinuation',
inSymbol: true,
isContinuation: true);
/// Identifier appears in an expression, and it does not immediately follow a
@@ -236,6 +237,9 @@ class IdentifierContext {
/// declaration.
final bool inLibraryOrPartOfDeclaration;
/// Indicates whether the identifier is within a symbol literal.
final bool inSymbol;
/// Indicates whether the identifier follows a `.`.
final bool isContinuation;
@@ -244,6 +248,7 @@ class IdentifierContext {
const IdentifierContext._(this._name,
{this.inLibraryOrPartOfDeclaration: false,
this.inSymbol: false,
this.isContinuation: false,
this.isScopeReference: false});