Esempio n. 1
0
def viz(ctx, grammar_file):
    debug = ctx.obj['debug']
    colors = ctx.obj['colors']
    t.colors = colors
    grammar, table = check_get_grammar_table(grammar_file, debug, colors)
    prints("Generating '%s.dot' file for the grammar PDA." % grammar_file)
    prints("Use dot viewer (e.g. xdot) "
           "or convert to pdf by running 'dot -Tpdf -O %s.dot'" % grammar_file)
    t.colors = False
    grammar_pda_export(table, "%s.dot" % grammar_file)
Esempio n. 2
0
def test_dot_export():
    grammar = 'S: S S | S S S | "b";'
    g = Grammar.from_string(grammar)

    table = create_table(g)

    f, file_name = mkstemp()
    grammar_pda_export(table, file_name)

    assert os.path.exists(file_name)
    with open(file_name) as f:
        assert 'label' in f.read()

    os.remove(file_name)
Esempio n. 3
0
def test_dot_export():
    grammar = 'S: S S | S S S | "b";'
    g = Grammar.from_string(grammar)

    table = create_table(g)

    tmp_dir = tempfile.mkdtemp()
    file_name = os.path.join(tmp_dir, 'testexport.dot')

    grammar_pda_export(table, file_name)

    with open(file_name) as f:
        assert 'label' in f.read()

    os.remove(file_name)
    os.rmdir(tmp_dir)