def p_include_once_ok(p): """ include_file : include_once NEWLINE program _ENDFILE_ """ global CURRENT_DIR p[0] = [p[1] + p[2]] + p[3] + [p[4]] CURRENT_FILE.pop() # Remove top of the stack CURRENT_DIR = os.path.dirname(CURRENT_FILE[-1])
def main(argv): global OUTPUT, ID_TABLE, ENABLED, CURRENT_DIR ENABLED = True OUTPUT = '' if argv: CURRENT_FILE.append(argv[0]) else: CURRENT_FILE.append(global_.FILENAME) CURRENT_DIR = os.path.dirname(CURRENT_FILE[-1]) if OPTIONS.Sinclair.value: included_file = search_filename('sinclair.bas', 0, local_first=False) if not included_file: return OUTPUT += include_once(included_file, 0, local_first=False) if len(OUTPUT) and OUTPUT[-1] != '\n': OUTPUT += '\n' parser.parse(lexer=LEXER, debug=OPTIONS.Debug.value > 2) CURRENT_FILE.pop() CURRENT_DIR = os.path.dirname(CURRENT_FILE[-1]) prev_file = global_.FILENAME global_.FILENAME = CURRENT_FILE[-1] OUTPUT += LEXER.include(CURRENT_FILE[-1]) if len(OUTPUT) and OUTPUT[-1] != '\n': OUTPUT += '\n' parser.parse(lexer=LEXER, debug=OPTIONS.Debug.value > 2) CURRENT_FILE.pop() global_.FILENAME = prev_file return global_.has_errors
def filter_(input_, filename='<internal>', state='INITIAL'): """ Filter the input string thought the preprocessor. result is appended to OUTPUT global str """ global CURRENT_DIR prev_dir = CURRENT_DIR CURRENT_FILE.append(filename) CURRENT_DIR = os.path.dirname(CURRENT_FILE[-1]) LEXER.input(input_, filename) LEXER.lex.begin(state) parser.parse(lexer=LEXER, debug=OPTIONS.Debug.value > 2) CURRENT_FILE.pop() CURRENT_DIR = prev_dir
def include_file(filename, lineno, local_first): """ Performs a file inclusion (#include) in the preprocessor. Writes down that "filename" was included at the current file, at line <lineno>. If local_first is True, then it will first search the file in the local path before looking for it in the include path chain. This is used when doing a #include "filename". """ global CURRENT_DIR filename = search_filename(filename, lineno, local_first) if filename not in INCLUDED.keys(): INCLUDED[filename] = [] if len(CURRENT_FILE) > 0: # Added from which file, line INCLUDED[filename].append((CURRENT_FILE[-1], lineno)) CURRENT_FILE.append(filename) CURRENT_DIR = os.path.dirname(filename) return LEXER.include(filename)