mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-15 07:49:31 -06:00
started a graphviz visualization for the LR(0) automaton
This commit is contained in:
@@ -3137,3 +3137,30 @@ pgf_align_words(PgfDB *db, PgfConcrRevision revision,
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PGF_API PgfText *
|
||||
pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision,
|
||||
PgfExn *err)
|
||||
{
|
||||
PGF_API_BEGIN {
|
||||
DB_scope scope(db, READER_SCOPE);
|
||||
|
||||
ref<PgfConcr> concr = db->revision2concr(revision);
|
||||
|
||||
PgfPrinter printer(NULL,0,NULL);
|
||||
|
||||
printer.puts("digraph {");
|
||||
for (size_t i = 0; i < concr->lrtable->len; i++) {
|
||||
ref<PgfLRState> state = vector_elem(concr->lrtable, i);
|
||||
for (size_t j = 0; j < state->shifts->len; j++) {
|
||||
ref<PgfLRShift> shift = vector_elem(state->shifts, j);
|
||||
printer.nprintf(16, " s%zu -> s%zu;\n", i, shift->next_state);
|
||||
}
|
||||
}
|
||||
printer.puts("}");
|
||||
|
||||
return printer.get_text();
|
||||
} PGF_API_END
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -906,4 +906,8 @@ pgf_align_words(PgfDB *db, PgfConcrRevision revision,
|
||||
size_t *n_phrases /* out */,
|
||||
PgfExn* err);
|
||||
|
||||
PGF_API PgfText *
|
||||
pgf_graphviz_lr_automaton(PgfDB *db, PgfConcrRevision revision,
|
||||
PgfExn *err);
|
||||
|
||||
#endif // PGF_H_
|
||||
|
||||
@@ -72,7 +72,7 @@ module PGF2 (-- * PGF
|
||||
graphvizAbstractTree, graphvizParseTree,
|
||||
Labels, getDepLabels,
|
||||
graphvizDependencyTree, conlls2latexDoc, getCncDepLabels,
|
||||
graphvizWordAlignment,
|
||||
graphvizWordAlignment, graphvizLRAutomaton,
|
||||
|
||||
-- * Concrete syntax
|
||||
ConcName,Concr,languages,concreteName,languageCode,concreteFlag,
|
||||
@@ -1389,6 +1389,15 @@ graphvizDependencyTree
|
||||
-> String -- ^ Rendered output in the specified format
|
||||
graphvizDependencyTree format debug mlab mclab concr t = error "TODO: graphvizDependencyTree"
|
||||
|
||||
graphvizLRAutomaton :: Concr -> String
|
||||
graphvizLRAutomaton c =
|
||||
unsafePerformIO $
|
||||
withForeignPtr (c_revision c) $ \c_revision ->
|
||||
bracket (withPgfExn "graphvizLRAutomaton" (pgf_graphviz_lr_automaton (c_db c) c_revision)) free $ \c_text ->
|
||||
if c_text == nullPtr
|
||||
then return ""
|
||||
else peekText c_text
|
||||
|
||||
---------------------- should be a separate module?
|
||||
|
||||
-- visualization with latex output. AR Nov 2015
|
||||
|
||||
@@ -315,6 +315,8 @@ foreign import ccall pgf_graphviz_parse_tree :: Ptr PgfDB -> Ptr Concr -> Stable
|
||||
|
||||
foreign import ccall pgf_graphviz_word_alignment :: Ptr PgfDB -> Ptr (Ptr Concr) -> CSize -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfGraphvizOptions -> Ptr PgfExn -> IO (Ptr PgfText)
|
||||
|
||||
foreign import ccall pgf_graphviz_lr_automaton :: Ptr PgfDB -> Ptr Concr -> Ptr PgfExn -> IO (Ptr PgfText)
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Texts
|
||||
|
||||
Reference in New Issue
Block a user