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

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

Issue 2676813002: Add helper methods for skipping Dart VM native bodies. (Closed)
Patch Set: Update documentation. Created 3 years, 10 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
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/parser/error_kind.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 on 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
15 Token;
16
17 import '../scanner/token_constants.dart' show
18 STRING_TOKEN;
19
20 import '../util/link.dart' show
21 Link;
22
23 import 'parser.dart' show
24 optional;
25
26 /// When parsing a Dart VM library file, we may encounter a native clause
27 /// instead of a function body. This method skips such a clause.
28 ///
29 /// This method is designed to be called when encountering
30 /// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError].
31 Token skipNativeClause(Token token) {
32 if (!optional("native", token)) return null;
33 token = token.next;
34 if (token.kind != STRING_TOKEN) return null;
35 token = token.next;
36 if (!optional(";", token)) return null;
37 return token;
38 }
39
40 /// When parsing a Dart VM library file, we may encounter native getters like
41 ///
42 /// int get length native "List_getLength";
43 ///
44 /// This will result in [identifiers] being
45 ///
46 /// [";", '"List_getLength"', "native", "length", "get"]
47 ///
48 /// We need to remove '"List_getLength"' and "native" from that list.
49 ///
50 /// This method designed to be called from [Listener.handleMemberName].
51 Link<Token> removeNativeClause(Link<Token> identifiers) {
52 Link<Token> result = identifiers.tail;
53 if (result.head.kind != STRING_TOKEN) return identifiers;
54 result = result.tail;
55 if (result.isEmpty) return identifiers;
56 if (optional('native', result.head)) {
57 return result.tail.prepend(identifiers.head);
58 }
59 return identifiers;
60 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/parser/error_kind.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698