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

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

Issue 2999303002: map fasta error codes to analyzer (Closed)
Patch Set: rebase Created 3 years, 3 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' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 if (scanner.hasErrors) { 1899 if (scanner.hasErrors) {
1900 return null; 1900 return null;
1901 } 1901 }
1902 return firstToken; 1902 return firstToken;
1903 } 1903 }
1904 1904
1905 @override 1905 @override
1906 void addCompileTimeError(Message message, int charOffset) { 1906 void addCompileTimeError(Message message, int charOffset) {
1907 Code code = message.code; 1907 Code code = message.code;
1908 Map<String, dynamic> arguments = message.arguments; 1908 Map<String, dynamic> arguments = message.arguments;
1909
1910 String stringOrTokenLexeme() {
1911 var text = arguments['string'];
1912 if (text == null) {
1913 Token token = arguments['token'];
1914 if (token != null) {
1915 text = token.lexeme;
1916 }
1917 }
1918 return text;
1919 }
1920
1909 switch (code.analyzerCode) { 1921 switch (code.analyzerCode) {
1910 case "EXPECTED_TYPE_NAME": 1922 case "EXPECTED_TYPE_NAME":
1911 errorReporter?.reportErrorForOffset( 1923 errorReporter?.reportErrorForOffset(
1912 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1); 1924 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1);
1913 return; 1925 return;
1914 case "NATIVE_CLAUSE_SHOULD_BE_ANNOTATION": 1926 case "NATIVE_CLAUSE_SHOULD_BE_ANNOTATION":
1915 if (!allowNativeClause) { 1927 if (!allowNativeClause) {
1916 errorReporter?.reportErrorForOffset( 1928 errorReporter?.reportErrorForOffset(
1917 ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION, 1929 ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION,
1918 charOffset, 1930 charOffset,
1919 1); 1931 1);
1920 } 1932 }
1921 return; 1933 return;
1922 case "EXPECTED_STRING_LITERAL": 1934 case "EXPECTED_STRING_LITERAL":
1923 errorReporter?.reportErrorForOffset( 1935 errorReporter?.reportErrorForOffset(
1924 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1); 1936 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1);
1925 return; 1937 return;
1938 case "EXTRANEOUS_MODIFIER":
1939 String text = stringOrTokenLexeme();
1940 errorReporter?.reportErrorForOffset(ParserErrorCode.EXTRANEOUS_MODIFIER,
1941 charOffset, text.length, [text]);
1942 return;
1926 case "UNEXPECTED_TOKEN": 1943 case "UNEXPECTED_TOKEN":
1927 String text = arguments['string']; 1944 String text = stringOrTokenLexeme();
1928 if (text == null) {
1929 Token token = arguments['token'];
1930 if (token != null) {
1931 text = token.lexeme;
1932 }
1933 }
1934 if (text == ';') { 1945 if (text == ';') {
1935 errorReporter?.reportErrorForOffset( 1946 errorReporter?.reportErrorForOffset(
1936 ParserErrorCode.EXPECTED_TOKEN, charOffset, text.length, [text]); 1947 ParserErrorCode.EXPECTED_TOKEN, charOffset, text.length, [text]);
1937 } else { 1948 } else {
1938 errorReporter?.reportErrorForOffset( 1949 errorReporter?.reportErrorForOffset(ParserErrorCode.UNEXPECTED_TOKEN,
1939 ParserErrorCode.UNEXPECTED_TOKEN, charOffset, 1, [text]); 1950 charOffset, text.length, [text]);
1940 } 1951 }
1941 return; 1952 return;
1942 default: 1953 default:
1943 // fall through 1954 // fall through
1944 } 1955 }
1945 library.addCompileTimeError(message, charOffset, uri); 1956 library.addCompileTimeError(message, charOffset, uri);
1946 } 1957 }
1947 } 1958 }
1948 1959
1949 /// Data structure placed on the stack to represent a class body. 1960 /// Data structure placed on the stack to represent a class body.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 } else if (identical('var', s)) { 2055 } else if (identical('var', s)) {
2045 finalConstOrVarKeyword = token; 2056 finalConstOrVarKeyword = token;
2046 } else if (identical('covariant', s)) { 2057 } else if (identical('covariant', s)) {
2047 covariantKeyword = token; 2058 covariantKeyword = token;
2048 } else { 2059 } else {
2049 unhandled("$s", "modifier", token.charOffset, null); 2060 unhandled("$s", "modifier", token.charOffset, null);
2050 } 2061 }
2051 } 2062 }
2052 } 2063 }
2053 } 2064 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/error/syntactic_errors.dart ('k') | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698