forked from dart-lang/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_parse.py
executable file
·44 lines (34 loc) · 1.55 KB
/
spec_parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
#
# Copyright (c) 2017, 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.
# This script runs the parser which is generated using ANTLR 4 from
# docs/language/Dart.g. It relies on a certain environment and is hence
# usable locally where this environment can be obtained, but it may not be
# possible to run it, e.g., on build bots. The requirements are as follows:
#
# - `make parser` in spec_parser has been executed successfully.
# - A suitable JVM is in the PATH and may be executed as 'java'.
# - the ANTLR3 jar is available as /usr/share/java/antlr4-runtime.jar.
import os
import subprocess
import sys
def Help(missing):
print('Execution of the spec parser failed. Missing: ' + missing)
print('Please read the comment near the top of spec_parse.py.\n')
sys.exit(1)
def Main():
args = sys.argv[1:]
tools_dir = os.path.dirname(os.path.realpath(__file__))
spec_parser_dir = os.path.join(tools_dir, 'spec_parser')
spec_parser_file = os.path.join(spec_parser_dir, 'SpecParser.class')
antlr_jar = '/usr/share/java/antlr4-runtime.jar'
class_path = ':'.join([spec_parser_dir, antlr_jar])
command = ['java', '-cp', class_path, 'SpecParser'] + args
if not os.path.exists(antlr_jar): Help(antlr_jar)
if not os.path.exists(spec_parser_file):
Help('"make parser" in spec_parser')
return subprocess.call(command)
if __name__ == '__main__':
sys.exit(Main())