Files
sdk/pkg/vm_service/tool/common/generate_common.dart
T
Jacob MacDonald 88fdbea483 Update to the latest markdown, an internal Cl has been prepared and
paired with this so the sdk roll can succeed.

TEST=Fixes static errors

Change-Id: Ia4e325936ea81d0d51fbf6dd939b732860d22100
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183760
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2021-02-09 18:42:42 +00:00

31 lines
1.1 KiB
Dart

// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library generate_vm_service_common;
import 'package:markdown/markdown.dart';
import 'package:pub_semver/pub_semver.dart';
import 'src_gen_common.dart';
/// [ApiParseUtil] contains top level parsing utilities.
class ApiParseUtil {
/// Extract the current VM Service version number as a String.
static String parseVersionString(List<Node> nodes) =>
parseVersionSemVer(nodes).toString();
static Version parseVersionSemVer(List<Node> nodes) {
final RegExp regex = RegExp(r'[\d.]+');
// Extract version from header: `# Dart VM Service Protocol 2.0`.
Element node = nodes.firstWhere((n) => isH1(n)) as Element;
Text text = node.children![0] as Text;
Match? match = regex.firstMatch(text.text);
if (match == null) throw 'Unable to locate service protocol version';
// Append a `.0`.
return Version.parse('${match.group(0)}.0');
}
}