OLD | NEW |
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' show Token, TokenType; | 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 void handleInvalidTopLevelDeclaration(Token endToken) { | 1131 void handleInvalidTopLevelDeclaration(Token endToken) { |
1132 debugEvent("InvalidTopLevelDeclaration"); | 1132 debugEvent("InvalidTopLevelDeclaration"); |
1133 pop(); // metadata star | 1133 pop(); // metadata star |
1134 // TODO(danrubel): consider creating a AST node | 1134 // TODO(danrubel): consider creating a AST node |
1135 // representing the invalid declaration to better support code completion, | 1135 // representing the invalid declaration to better support code completion, |
1136 // quick fixes, etc, rather than discarding the metadata and token | 1136 // quick fixes, etc, rather than discarding the metadata and token |
1137 } | 1137 } |
1138 | 1138 |
1139 @override | 1139 @override |
1140 void beginCompilationUnit(Token token) { | 1140 void beginCompilationUnit(Token token) { |
| 1141 super.beginCompilationUnit(token); |
1141 push(token); | 1142 push(token); |
1142 } | 1143 } |
1143 | 1144 |
1144 @override | 1145 @override |
1145 void endCompilationUnit(int count, Token endToken) { | 1146 void endCompilationUnit(int count, Token endToken) { |
1146 debugEvent("CompilationUnit"); | 1147 debugEvent("CompilationUnit"); |
1147 Token beginToken = pop(); | 1148 Token beginToken = pop(); |
1148 checkEmpty(endToken.charOffset); | 1149 checkEmpty(endToken.charOffset); |
1149 | 1150 |
1150 push(ast.compilationUnit( | 1151 push(ast.compilationUnit( |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 switch (code.analyzerCode) { | 1890 switch (code.analyzerCode) { |
1890 case "EXPECTED_TYPE_NAME": | 1891 case "EXPECTED_TYPE_NAME": |
1891 errorReporter?.reportErrorForOffset( | 1892 errorReporter?.reportErrorForOffset( |
1892 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1); | 1893 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1); |
1893 return; | 1894 return; |
1894 case "EXPECTED_STRING_LITERAL": | 1895 case "EXPECTED_STRING_LITERAL": |
1895 errorReporter?.reportErrorForOffset( | 1896 errorReporter?.reportErrorForOffset( |
1896 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1); | 1897 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1); |
1897 return; | 1898 return; |
1898 case "UNEXPECTED_TOKEN": | 1899 case "UNEXPECTED_TOKEN": |
1899 var text = arguments['string']; | 1900 String text = arguments['string']; |
1900 if (text == null) { | 1901 if (text == null) { |
1901 Token token = arguments['token']; | 1902 Token token = arguments['token']; |
1902 if (token != null) { | 1903 if (token != null) { |
1903 text = token.lexeme; | 1904 text = token.lexeme; |
1904 } | 1905 } |
1905 } | 1906 } |
1906 errorReporter?.reportErrorForOffset( | 1907 if (text == ';') { |
1907 ParserErrorCode.UNEXPECTED_TOKEN, charOffset, 1, [text]); | 1908 errorReporter?.reportErrorForOffset( |
| 1909 ParserErrorCode.EXPECTED_TOKEN, charOffset, text.length, [text]); |
| 1910 } else { |
| 1911 errorReporter?.reportErrorForOffset( |
| 1912 ParserErrorCode.UNEXPECTED_TOKEN, charOffset, 1, [text]); |
| 1913 } |
1908 return; | 1914 return; |
1909 default: | 1915 default: |
1910 // fall through | 1916 // fall through |
1911 } | 1917 } |
1912 library.addCompileTimeError(message, charOffset, uri); | 1918 library.addCompileTimeError(message, charOffset, uri); |
1913 } | 1919 } |
1914 } | 1920 } |
1915 | 1921 |
1916 /// Data structure placed on the stack to represent a class body. | 1922 /// Data structure placed on the stack to represent a class body. |
1917 /// | 1923 /// |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 } else if (identical('var', s)) { | 2017 } else if (identical('var', s)) { |
2012 finalConstOrVarKeyword = token; | 2018 finalConstOrVarKeyword = token; |
2013 } else if (identical('covariant', s)) { | 2019 } else if (identical('covariant', s)) { |
2014 covariantKeyword = token; | 2020 covariantKeyword = token; |
2015 } else { | 2021 } else { |
2016 unhandled("$s", "modifier", token.charOffset, null); | 2022 unhandled("$s", "modifier", token.charOffset, null); |
2017 } | 2023 } |
2018 } | 2024 } |
2019 } | 2025 } |
2020 } | 2026 } |
OLD | NEW |