11import argparse
2+ import os
23import re
34import sys
45import time
78from OWScript .Parser import Parser
89from OWScript .Transpiler import Transpiler
910
10- def transpile (text , args ):
11+ def transpile (text , path , args ):
1112 """Transpiles an OWScript code into Overwatch Workshop rules."""
1213 start = time .time ()
1314 Errors .TEXT = text
@@ -23,7 +24,7 @@ def transpile(text, args):
2324 tree = parser .script ()
2425 if args .tree :
2526 print (tree .string ())
26- transpiler = Transpiler (tree = tree )
27+ transpiler = Transpiler (tree = tree , path = path )
2728 code = transpiler .run ()
2829 if args .min :
2930 code = re .sub (r'[\s\n]*' , '' , code )
@@ -50,10 +51,15 @@ def transpile(text, args):
5051 parser .add_argument ('--tokens' , action = 'store_true' , help = 'Debug: shows the tokens created by the lexer' )
5152 parser .add_argument ('--tree' , action = 'store_true' , help = 'Debug: visualizes the AST generated by the parser' )
5253 args = parser .parse_args ()
53- file_input = args .input [0 ] if args .input else sys .stdin
54- with open (file_input ) as f :
55- text = f .read ()
54+ if args .input :
55+ file_input = args .input [0 ]
56+ path = os .path .abspath (file_input )
57+ with open (path ) as f :
58+ text = f .read ()
59+ else :
60+ text = sys .stdin .read ()
61+ path = os .getcwd ()
5662 try :
57- transpile (text , args = args )
63+ transpile (text , path = path , args = args )
5864 except Errors .OWSError as ex :
5965 print ('Error:' , ex )
0 commit comments