<gh_stars>1-10
import argparse
from drake.lexer import lex
from drake.parser import Parser

parser = argparse.ArgumentParser(description='Compile or interpret a Drake program.')
parser.add_argument('cmd', choices=['build', 'run'])
parser.add_argument('file')
parser.add_argument('-o', '--output', action='store', dest='output', type=str)

args = parser.parse_args()

try:
    with open(args.file) as f:
        input_file = f.read()

    ast = Parser(lex(input_file)).ast

    if args.output:
        with open(args.output, 'w+') as f:
            f.write(ast.pprint())
    else:
        print(ast.pprint())

except FileNotFoundError:
    print(f'Could not find `{args.file}`')

import argparse
from drake.lexer import lex
from drake.parser import Parser

parser = argparse.ArgumentParser(description='Compile or interpret a Drake program.')
parser.add_argument('cmd', choices=['build', 'run'])
parser.add_argument('file')
parser.add_argument('-o', '--output', action='store', dest='output', type=str)

args = parser.parse_args()

try:
    with open(args.file) as f:
        input_file = f.read()

    ast = Parser(lex(input_file)).ast

    if args.output:
        with open(args.output, 'w+') as f:
            f.write(ast.pprint())
    else:
        print(ast.pprint())

except FileNotFoundError:
    print(f'Could not find `{args.file}`')