def trace(path): from bookish.grammars.wiki import blocks from bookish.parser import parser, rules pages = flaskapp.get_wikipages(manager.app) src = pages.content(path) src = wikipages.condition_string(src) lines = parser.Lines(src) ctx = wikipages.bootstrap_context() i = 0 while not rules.streamend.at_end(src, i): out, newi = blocks(src, i, ctx) print(i, out, newi) if not isinstance(out, dict): line, col = lines.line_and_col(i) print("Miss at line", line, "column", col, "(char %s)" % i) print(repr(src[i:])) break if newi == i: line, col = lines.line_and_col(i) print("Stall at line", line, "column", col, "(char %s)" % i) print(repr(src[i:])) break i = newi
def debug_wiki(path): from bookish.grammars.wiki import blocks from bookish.parser import parser, rules pages = flaskapp.get_wikipages(manager.app) src = wikipages.condition_string(pages.content(path)) ctx = wikipages.bootstrap_context() i = 0 blist = [] t = util.perf_counter() missed = False while rules.streamend.accept(src, i, ctx)[0] is parser.Miss: tt = util.perf_counter() out, newi = blocks(src, i, ctx) tt = util.perf_counter() - tt if not isinstance(out, dict): lines = parser.Lines(src) line, col = lines.line_and_col(i) print("Miss at line", line, "column", col, "(char %s)" % i) print(repr(src[i:i+10])) missed = True break i = newi blist.append((tt, out.get("type"), repr(functions.string(out.get("text"))[:40]))) t = util.perf_counter() - t print("%0.06f" % t) if not missed: blist.sort(reverse=True) for tt, typename, txt in blist: print("%0.06f" % tt, typename, txt)