Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart

Issue 2738313002: rename fasta.Token.value --> lexeme (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.analyzer.ast_builder; 5 library fasta.analyzer.ast_builder;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory;
9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard;
10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 push(ast.parenthesizedExpression( 102 push(ast.parenthesizedExpression(
103 toAnalyzerToken(token), expression, toAnalyzerToken(token.endGroup))); 103 toAnalyzerToken(token), expression, toAnalyzerToken(token.endGroup)));
104 } 104 }
105 105
106 void handleStringPart(Token token) { 106 void handleStringPart(Token token) {
107 debugEvent("StringPart"); 107 debugEvent("StringPart");
108 push(token); 108 push(token);
109 } 109 }
110 110
111 void doStringPart(Token token) { 111 void doStringPart(Token token) {
112 push(ast.simpleStringLiteral(toAnalyzerToken(token), token.value)); 112 push(ast.simpleStringLiteral(toAnalyzerToken(token), token.lexeme));
113 } 113 }
114 114
115 void endLiteralString(int interpolationCount) { 115 void endLiteralString(int interpolationCount) {
116 debugEvent("endLiteralString"); 116 debugEvent("endLiteralString");
117 if (interpolationCount == 0) { 117 if (interpolationCount == 0) {
118 Token token = pop(); 118 Token token = pop();
119 String value = unescapeString(token.value); 119 String value = unescapeString(token.lexeme);
120 push(ast.simpleStringLiteral(toAnalyzerToken(token), value)); 120 push(ast.simpleStringLiteral(toAnalyzerToken(token), value));
121 } else { 121 } else {
122 List parts = popList(1 + interpolationCount * 2); 122 List parts = popList(1 + interpolationCount * 2);
123 Token first = parts.first; 123 Token first = parts.first;
124 Token last = parts.last; 124 Token last = parts.last;
125 Quote quote = analyzeQuote(first.value); 125 Quote quote = analyzeQuote(first.lexeme);
126 List<InterpolationElement> elements = <InterpolationElement>[]; 126 List<InterpolationElement> elements = <InterpolationElement>[];
127 elements.add(ast.interpolationString( 127 elements.add(ast.interpolationString(
128 toAnalyzerToken(first), unescapeFirstStringPart(first.value, quote))); 128 toAnalyzerToken(first), unescapeFirstStringPart(first.lexeme, quote))) ;
ahe 2017/03/10 07:26:11 Long line.
danrubel 2017/03/11 22:10:38 Reformatted.
129 for (int i = 1; i < parts.length - 1; i++) { 129 for (int i = 1; i < parts.length - 1; i++) {
130 var part = parts[i]; 130 var part = parts[i];
131 if (part is Token) { 131 if (part is Token) {
132 elements 132 elements
133 .add(ast.interpolationString(toAnalyzerToken(part), part.value)); 133 .add(ast.interpolationString(toAnalyzerToken(part), part.lexeme));
134 } else if (part is Expression) { 134 } else if (part is Expression) {
135 elements.add(ast.interpolationExpression(null, part, null)); 135 elements.add(ast.interpolationExpression(null, part, null));
136 } else { 136 } else {
137 internalError( 137 internalError(
138 "Unexpected part in string interpolation: ${part.runtimeType}"); 138 "Unexpected part in string interpolation: ${part.runtimeType}");
139 } 139 }
140 } 140 }
141 elements.add(ast.interpolationString( 141 elements.add(ast.interpolationString(
142 toAnalyzerToken(last), unescapeLastStringPart(last.value, quote))); 142 toAnalyzerToken(last), unescapeLastStringPart(last.lexeme, quote)));
143 push(ast.stringInterpolation(elements)); 143 push(ast.stringInterpolation(elements));
144 } 144 }
145 } 145 }
146 146
147 void handleScript(Token token) { 147 void handleScript(Token token) {
148 debugEvent("Script"); 148 debugEvent("Script");
149 push(ast.scriptTag(toAnalyzerToken(token))); 149 push(ast.scriptTag(toAnalyzerToken(token)));
150 } 150 }
151 151
152 void handleStringJuxtaposition(int literalCount) { 152 void handleStringJuxtaposition(int literalCount) {
(...skipping 26 matching lines...) Expand all
179 push(identifier); 179 push(identifier);
180 } 180 }
181 } else if (context == IdentifierContext.enumValueDeclaration) { 181 } else if (context == IdentifierContext.enumValueDeclaration) {
182 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have 182 // TODO(paulberry): analyzer's ASTs allow for enumerated values to have
183 // metadata, but the spec doesn't permit it. 183 // metadata, but the spec doesn't permit it.
184 List<Annotation> metadata; 184 List<Annotation> metadata;
185 Comment comment = _toAnalyzerComment(token.precedingComments); 185 Comment comment = _toAnalyzerComment(token.precedingComments);
186 push(ast.enumConstantDeclaration(comment, metadata, identifier)); 186 push(ast.enumConstantDeclaration(comment, metadata, identifier));
187 } else { 187 } else {
188 if (context.isScopeReference) { 188 if (context.isScopeReference) {
189 String name = token.value; 189 String name = token.lexeme;
190 Builder builder = scope.lookup(name, token.charOffset, uri); 190 Builder builder = scope.lookup(name, token.charOffset, uri);
191 if (builder != null) { 191 if (builder != null) {
192 Element element = elementStore[builder]; 192 Element element = elementStore[builder];
193 assert(element != null); 193 assert(element != null);
194 identifier.staticElement = element; 194 identifier.staticElement = element;
195 } 195 }
196 } else if (context == IdentifierContext.classDeclaration) { 196 } else if (context == IdentifierContext.classDeclaration) {
197 className = identifier.name; 197 className = identifier.name;
198 } 198 }
199 push(identifier); 199 push(identifier);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ..operator = toAnalyzerToken(token); 325 ..operator = toAnalyzerToken(token);
326 push(identifierOrInvoke); 326 push(identifierOrInvoke);
327 } else { 327 } else {
328 internalError( 328 internalError(
329 "Unhandled property access: ${identifierOrInvoke.runtimeType}"); 329 "Unhandled property access: ${identifierOrInvoke.runtimeType}");
330 } 330 }
331 } 331 }
332 332
333 void handleLiteralInt(Token token) { 333 void handleLiteralInt(Token token) {
334 debugEvent("LiteralInt"); 334 debugEvent("LiteralInt");
335 push(ast.integerLiteral(toAnalyzerToken(token), int.parse(token.value))); 335 push(ast.integerLiteral(toAnalyzerToken(token), int.parse(token.lexeme)));
336 } 336 }
337 337
338 void endExpressionFunctionBody(Token arrowToken, Token endToken) { 338 void endExpressionFunctionBody(Token arrowToken, Token endToken) {
339 debugEvent("ExpressionFunctionBody"); 339 debugEvent("ExpressionFunctionBody");
340 Expression expression = pop(); 340 Expression expression = pop();
341 analyzer.Token star = pop(); 341 analyzer.Token star = pop();
342 analyzer.Token asyncKeyword = pop(); 342 analyzer.Token asyncKeyword = pop();
343 assert(star == null); 343 assert(star == null);
344 push(ast.expressionFunctionBody(asyncKeyword, toAnalyzerToken(arrowToken), 344 push(ast.expressionFunctionBody(asyncKeyword, toAnalyzerToken(arrowToken),
345 expression, toAnalyzerToken(endToken))); 345 expression, toAnalyzerToken(endToken)));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 487
488 void handleLiteralBool(Token token) { 488 void handleLiteralBool(Token token) {
489 debugEvent("LiteralBool"); 489 debugEvent("LiteralBool");
490 bool value = identical(token.stringValue, "true"); 490 bool value = identical(token.stringValue, "true");
491 assert(value || identical(token.stringValue, "false")); 491 assert(value || identical(token.stringValue, "false"));
492 push(ast.booleanLiteral(toAnalyzerToken(token), value)); 492 push(ast.booleanLiteral(toAnalyzerToken(token), value));
493 } 493 }
494 494
495 void handleLiteralDouble(Token token) { 495 void handleLiteralDouble(Token token) {
496 debugEvent("LiteralDouble"); 496 debugEvent("LiteralDouble");
497 push(ast.doubleLiteral(toAnalyzerToken(token), double.parse(token.value))); 497 push(ast.doubleLiteral(toAnalyzerToken(token), double.parse(token.lexeme)));
498 } 498 }
499 499
500 void handleLiteralNull(Token token) { 500 void handleLiteralNull(Token token) {
501 debugEvent("LiteralNull"); 501 debugEvent("LiteralNull");
502 push(ast.nullLiteral(toAnalyzerToken(token))); 502 push(ast.nullLiteral(toAnalyzerToken(token)));
503 } 503 }
504 504
505 void handleLiteralMap( 505 void handleLiteralMap(
506 int count, Token beginToken, Token constKeyword, Token endToken) { 506 int count, Token beginToken, Token constKeyword, Token endToken) {
507 debugEvent("LiteralMap"); 507 debugEvent("LiteralMap");
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 Token abstractKeyword; 1495 Token abstractKeyword;
1496 Token externalKeyword; 1496 Token externalKeyword;
1497 Token finalConstOrVarKeyword; 1497 Token finalConstOrVarKeyword;
1498 Token staticKeyword; 1498 Token staticKeyword;
1499 1499
1500 _Modifiers(List<Token> modifierTokens) { 1500 _Modifiers(List<Token> modifierTokens) {
1501 // No need to check the order and uniqueness of the modifiers, or that 1501 // No need to check the order and uniqueness of the modifiers, or that
1502 // disallowed modifiers are not used; the parser should do that. 1502 // disallowed modifiers are not used; the parser should do that.
1503 // TODO(paulberry,ahe): implement the necessary logic in the parser. 1503 // TODO(paulberry,ahe): implement the necessary logic in the parser.
1504 for (var token in modifierTokens) { 1504 for (var token in modifierTokens) {
1505 var s = token.value; 1505 var s = token.lexeme;
1506 if (identical('abstract', s)) { 1506 if (identical('abstract', s)) {
1507 abstractKeyword = token; 1507 abstractKeyword = token;
1508 } else if (identical('const', s)) { 1508 } else if (identical('const', s)) {
1509 finalConstOrVarKeyword = token; 1509 finalConstOrVarKeyword = token;
1510 } else if (identical('external', s)) { 1510 } else if (identical('external', s)) {
1511 externalKeyword = token; 1511 externalKeyword = token;
1512 } else if (identical('final', s)) { 1512 } else if (identical('final', s)) {
1513 finalConstOrVarKeyword = token; 1513 finalConstOrVarKeyword = token;
1514 } else if (identical('static', s)) { 1514 } else if (identical('static', s)) {
1515 staticKeyword = token; 1515 staticKeyword = token;
1516 } else if (identical('var', s)) { 1516 } else if (identical('var', s)) {
1517 finalConstOrVarKeyword = token; 1517 finalConstOrVarKeyword = token;
1518 } else { 1518 } else {
1519 internalError('Unhandled modifier: $s'); 1519 internalError('Unhandled modifier: $s');
1520 } 1520 }
1521 } 1521 }
1522 } 1522 }
1523 } 1523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698