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

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 2899043006: cleanup fasta token classes (Closed)
Patch Set: Created 3 years, 7 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'dart:collection'; 5 import 'dart:collection';
6 import "dart:math" as math; 6 import "dart:math" as math;
7 7
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 if (Character.isLetterOrDigit(charAfterLeft)) { 1831 if (Character.isLetterOrDigit(charAfterLeft)) {
1832 int nameEnd = StringUtilities.indexOfFirstNotLetterDigit( 1832 int nameEnd = StringUtilities.indexOfFirstNotLetterDigit(
1833 comment, leftIndex + 1); 1833 comment, leftIndex + 1);
1834 String name = comment.substring(leftIndex + 1, nameEnd); 1834 String name = comment.substring(leftIndex + 1, nameEnd);
1835 nameToken = 1835 nameToken =
1836 new StringToken(TokenType.IDENTIFIER, name, nameOffset); 1836 new StringToken(TokenType.IDENTIFIER, name, nameOffset);
1837 } else { 1837 } else {
1838 nameToken = new SyntheticStringToken( 1838 nameToken = new SyntheticStringToken(
1839 TokenType.IDENTIFIER, '', nameOffset); 1839 TokenType.IDENTIFIER, '', nameOffset);
1840 } 1840 }
1841 nameToken.setNext(new SimpleToken(TokenType.EOF, nameToken.end)); 1841 nameToken.setNext(new Token.eof(nameToken.end));
1842 references.add(astFactory.commentReference( 1842 references.add(astFactory.commentReference(
1843 null, astFactory.simpleIdentifier(nameToken))); 1843 null, astFactory.simpleIdentifier(nameToken)));
1844 token.references.add(nameToken); 1844 token.references.add(nameToken);
1845 // next character 1845 // next character
1846 rightIndex = leftIndex + 1; 1846 rightIndex = leftIndex + 1;
1847 } 1847 }
1848 leftIndex = comment.indexOf('[', rightIndex); 1848 leftIndex = comment.indexOf('[', rightIndex);
1849 } else { 1849 } else {
1850 leftIndex = comment.indexOf('[', range[1]); 1850 leftIndex = comment.indexOf('[', range[1]);
1851 } 1851 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 // is being generated). 1964 // is being generated).
1965 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, 1965 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken,
1966 [_currentToken.lexeme]); 1966 [_currentToken.lexeme]);
1967 _advance(); 1967 _advance();
1968 } else { 1968 } else {
1969 CompilationUnitMember member; 1969 CompilationUnitMember member;
1970 try { 1970 try {
1971 member = parseCompilationUnitMember(commentAndMetadata); 1971 member = parseCompilationUnitMember(commentAndMetadata);
1972 } on _TooDeepTreeError { 1972 } on _TooDeepTreeError {
1973 _reportErrorForToken(ParserErrorCode.STACK_OVERFLOW, _currentToken); 1973 _reportErrorForToken(ParserErrorCode.STACK_OVERFLOW, _currentToken);
1974 Token eof = new Token(TokenType.EOF, 0); 1974 Token eof = new Token.eof(0);
1975 eof.previous = eof;
1976 eof.setNext(eof);
1977 return astFactory.compilationUnit(eof, null, null, null, eof); 1975 return astFactory.compilationUnit(eof, null, null, null, eof);
1978 } 1976 }
1979 if (member != null) { 1977 if (member != null) {
1980 declarations.add(member); 1978 declarations.add(member);
1981 } 1979 }
1982 } 1980 }
1983 if (identical(_currentToken, memberStart)) { 1981 if (identical(_currentToken, memberStart)) {
1984 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, 1982 _reportErrorForToken(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken,
1985 [_currentToken.lexeme]); 1983 [_currentToken.lexeme]);
1986 _advance(); 1984 _advance();
(...skipping 3824 matching lines...) Expand 10 before | Expand all | Expand 10 after
5811 5809
5812 /** 5810 /**
5813 * Clone all token starting from the given [token] up to the end of the token 5811 * Clone all token starting from the given [token] up to the end of the token
5814 * stream, and return the first token in the new token stream. 5812 * stream, and return the first token in the new token stream.
5815 */ 5813 */
5816 Token _cloneTokens(Token token) { 5814 Token _cloneTokens(Token token) {
5817 if (token == null) { 5815 if (token == null) {
5818 return null; 5816 return null;
5819 } 5817 }
5820 token = token is CommentToken ? token.parent : token; 5818 token = token is CommentToken ? token.parent : token;
5821 Token head = new Token(TokenType.EOF, -1); 5819 Token head = new Token.eof(-1);
5822 head.setNext(head);
5823 Token current = head; 5820 Token current = head;
5824 while (token.type != TokenType.EOF) { 5821 while (token.type != TokenType.EOF) {
5825 Token clone = token.copy(); 5822 Token clone = token.copy();
5826 current.setNext(clone); 5823 current.setNext(clone);
5827 current = clone; 5824 current = clone;
5828 token = token.next; 5825 token = token.next;
5829 } 5826 }
5830 Token tail = new Token(TokenType.EOF, 0); 5827 Token tail = new Token.eof(0);
5831 tail.setNext(tail);
5832 current.setNext(tail); 5828 current.setNext(tail);
5833 return head.next; 5829 return head.next;
5834 } 5830 }
5835 5831
5836 /** 5832 /**
5837 * Convert the given [method] declaration into the nearest valid top-level 5833 * Convert the given [method] declaration into the nearest valid top-level
5838 * function declaration (that is, the function declaration that most closely 5834 * function declaration (that is, the function declaration that most closely
5839 * captures the components of the given method declaration). 5835 * captures the components of the given method declaration).
5840 */ 5836 */
5841 FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) => 5837 FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) =>
(...skipping 2757 matching lines...) Expand 10 before | Expand all | Expand 10 after
8599 } 8595 }
8600 } 8596 }
8601 } 8597 }
8602 8598
8603 /** 8599 /**
8604 * Instances of this class are thrown when the parser detects that AST has 8600 * Instances of this class are thrown when the parser detects that AST has
8605 * too many nested expressions to be parsed safely and avoid possibility of 8601 * too many nested expressions to be parsed safely and avoid possibility of
8606 * [StackOverflowError] in the parser or during later analysis. 8602 * [StackOverflowError] in the parser or during later analysis.
8607 */ 8603 */
8608 class _TooDeepTreeError {} 8604 class _TooDeepTreeError {}
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/fasta/token_utils.dart ('k') | pkg/analyzer/lib/src/summary/fasta/stack_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698