-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax_checker.py
48 lines (36 loc) · 1.07 KB
/
syntax_checker.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
45
46
47
48
from typing import List, Tuple
from os import listdir
from os.path import isfile, join
from lark import LarkError
from parser.parser import decaf_parser
def _get_inputs(dir_: str, current_files: List[str]):
sub_folders = []
for content in listdir(dir_):
abs_path = join(dir_, content)
if isfile(abs_path):
if content.endswith('.d'):
current_files.append(abs_path)
else:
sub_folders.append(abs_path)
for sub_folder in sub_folders:
_get_inputs(sub_folder, current_files)
def get_inputs(dir_: str) -> List[str]:
inputs = []
_get_inputs(dir_, inputs)
return inputs
def run_test_case(code):
tree = decaf_parser.parse(code)
def main():
test_folder = 'tests'
inputs = get_inputs(test_folder)
bugs = []
for input in inputs:
try:
with open(input, mode='r') as f:
run_test_case(f.read())
except LarkError:
bugs.append(input)
print(f'there are {len(bugs)} bugs')
print(bugs)
if __name__ == '__main__':
main()