1818from typing import NamedTuple , List
1919
2020from .zxbpplex import tokens # noqa
21- from . import zxbpplex , zxbasmpplex
22- from ply import yacc
21+ from . import zxbpplex
22+ from . import zxbasmpplex
23+ from src .ply import yacc
2324
2425from src .api .config import OPTIONS
2526from src .api import global_
2627import src .api .utils
28+
29+ from .prepro import output
2730from .prepro .output import warning
2831from .prepro .output import error
29- from .prepro .output import CURRENT_FILE
3032from .prepro import DefinesTable , ID , MacroCall , Arg , ArgList
3133from .prepro .exceptions import PreprocError
3234
@@ -75,7 +77,6 @@ def init():
7577 global ENABLED
7678 global IFDEFS
7779 global ID_TABLE
78- global CURRENT_FILE
7980
8081 OPTIONS .add_option_if_not_defined ('debug_zxbpp' , bool , False )
8182 global_ .FILENAME = '(stdin)'
@@ -88,7 +89,7 @@ def init():
8889 global_ .error_msg_cache .clear ()
8990 parser .defaulted_states = {}
9091 ID_TABLE = DefinesTable ()
91- del CURRENT_FILE [:]
92+ del output . CURRENT_FILE [:]
9293
9394
9495def get_include_path ():
@@ -152,16 +153,15 @@ def include_file(filename, lineno, local_first):
152153 This is used when doing a #include "filename".
153154 """
154155 global CURRENT_DIR
155- global CURRENT_FILE
156156
157157 filename = search_filename (filename , lineno , local_first )
158158 if filename not in INCLUDED .keys ():
159159 INCLUDED [filename ] = []
160160
161- if len (CURRENT_FILE ) > 0 : # Added from which file, line
162- INCLUDED [filename ].append ((CURRENT_FILE [- 1 ], lineno ))
161+ if len (output . CURRENT_FILE ) > 0 : # Added from which file, line
162+ INCLUDED [filename ].append ((output . CURRENT_FILE [- 1 ], lineno ))
163163
164- CURRENT_FILE .append (filename )
164+ output . CURRENT_FILE .append (filename )
165165 CURRENT_DIR = os .path .dirname (filename )
166166 return LEXER .include (filename )
167167
@@ -284,8 +284,8 @@ def p_include_file(p):
284284 """
285285 global CURRENT_DIR
286286 p [0 ] = [p [1 ] + p [2 ]] + p [3 ] + [p [4 ]]
287- CURRENT_FILE .pop () # Remove top of the stack
288- CURRENT_DIR = os .path .dirname (CURRENT_FILE [- 1 ])
287+ output . CURRENT_FILE .pop () # Remove top of the stack
288+ CURRENT_DIR = os .path .dirname (output . CURRENT_FILE [- 1 ])
289289
290290
291291def p_include_file_empty (p ):
@@ -305,8 +305,8 @@ def p_include_once_ok(p):
305305 """
306306 global CURRENT_DIR
307307 p [0 ] = [p [1 ] + p [2 ]] + p [3 ] + [p [4 ]]
308- CURRENT_FILE .pop () # Remove top of the stack
309- CURRENT_DIR = os .path .dirname (CURRENT_FILE [- 1 ])
308+ output . CURRENT_FILE .pop () # Remove top of the stack
309+ CURRENT_DIR = os .path .dirname (output . CURRENT_FILE [- 1 ])
310310
311311
312312def p_include (p ):
@@ -422,7 +422,7 @@ def p_define(p):
422422 warning (p .lineno (1 ), "missing whitespace after the macro name" )
423423
424424 ID_TABLE .define (p [2 ], args = p [3 ], value = p [4 ], lineno = p .lineno (2 ),
425- fname = CURRENT_FILE [- 1 ])
425+ fname = output . CURRENT_FILE [- 1 ])
426426 p [0 ] = []
427427
428428
@@ -437,7 +437,7 @@ def p_define_params_empty(p):
437437 """
438438 # Defines the 'epsilon' parameter
439439 p [0 ] = [ID ('' , value = '' , args = None , lineno = p .lineno (1 ),
440- fname = CURRENT_FILE [- 1 ])]
440+ fname = output . CURRENT_FILE [- 1 ])]
441441
442442
443443def p_define_params_paramlist (p ):
@@ -464,14 +464,14 @@ def p_paramlist_single(p):
464464 """ paramlist : ID
465465 """
466466 p [0 ] = [ID (p [1 ], value = '' , args = None , lineno = p .lineno (1 ),
467- fname = CURRENT_FILE [- 1 ])]
467+ fname = output . CURRENT_FILE [- 1 ])]
468468
469469
470470def p_paramlist_paramlist (p ):
471471 """ paramlist : paramlist COMMA ID
472472 """
473473 p [0 ] = p [1 ] + [ID (p [3 ], value = '' , args = None , lineno = p .lineno (1 ),
474- fname = CURRENT_FILE [- 1 ])]
474+ fname = output . CURRENT_FILE [- 1 ])]
475475
476476
477477def p_pragma_id (p ):
@@ -505,7 +505,7 @@ def p_ifdef(p):
505505 else :
506506 p [0 ] = []
507507
508- p [0 ] += ['#line %i "%s"' % (p .lineno (4 ) + 1 , CURRENT_FILE [- 1 ])]
508+ p [0 ] += ['#line %i "%s"' % (p .lineno (4 ) + 1 , output . CURRENT_FILE [- 1 ])]
509509 ENABLED = IFDEFS .pop ().enabled
510510
511511
@@ -520,7 +520,7 @@ def p_ifdef_else(p):
520520 else :
521521 p [0 ] = []
522522
523- p [0 ] += ['#line %i "%s"' % (p .lineno (3 ) + 1 , CURRENT_FILE [- 1 ])]
523+ p [0 ] += ['#line %i "%s"' % (p .lineno (3 ) + 1 , output . CURRENT_FILE [- 1 ])]
524524
525525
526526def p_ifdef_else_a (p ):
@@ -541,7 +541,7 @@ def p_ifdef_else_b(p):
541541 global ENABLED
542542
543543 if ENABLED :
544- p [0 ] = ['#line %i "%s"%s' % (p .lineno (1 ) + 1 , CURRENT_FILE [- 1 ], p [2 ])]
544+ p [0 ] = ['#line %i "%s"%s' % (p .lineno (1 ) + 1 , output . CURRENT_FILE [- 1 ], p [2 ])]
545545 p [0 ] += p [3 ]
546546 else :
547547 p [0 ] = []
@@ -757,12 +757,12 @@ def filter_(input_, filename='<internal>', state='INITIAL'):
757757 global CURRENT_DIR
758758
759759 prev_dir = CURRENT_DIR
760- CURRENT_FILE .append (filename )
761- CURRENT_DIR = os .path .dirname (CURRENT_FILE [- 1 ])
760+ output . CURRENT_FILE .append (filename )
761+ CURRENT_DIR = os .path .dirname (output . CURRENT_FILE [- 1 ])
762762 LEXER .input (input_ , filename )
763763 LEXER .lex .begin (state )
764764 parser .parse (lexer = LEXER , debug = OPTIONS .debug_zxbpp )
765- CURRENT_FILE .pop ()
765+ output . CURRENT_FILE .pop ()
766766 CURRENT_DIR = prev_dir
767767
768768
@@ -774,10 +774,10 @@ def main(argv):
774774 set_include_path ()
775775
776776 if argv :
777- CURRENT_FILE .append (argv [0 ])
777+ output . CURRENT_FILE .append (argv [0 ])
778778 else :
779- CURRENT_FILE .append (global_ .FILENAME )
780- CURRENT_DIR = os .path .dirname (CURRENT_FILE [- 1 ])
779+ output . CURRENT_FILE .append (global_ .FILENAME )
780+ CURRENT_DIR = os .path .dirname (output . CURRENT_FILE [- 1 ])
781781
782782 if OPTIONS .Sinclair :
783783 included_file = search_filename ('sinclair.bas' , 0 , local_first = False )
@@ -789,17 +789,17 @@ def main(argv):
789789 OUTPUT += '\n '
790790
791791 parser .parse (lexer = LEXER , debug = OPTIONS .debug_zxbpp )
792- CURRENT_FILE .pop ()
793- CURRENT_DIR = os .path .dirname (CURRENT_FILE [- 1 ])
792+ output . CURRENT_FILE .pop ()
793+ CURRENT_DIR = os .path .dirname (output . CURRENT_FILE [- 1 ])
794794
795795 prev_file = global_ .FILENAME
796- global_ .FILENAME = CURRENT_FILE [- 1 ]
797- OUTPUT += LEXER .include (CURRENT_FILE [- 1 ])
796+ global_ .FILENAME = output . CURRENT_FILE [- 1 ]
797+ OUTPUT += LEXER .include (output . CURRENT_FILE [- 1 ])
798798 if len (OUTPUT ) and OUTPUT [- 1 ] != '\n ' :
799799 OUTPUT += '\n '
800800
801801 parser .parse (lexer = LEXER , debug = OPTIONS .debug_zxbpp )
802- CURRENT_FILE .pop ()
802+ output . CURRENT_FILE .pop ()
803803 global_ .FILENAME = prev_file
804804 return global_ .has_errors
805805
0 commit comments