OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /// Implements support for two variants of the native syntax extension. | 5 /// Implements support for two variants of the native syntax extension. |
6 /// | 6 /// |
7 /// * The Dart VM variant, where native method bodies have this form: | 7 /// * The Dart VM variant, where native method bodies have this form: |
8 /// | 8 /// |
9 /// methodDeclaration() native STRING; | 9 /// methodDeclaration() native STRING; |
10 /// | 10 /// |
11 /// * The Dart2js and DDC variant, where native method bodies have this form: | 11 /// * The Dart2js and DDC variant, where native method bodies have this form: |
12 /// | 12 /// |
13 /// methodDeclaration() native; | 13 /// methodDeclaration() native; |
14 /// | 14 /// |
15 /// This support is kept separate from parser.dart as this isn't specified in | 15 /// This support is kept separate from parser.dart as this isn't specified in |
16 /// the Dart Language Specification, also we hope to remove this syntax long | 16 /// the Dart Language Specification, also we hope to remove this syntax long |
17 /// term and replace it with annotations and external declarations. | 17 /// term and replace it with annotations and external declarations. |
18 library fasta.parser.dart_vm_native; | 18 library fasta.parser.dart_vm_native; |
19 | 19 |
20 import '../../scanner/token.dart' show Token; | 20 import '../../scanner/token.dart' show Token; |
21 | 21 |
| 22 import '../quote.dart' show unescapeString; |
| 23 |
22 import '../scanner/token_constants.dart' show STRING_TOKEN; | 24 import '../scanner/token_constants.dart' show STRING_TOKEN; |
23 | 25 |
24 import '../util/link.dart' show Link; | 26 import '../util/link.dart' show Link; |
25 | 27 |
26 import 'parser.dart' show optional; | 28 import 'util.dart' show optional; |
27 | |
28 import '../quote.dart' show unescapeString; | |
29 | 29 |
30 /// When parsing a library file, we may encounter a native clause | 30 /// When parsing a library file, we may encounter a native clause |
31 /// instead of a function body. This method skips such a clause. The | 31 /// instead of a function body. This method skips such a clause. The |
32 /// [expectString] argument is used to choose which variant of the native clause | 32 /// [expectString] argument is used to choose which variant of the native clause |
33 /// we expect to parse. | 33 /// we expect to parse. |
34 /// | 34 /// |
35 /// This method is designed to be called when encountering | 35 /// This method is designed to be called when encountering |
36 /// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError]. | 36 /// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError]. |
37 Token skipNativeClause(Token token, bool expectString) { | 37 Token skipNativeClause(Token token, bool expectString) { |
38 if (!optional("native", token)) return null; | 38 if (!optional("native", token)) return null; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 return identifiers; | 78 return identifiers; |
79 } | 79 } |
80 | 80 |
81 /// When the parser encounters a native clause and expects a string (like in VM | 81 /// When the parser encounters a native clause and expects a string (like in VM |
82 /// and flutter patch files), this method extracts the native name in that | 82 /// and flutter patch files), this method extracts the native name in that |
83 /// string. | 83 /// string. |
84 String extractNativeMethodName(Token token) { | 84 String extractNativeMethodName(Token token) { |
85 return unescapeString(token.next.lexeme); | 85 return unescapeString(token.next.lexeme); |
86 } | 86 } |
OLD | NEW |