def subst(s, ns): if isinstance(s, str): tree = texparse.parse(s) else: tree = s new_tree = traverse(tree, ns) s = texparse.unparse(new_tree, True) return s
def assert_is_single_token(frm, lno, **kw): fs = texparse.parse(frm) if len(fs) != 1: raise RuntimeError( "line %d: key '%s' should have only one token but has %s" % (lno + 1, frm, fs))