def vmlines(fhandle): with reset_seek(fhandle) as f: def normalize_whitespace(string): return re.sub('\s{2,}', ' ', string) for line in fhandle: cleaned_line = normalize_whitespace(remove_comments(line)) if cleaned_line: yield cleaned_line
def itertext(fhandle): """Yields stream of tuples (code_text, goto_label) - code_text non-empty code text - goto_label if code_text is a goto label then None, else the goto label """ def remove_whitespace(line): return re.sub(r'\s*', '', line) with reset_seek(fhandle) as f: for line in f: cleaned_code_line = remove_whitespace(remove_comments(line)) if cleaned_code_line: yield cleaned_code_line, goto_label_match(cleaned_code_line)