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

Side by Side Diff: pkg/front_end/lib/src/fasta/parser/listener.dart

Issue 2778213002: Use message.yaml in parser. (Closed)
Patch Set: Update subpackage relationships. Created 3 years, 8 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.parser.listener; 5 library fasta.parser.listener;
6 6
7 import '../fasta_codes.dart' show FastaMessage;
8
7 import '../scanner/token.dart' show BeginGroupToken, SymbolToken, Token; 9 import '../scanner/token.dart' show BeginGroupToken, SymbolToken, Token;
8 10
9 import '../util/link.dart' show Link; 11 import '../util/link.dart' show Link;
10 12
11 import 'error_kind.dart' show ErrorKind;
12 import 'package:front_end/src/fasta/scanner/precedence.dart' show RECOVERY_INFO; 13 import 'package:front_end/src/fasta/scanner/precedence.dart' show RECOVERY_INFO;
13 import 'parser.dart' show FormalParameterType; 14 import 'parser.dart' show FormalParameterType;
14 15
15 import 'identifier_context.dart' show IdentifierContext; 16 import 'identifier_context.dart' show IdentifierContext;
16 17
17 /// A parser event listener that does nothing except throw exceptions 18 /// A parser event listener that does nothing except throw exceptions
18 /// on parser errors. 19 /// on parser errors.
19 /// 20 ///
20 /// Events are methods that begin with one of: `begin`, `end`, or `handle`. 21 /// Events are methods that begin with one of: `begin`, `end`, or `handle`.
21 /// 22 ///
22 /// Events starting with `begin` and `end` come in pairs. Normally, a 23 /// Events starting with `begin` and `end` come in pairs. Normally, a
23 /// `beginFoo` event is followed by an `endFoo` event. There's a few exceptions 24 /// `beginFoo` event is followed by an `endFoo` event. There's a few exceptions
24 /// documented below. 25 /// documented below.
25 /// 26 ///
26 /// Events starting with `handle` are used when isn't possible to have a begin 27 /// Events starting with `handle` are used when isn't possible to have a begin
27 /// event. 28 /// event.
28 class Listener { 29 class Listener {
29 final List<ParserError> recoverableErrors = <ParserError>[]; 30 final List<ParserError> recoverableErrors = <ParserError>[];
30 31
32 Uri get uri => null;
33
31 void logEvent(String name) {} 34 void logEvent(String name) {}
32 35
33 set suppressParseErrors(bool value) {} 36 set suppressParseErrors(bool value) {}
34 37
35 void beginArguments(Token token) {} 38 void beginArguments(Token token) {}
36 39
37 void endArguments(int count, Token beginToken, Token endToken) { 40 void endArguments(int count, Token beginToken, Token endToken) {
38 logEvent("Arguments"); 41 logEvent("Arguments");
39 } 42 }
40 43
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 /// recover, it should return a non-null continuation token whose `next` 1002 /// recover, it should return a non-null continuation token whose `next`
1000 /// pointer is the token the parser should continue from. Error recovery 1003 /// pointer is the token the parser should continue from. Error recovery
1001 /// is tightly coupled to the parser implementation, so to recover from an 1004 /// is tightly coupled to the parser implementation, so to recover from an
1002 /// error, one must carefully examine the code in the parser that generates 1005 /// error, one must carefully examine the code in the parser that generates
1003 /// the error. 1006 /// the error.
1004 /// 1007 ///
1005 /// If the listener can't recover, it can throw an exception or return 1008 /// If the listener can't recover, it can throw an exception or return
1006 /// `null`. In the latter case, the parser simply skips to EOF which will 1009 /// `null`. In the latter case, the parser simply skips to EOF which will
1007 /// often result in additional parser errors as the parser returns from its 1010 /// often result in additional parser errors as the parser returns from its
1008 /// recursive state. 1011 /// recursive state.
1009 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { 1012 Token handleUnrecoverableError(Token token, FastaMessage message) {
1010 throw new ParserError.fromTokens(token, token, kind, arguments); 1013 throw new ParserError.fromTokens(token, token, message);
1011 } 1014 }
1012 1015
1013 /// The parser noticed a syntax error, but was able to recover from it. 1016 /// The parser noticed a syntax error, but was able to recover from it.
1014 void handleRecoverableError(Token token, ErrorKind kind, Map arguments) { 1017 void handleRecoverableError(Token token, FastaMessage message) {
1015 recoverableErrors 1018 recoverableErrors.add(new ParserError.fromTokens(token, token, message));
1016 .add(new ParserError.fromTokens(token, token, kind, arguments));
1017 } 1019 }
1018 1020
1019 void handleScript(Token token) { 1021 void handleScript(Token token) {
1020 logEvent("Script"); 1022 logEvent("Script");
1021 } 1023 }
1022 1024
1023 /// Creates a new synthetic token whose `next` pointer points to [next]. 1025 /// Creates a new synthetic token whose `next` pointer points to [next].
1024 /// 1026 ///
1025 /// If [next] is `null`, `null` is returned. 1027 /// If [next] is `null`, `null` is returned.
1026 Token newSyntheticToken(Token next) { 1028 Token newSyntheticToken(Token next) {
1027 if (next == null) return null; 1029 if (next == null) return null;
1028 return new SymbolToken(RECOVERY_INFO, next.charOffset)..next = next; 1030 return new SymbolToken(RECOVERY_INFO, next.charOffset)..next = next;
1029 } 1031 }
1030 } 1032 }
1031 1033
1032 class ParserError { 1034 class ParserError {
1033 /// Character offset from the beginning of file where this error starts. 1035 /// Character offset from the beginning of file where this error starts.
1034 final int beginOffset; 1036 final int beginOffset;
1035 1037
1036 /// Character offset from the beginning of file where this error ends. 1038 /// Character offset from the beginning of file where this error ends.
1037 final int endOffset; 1039 final int endOffset;
1038 1040
1039 final ErrorKind kind; 1041 final FastaMessage message;
1040 1042
1041 final Map arguments; 1043 ParserError(this.beginOffset, this.endOffset, this.message);
1042 1044
1043 ParserError(this.beginOffset, this.endOffset, this.kind, this.arguments); 1045 ParserError.fromTokens(Token begin, Token end, FastaMessage message)
1046 : this(begin.charOffset, end.charOffset + end.charCount, message);
1044 1047
1045 ParserError.fromTokens(Token begin, Token end, ErrorKind kind, Map arguments) 1048 String toString() => "@${beginOffset}: ${message.message}\n${message.tip}";
1046 : this(begin.charOffset, end.charOffset + end.charCount, kind, arguments);
1047
1048 String toString() => "@${beginOffset}: $kind $arguments";
1049 } 1049 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/parser/error_kind.dart ('k') | pkg/front_end/lib/src/fasta/parser/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698