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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart
diff --git a/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart b/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7f2605361d807d4d3c7585fc631ea46afb0130df
--- /dev/null
+++ b/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart
@@ -0,0 +1,56 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
ahe 2017/02/03 17:26:42 It's 2017.
ahe 2017/02/06 10:17:54 Done.
+// for details. All rights reserved. Use of this source code is governed by a
ahe 2017/02/03 17:26:42 Add note to listener events about these helper met
ahe 2017/02/06 10:17:54 Done.
+// BSD-style license that can be found in the LICENSE file.
+
+/// Implements support for Dart VM native method bodies on this form:
+///
+/// native STRING
Siggi Cherem (dart-lang) 2017/02/03 17:18:52 consider adding one more sentence saying that this
ahe 2017/02/06 10:17:54 Done.
+library fasta.parser.dart_vm_native;
+
+import '../scanner/token.dart' show
+ Token;
+
+import '../scanner/token_constants.dart' show
+ STRING_TOKEN;
+
+import '../util/link.dart' show
+ Link;
+
+import 'parser.dart' show
+ optional;
+
+/// When parsing a Dart VM library file, we may encounter a native clause
+/// instead of a function body. This method skips such a clause.
+///
+/// This method is designed to be called when encountering
+/// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError].
+Token skipNativeClause(Token token) {
+ if (!optional("native", token)) return null;
+ token = token.next;
+ if (token.kind != STRING_TOKEN) return null;
+ token = token.next;
+ if (!optional(";", token)) return null;
+ return token;
+}
+
+/// When parsing a Dart VM library file, we may encounter native getters like
+///
+/// int get length native "List_getLength";
+///
+/// This will result in [identifiers] being
+///
+/// [";", '"List_getLength"', "native", "length", "get"]
+///
+/// We need to remove '"List_getLength"' and "native" from that list.
+///
+/// This method designed to be called from [Listener.handleMemberName].
+Link<Token> removeNativeClause(Link<Token> identifiers) {
+ Link<Token> result = identifiers.tail;
+ if (result.head.kind != STRING_TOKEN) return identifiers;
+ result = result.tail;
+ if (result.isEmpty) return identifiers;
+ if (optional('native', result.head)) {
+ return result.tail.prepend(identifiers.head);
+ }
+ return identifiers;
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698