| OLD | NEW |
| 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 '../../scanner/token.dart' show Token, TokenType; | 7 import '../../scanner/token.dart' show Token, TokenType; |
| 8 | 8 |
| 9 import '../fasta_codes.dart' show Message; | 9 import '../fasta_codes.dart' show Message; |
| 10 | 10 |
| 11 import '../util/link.dart' show Link; | 11 import '../util/link.dart' show Link; |
| 12 | 12 |
| 13 import 'assert.dart' show Assert; | 13 import 'assert.dart' show Assert; |
| 14 | 14 |
| 15 import 'formal_parameter_kind.dart' show FormalParameterKind; | 15 import 'formal_parameter_kind.dart' show FormalParameterKind; |
| 16 | 16 |
| 17 import 'identifier_context.dart' show IdentifierContext; | 17 import 'identifier_context.dart' show IdentifierContext; |
| 18 | 18 |
| 19 import 'member_kind.dart' show MemberKind; | 19 import 'member_kind.dart' show MemberKind; |
| 20 | 20 |
| 21 import 'parser_error.dart' show ParserError; | 21 import 'parser_error.dart' show ParserError; |
| 22 | 22 |
| 23 import 'token_stream_rewriter.dart'; |
| 24 |
| 23 /// A parser event listener that does nothing except throw exceptions | 25 /// A parser event listener that does nothing except throw exceptions |
| 24 /// on parser errors. | 26 /// on parser errors. |
| 25 /// | 27 /// |
| 26 /// Events are methods that begin with one of: `begin`, `end`, or `handle`. | 28 /// Events are methods that begin with one of: `begin`, `end`, or `handle`. |
| 27 /// | 29 /// |
| 28 /// Events starting with `begin` and `end` come in pairs. Normally, a | 30 /// Events starting with `begin` and `end` come in pairs. Normally, a |
| 29 /// `beginFoo` event is followed by an `endFoo` event. There's a few exceptions | 31 /// `beginFoo` event is followed by an `endFoo` event. There's a few exceptions |
| 30 /// documented below. | 32 /// documented below. |
| 31 /// | 33 /// |
| 32 /// Events starting with `handle` are used when isn't possible to have a begin | 34 /// Events starting with `handle` are used when isn't possible to have a begin |
| 33 /// event. | 35 /// event. |
| 34 class Listener { | 36 class Listener { |
| 35 final List<ParserError> recoverableErrors = <ParserError>[]; | 37 final List<ParserError> recoverableErrors = <ParserError>[]; |
| 36 | 38 |
| 39 /// The first token in the parse stream and used during parser recovery. |
| 40 /// This is automatically set by the [beginCompilationUnit] event, |
| 41 /// but must be manually set when parsing anything smaller. |
| 42 Token firstToken; |
| 43 |
| 44 /// A rewriter for inserting synthetic tokens. |
| 45 /// Access using [rewriter] for lazy initialization. |
| 46 TokenStreamRewriter _tokenRewriter; |
| 47 |
| 48 TokenStreamRewriter get rewriter { |
| 49 assert(firstToken != null, 'firstToken must be set for parser recovery'); |
| 50 _tokenRewriter ??= new TokenStreamRewriter(firstToken); |
| 51 return _tokenRewriter; |
| 52 } |
| 53 |
| 54 Listener(); |
| 55 |
| 37 Uri get uri => null; | 56 Uri get uri => null; |
| 38 | 57 |
| 39 void logEvent(String name) {} | 58 void logEvent(String name) {} |
| 40 | 59 |
| 41 set suppressParseErrors(bool value) {} | 60 set suppressParseErrors(bool value) {} |
| 42 | 61 |
| 43 void beginArguments(Token token) {} | 62 void beginArguments(Token token) {} |
| 44 | 63 |
| 45 void endArguments(int count, Token beginToken, Token endToken) { | 64 void endArguments(int count, Token beginToken, Token endToken) { |
| 46 logEvent("Arguments"); | 65 logEvent("Arguments"); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 Token endToken) { | 124 Token endToken) { |
| 106 logEvent("ClassDeclaration"); | 125 logEvent("ClassDeclaration"); |
| 107 } | 126 } |
| 108 | 127 |
| 109 void beginCombinators(Token token) {} | 128 void beginCombinators(Token token) {} |
| 110 | 129 |
| 111 void endCombinators(int count) { | 130 void endCombinators(int count) { |
| 112 logEvent("Combinators"); | 131 logEvent("Combinators"); |
| 113 } | 132 } |
| 114 | 133 |
| 115 void beginCompilationUnit(Token token) {} | 134 void beginCompilationUnit(Token token) { |
| 135 firstToken = token; |
| 136 } |
| 116 | 137 |
| 117 void endCompilationUnit(int count, Token token) { | 138 void endCompilationUnit(int count, Token token) { |
| 118 logEvent("CompilationUnit"); | 139 logEvent("CompilationUnit"); |
| 119 } | 140 } |
| 120 | 141 |
| 121 void beginConstLiteral(Token token) {} | 142 void beginConstLiteral(Token token) {} |
| 122 | 143 |
| 123 void endConstLiteral(Token token) { | 144 void endConstLiteral(Token token) { |
| 124 logEvent("ConstLiteral"); | 145 logEvent("ConstLiteral"); |
| 125 } | 146 } |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 void discardTypeReplacedWithCommentTypeAssign() {} | 1141 void discardTypeReplacedWithCommentTypeAssign() {} |
| 1121 | 1142 |
| 1122 /// Creates a new synthetic token whose `next` pointer points to [next]. | 1143 /// Creates a new synthetic token whose `next` pointer points to [next]. |
| 1123 /// | 1144 /// |
| 1124 /// If [next] is `null`, `null` is returned. | 1145 /// If [next] is `null`, `null` is returned. |
| 1125 Token newSyntheticToken(Token next) { | 1146 Token newSyntheticToken(Token next) { |
| 1126 if (next == null) return null; | 1147 if (next == null) return null; |
| 1127 return new Token(TokenType.RECOVERY, next.charOffset)..next = next; | 1148 return new Token(TokenType.RECOVERY, next.charOffset)..next = next; |
| 1128 } | 1149 } |
| 1129 } | 1150 } |
| OLD | NEW |