def p_error(p): if p is None: raise InternalBentoError( "Unknown parsing error (parser/lexer bug ? Please report this with your bento.info)" ) else: msg = "yacc: Syntax error at line %d, Token(%s, %r)" % \ (p.lineno, p.type, p.value) if hasattr(p.lexer, "lexdata"): data = p.lexer.lexdata.splitlines() msg += "\n\t%r" % (data[p.lineno - 1], ) raise ParseError(msg, p)
def raw_to_subpkg_kw(raw_dict): d = build_ast_from_raw_dict(raw_dict) libraries_d, misc_d = extract_top_dicts_subento(deepcopy(d)) kw = {} libraries = build_libs_from_dict(libraries_d) kw.update(libraries) kw["hook_files"] = misc_d["hook_files"] sub_directory = kw.pop("sub_directory") if sub_directory is not None: raise InternalBentoError("Unexpected sub_directory while parsing recursed bendo") return kw, misc_d["subento"]
def p_error(p): if p is None: raise InternalBentoError( "Unknown parsing error (parser/lexer bug ? Please report this with your bento.info)" ) else: msg = "yacc: Syntax error at line %d, Token(%s, %r)" % \ (p.lineno, p.type, p.value) if hasattr(p.lexer, "lexdata"): raw_data = p.lexer.lexdata data = raw_data.splitlines() line_lexpos = sum(len(line) + 1 for line in data[:p.lineno - 1]) inline_lexpos = p.lexpos - line_lexpos msg += "\n%s" % (data[p.lineno - 1], ) msg += "\n%s" % (" " * inline_lexpos + "^", ) raise ParseError(msg, p)
def post_process_string(it): """Remove spurious spacing from *MULTILINE_STRING tokens.""" it = BackwardGenerator(it) for token in it: if token.type == "BLOCK_MULTILINES_STRING": previous = it.previous() if not previous.type == "INDENT": raise InternalBentoError( "Error while post processing block line: %s -> %s" \ % (previous, token)) else: indent = previous.value token.value = remove_lines_indent(token.value, indent) token.type = "MULTILINES_STRING" elif token.type == "MULTILINES_STRING": token.value = remove_lines_indent(token.value) yield token