11 lines
425 B
Python
11 lines
425 B
Python
import subprocess
|
|
import json
|
|
class ParserError(Exception):
|
|
pass
|
|
class Parser:
|
|
def parse(self,tokens):
|
|
result = subprocess.run(['./parse.exe'], input=json.dumps(tokens, indent=4).encode('utf-8'),stdout=subprocess.PIPE)
|
|
ast = json.loads(result.stdout.decode('utf-8'))
|
|
if "error" in ast:
|
|
raise ParserError(f"{ast['message']}")
|
|
return json.loads(result.stdout.decode('utf-8')) |