OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /// Implements support for Dart VM native method bodies of this form: | |
6 /// | |
7 /// native STRING | |
8 /// | |
9 /// This support is kept separate from parser.dart as this isn't specified in | |
10 /// the Dart Language Specification, also we hope to remove this syntax long | |
11 /// term and replace it with annotations as in `dart2js`. | |
12 library fasta.parser.dart_vm_native; | |
13 | |
14 import '../../scanner/token.dart' show Token; | |
15 | |
16 import '../scanner/token_constants.dart' show STRING_TOKEN; | |
17 | |
18 import '../util/link.dart' show Link; | |
19 | |
20 import 'parser.dart' show optional; | |
21 | |
22 /// When parsing a Dart VM library file, we may encounter a native clause | |
23 /// instead of a function body. This method skips such a clause. | |
24 /// | |
25 /// This method is designed to be called when encountering | |
26 /// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError]. | |
27 Token skipNativeClause(Token token) { | |
28 if (!optional("native", token)) return null; | |
29 token = token.next; | |
30 if (token.kind != STRING_TOKEN) return null; | |
31 if (!optional(";", token.next)) return null; | |
32 return token; | |
33 } | |
34 | |
35 /// When parsing a Dart VM library file, we may encounter native getters like | |
36 /// | |
37 /// int get length native "List_getLength"; | |
38 /// | |
39 /// This will result in [identifiers] being | |
40 /// | |
41 /// [";", '"List_getLength"', "native", "length", "get"] | |
42 /// | |
43 /// We need to remove '"List_getLength"' and "native" from that list. | |
44 /// | |
45 /// This method designed to be called from [Listener.handleMemberName]. | |
46 Link<Token> removeNativeClause(Link<Token> identifiers) { | |
47 Link<Token> result = identifiers.tail; | |
48 if (result.isEmpty) return identifiers; | |
49 if (result.head.kind != STRING_TOKEN) return identifiers; | |
50 result = result.tail; | |
51 if (result.isEmpty) return identifiers; | |
52 if (optional('native', result.head)) { | |
53 return result.tail.prepend(identifiers.head); | |
54 } | |
55 return identifiers; | |
56 } | |
OLD | NEW |