forked from GitHub/gf-core
added bracketedLinearizeAll
This commit is contained in:
@@ -91,6 +91,10 @@ void PgfLinearizationGraphvizOutput::symbol_bind()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PgfLinearizationGraphvizOutput::flush()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void PgfLinearizationGraphvizOutput::generate_graphviz_level(PgfPrinter *printer, PgfGraphvizOptions* opts, ParseLevel *level)
|
void PgfLinearizationGraphvizOutput::generate_graphviz_level(PgfPrinter *printer, PgfGraphvizOptions* opts, ParseLevel *level)
|
||||||
{
|
{
|
||||||
printer->puts("\n subgraph {\n rank=same;\n");
|
printer->puts("\n subgraph {\n rank=same;\n");
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public:
|
|||||||
virtual void end_phrase(PgfText *cat, int fid, PgfText *ann, PgfText *fun);
|
virtual void end_phrase(PgfText *cat, int fid, PgfText *ann, PgfText *fun);
|
||||||
virtual void symbol_ne();
|
virtual void symbol_ne();
|
||||||
virtual void symbol_bind();
|
virtual void symbol_bind();
|
||||||
|
virtual void flush();
|
||||||
};
|
};
|
||||||
|
|
||||||
class PGF_INTERNAL_DECL PgfAbstractGraphvizOutput : public PgfUnmarshaller {
|
class PGF_INTERNAL_DECL PgfAbstractGraphvizOutput : public PgfUnmarshaller {
|
||||||
|
|||||||
@@ -763,3 +763,7 @@ void PgfLinearizationOutput::symbol_bind()
|
|||||||
{
|
{
|
||||||
bind = true;
|
bind = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PgfLinearizationOutput::flush()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
virtual void end_phrase(PgfText *cat, int fid, PgfText *ann, PgfText *fun);
|
virtual void end_phrase(PgfText *cat, int fid, PgfText *ann, PgfText *fun);
|
||||||
virtual void symbol_ne();
|
virtual void symbol_ne();
|
||||||
virtual void symbol_bind();
|
virtual void symbol_bind();
|
||||||
|
virtual void flush();
|
||||||
};
|
};
|
||||||
|
|
||||||
class PGF_INTERNAL_DECL PgfLinearizer : public PgfUnmarshaller {
|
class PGF_INTERNAL_DECL PgfLinearizer : public PgfUnmarshaller {
|
||||||
|
|||||||
@@ -2140,6 +2140,27 @@ void pgf_bracketed_linearize(PgfDB *db, PgfConcrRevision revision,
|
|||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API_DECL
|
||||||
|
void pgf_bracketed_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
|
PgfMarshaller *m,
|
||||||
|
PgfLinearizationOutputIface *out,
|
||||||
|
PgfExn* err)
|
||||||
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
|
DB_scope scope(db, READER_SCOPE);
|
||||||
|
|
||||||
|
ref<PgfConcr> concr = PgfDB::revision2concr(revision);
|
||||||
|
PgfLinearizer linearizer(ctxt, concr, m);
|
||||||
|
m->match_expr(&linearizer, expr);
|
||||||
|
linearizer.reverse_and_label(true);
|
||||||
|
while (linearizer.resolve()) {
|
||||||
|
linearizer.linearize(out, 0);
|
||||||
|
out->flush();
|
||||||
|
}
|
||||||
|
} PGF_API_END
|
||||||
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfText *pgf_get_printname(PgfDB *db, PgfConcrRevision revision,
|
PgfText *pgf_get_printname(PgfDB *db, PgfConcrRevision revision,
|
||||||
PgfText *fun, PgfExn* err)
|
PgfText *fun, PgfExn* err)
|
||||||
|
|||||||
@@ -599,6 +599,9 @@ struct PgfLinearizationOutputIface
|
|||||||
|
|
||||||
/// token binding
|
/// token binding
|
||||||
virtual void symbol_bind()=0;
|
virtual void symbol_bind()=0;
|
||||||
|
|
||||||
|
/// called when the current linearization is finished
|
||||||
|
virtual void flush()=0;
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
typedef struct PgfLinearizationOutputIface PgfLinearizationOutputIface;
|
typedef struct PgfLinearizationOutputIface PgfLinearizationOutputIface;
|
||||||
@@ -619,6 +622,9 @@ struct PgfLinearizationOutputIfaceVtbl
|
|||||||
|
|
||||||
/// token binding
|
/// token binding
|
||||||
void (*symbol_bind)(PgfLinearizationOutputIface *this);
|
void (*symbol_bind)(PgfLinearizationOutputIface *this);
|
||||||
|
|
||||||
|
/// called when the current linearization is finished
|
||||||
|
void (*flush)(PgfLinearizationOutputIface *this);
|
||||||
};
|
};
|
||||||
struct PgfLinearizationOutputIface
|
struct PgfLinearizationOutputIface
|
||||||
{
|
{
|
||||||
@@ -632,12 +638,12 @@ PgfText *pgf_linearize(PgfDB *db, PgfConcrRevision revision,
|
|||||||
PgfMarshaller *m,
|
PgfMarshaller *m,
|
||||||
PgfExn* err);
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API
|
PGF_API_DECL
|
||||||
PgfText **pgf_tabular_linearize(PgfDB *db, PgfConcrRevision revision,
|
PgfText **pgf_tabular_linearize(PgfDB *db, PgfConcrRevision revision,
|
||||||
PgfExpr expr, PgfPrintContext *ctxt,
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
PgfMarshaller *m, PgfExn* err);
|
PgfMarshaller *m, PgfExn* err);
|
||||||
|
|
||||||
PGF_API
|
PGF_API_DECL
|
||||||
PgfText **pgf_tabular_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
PgfText **pgf_tabular_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
||||||
PgfExpr expr, PgfPrintContext *ctxt,
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
PgfMarshaller *m, PgfExn* err);
|
PgfMarshaller *m, PgfExn* err);
|
||||||
@@ -649,6 +655,13 @@ void pgf_bracketed_linearize(PgfDB *db, PgfConcrRevision revision,
|
|||||||
PgfLinearizationOutputIface *out,
|
PgfLinearizationOutputIface *out,
|
||||||
PgfExn* err);
|
PgfExn* err);
|
||||||
|
|
||||||
|
PGF_API_DECL
|
||||||
|
void pgf_bracketed_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
|
PgfMarshaller *m,
|
||||||
|
PgfLinearizationOutputIface *out,
|
||||||
|
PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfText *pgf_get_printname(PgfDB *db, PgfConcrRevision revision,
|
PgfText *pgf_get_printname(PgfDB *db, PgfConcrRevision revision,
|
||||||
PgfText *fun, PgfExn* err);
|
PgfText *fun, PgfExn* err);
|
||||||
|
|||||||
@@ -736,11 +736,13 @@ bracketedLinearize c e = unsafePerformIO $ do
|
|||||||
bracket (wrapSymbol2 (end_phrase ref)) freeHaskellFunPtr $ \c_end_phrase ->
|
bracket (wrapSymbol2 (end_phrase ref)) freeHaskellFunPtr $ \c_end_phrase ->
|
||||||
bracket (wrapSymbol0 (symbol_bind ref)) freeHaskellFunPtr $ \c_symbol_bind ->
|
bracket (wrapSymbol0 (symbol_bind ref)) freeHaskellFunPtr $ \c_symbol_bind ->
|
||||||
bracket (wrapSymbol0 (symbol_ne ref)) freeHaskellFunPtr $ \c_symbol_ne -> do
|
bracket (wrapSymbol0 (symbol_ne ref)) freeHaskellFunPtr $ \c_symbol_ne -> do
|
||||||
|
bracket (wrapSymbol0 (flush ref)) freeHaskellFunPtr $ \c_flush -> do
|
||||||
(#poke PgfLinearizationOutputIfaceVtbl, symbol_token) vtbl c_symbol_token
|
(#poke PgfLinearizationOutputIfaceVtbl, symbol_token) vtbl c_symbol_token
|
||||||
(#poke PgfLinearizationOutputIfaceVtbl, begin_phrase) vtbl c_begin_phrase
|
(#poke PgfLinearizationOutputIfaceVtbl, begin_phrase) vtbl c_begin_phrase
|
||||||
(#poke PgfLinearizationOutputIfaceVtbl, end_phrase) vtbl c_end_phrase
|
(#poke PgfLinearizationOutputIfaceVtbl, end_phrase) vtbl c_end_phrase
|
||||||
(#poke PgfLinearizationOutputIfaceVtbl, symbol_bind) vtbl c_symbol_bind
|
(#poke PgfLinearizationOutputIfaceVtbl, symbol_bind) vtbl c_symbol_bind
|
||||||
(#poke PgfLinearizationOutputIfaceVtbl, symbol_ne) vtbl c_symbol_ne
|
(#poke PgfLinearizationOutputIfaceVtbl, symbol_ne) vtbl c_symbol_ne
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, flush) vtbl c_flush
|
||||||
(#poke PgfLinearizationOutputIface, vtbl) c_out vtbl
|
(#poke PgfLinearizationOutputIface, vtbl) c_out vtbl
|
||||||
withPgfExn "bracketedLinearize" (pgf_bracketed_linearize (c_db c) c_revision c_e nullPtr m c_out))
|
withPgfExn "bracketedLinearize" (pgf_bracketed_linearize (c_db c) c_revision c_e nullPtr m c_out))
|
||||||
(ne,_,bs) <- readIORef ref
|
(ne,_,bs) <- readIORef ref
|
||||||
@@ -775,8 +777,66 @@ bracketedLinearize c e = unsafePerformIO $ do
|
|||||||
(ne,stack,bs) <- readIORef ref
|
(ne,stack,bs) <- readIORef ref
|
||||||
writeIORef ref (True,[],[])
|
writeIORef ref (True,[],[])
|
||||||
|
|
||||||
|
flush _ _ = return ()
|
||||||
|
|
||||||
bracketedLinearizeAll :: Concr -> Expr -> [[BracketedString]]
|
bracketedLinearizeAll :: Concr -> Expr -> [[BracketedString]]
|
||||||
bracketedLinearizeAll = error "TODO: bracketedLinearizeAll"
|
bracketedLinearizeAll c e = unsafePerformIO $ do
|
||||||
|
ref <- newIORef (False,[],[],[])
|
||||||
|
(withForeignPtr (c_revision c) $ \c_revision ->
|
||||||
|
bracket (newStablePtr e) freeStablePtr $ \c_e ->
|
||||||
|
withForeignPtr marshaller $ \m ->
|
||||||
|
allocaBytes (#size PgfLinearizationOutputIface) $ \c_out ->
|
||||||
|
allocaBytes (#size PgfLinearizationOutputIfaceVtbl) $ \vtbl ->
|
||||||
|
bracket (wrapSymbol1 (symbol_token ref)) freeHaskellFunPtr $ \c_symbol_token ->
|
||||||
|
bracket (wrapSymbol2 (begin_phrase ref)) freeHaskellFunPtr $ \c_begin_phrase ->
|
||||||
|
bracket (wrapSymbol2 (end_phrase ref)) freeHaskellFunPtr $ \c_end_phrase ->
|
||||||
|
bracket (wrapSymbol0 (symbol_bind ref)) freeHaskellFunPtr $ \c_symbol_bind ->
|
||||||
|
bracket (wrapSymbol0 (symbol_ne ref)) freeHaskellFunPtr $ \c_symbol_ne -> do
|
||||||
|
bracket (wrapSymbol0 (flush ref)) freeHaskellFunPtr $ \c_flush -> do
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, symbol_token) vtbl c_symbol_token
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, begin_phrase) vtbl c_begin_phrase
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, end_phrase) vtbl c_end_phrase
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, symbol_bind) vtbl c_symbol_bind
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, symbol_ne) vtbl c_symbol_ne
|
||||||
|
(#poke PgfLinearizationOutputIfaceVtbl, flush) vtbl c_flush
|
||||||
|
(#poke PgfLinearizationOutputIface, vtbl) c_out vtbl
|
||||||
|
withPgfExn "bracketedLinearizeAll" (pgf_bracketed_linearize_all (c_db c) c_revision c_e nullPtr m c_out))
|
||||||
|
(_,_,_,all) <- readIORef ref
|
||||||
|
return all
|
||||||
|
where
|
||||||
|
symbol_token ref _ c_text = do
|
||||||
|
(ne,stack,bs,all) <- readIORef ref
|
||||||
|
token <- peekText c_text
|
||||||
|
writeIORef ref (ne,stack,Leaf token : bs,all)
|
||||||
|
|
||||||
|
begin_phrase ref _ c_cat c_fid c_ann c_fun = do
|
||||||
|
(ne,stack,bs,all) <- readIORef ref
|
||||||
|
writeIORef ref (ne,bs:stack,[],all)
|
||||||
|
|
||||||
|
end_phrase ref _ c_cat c_fid c_ann c_fun = do
|
||||||
|
(ne,bs':stack,bs,all) <- readIORef ref
|
||||||
|
if null bs
|
||||||
|
then writeIORef ref (ne,stack,bs',all)
|
||||||
|
else do cat <- peekText c_cat
|
||||||
|
let fid = fromIntegral c_fid
|
||||||
|
ann <- peekText c_ann
|
||||||
|
fun <- peekText c_fun
|
||||||
|
writeIORef ref (ne,stack,Bracket cat fid ann fun (reverse bs) : bs',all)
|
||||||
|
|
||||||
|
symbol_bind ref _ = do
|
||||||
|
(ne,stack,bs,all) <- readIORef ref
|
||||||
|
writeIORef ref (ne,stack,BIND : bs,all)
|
||||||
|
|
||||||
|
symbol_ne ref _ = do
|
||||||
|
(ne,stack,bs,all) <- readIORef ref
|
||||||
|
writeIORef ref (True,[],[],all)
|
||||||
|
|
||||||
|
flush ref _ = do
|
||||||
|
(ne,_,bs,all) <- readIORef ref
|
||||||
|
if ne
|
||||||
|
then writeIORef ref (False,[],[],all)
|
||||||
|
else writeIORef ref (False,[],[],reverse bs:all)
|
||||||
|
|
||||||
|
|
||||||
generateAll :: PGF -> Type -> [(Expr,Float)]
|
generateAll :: PGF -> Type -> [(Expr,Float)]
|
||||||
generateAll p ty = error "TODO: generateAll"
|
generateAll p ty = error "TODO: generateAll"
|
||||||
|
|||||||
@@ -217,6 +217,8 @@ foreign import ccall pgf_tabular_linearize_all :: Ptr PgfDB -> Ptr Concr -> Stab
|
|||||||
|
|
||||||
foreign import ccall pgf_bracketed_linearize :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfLinearizationOutputIface -> Ptr PgfExn -> IO ()
|
foreign import ccall pgf_bracketed_linearize :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfLinearizationOutputIface -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
|
foreign import ccall pgf_bracketed_linearize_all :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfLinearizationOutputIface -> Ptr PgfExn -> IO ()
|
||||||
|
|
||||||
foreign import ccall "wrapper" wrapSymbol0 :: Wrapper (Ptr PgfLinearizationOutputIface -> IO ())
|
foreign import ccall "wrapper" wrapSymbol0 :: Wrapper (Ptr PgfLinearizationOutputIface -> IO ())
|
||||||
|
|
||||||
foreign import ccall "wrapper" wrapSymbol1 :: Wrapper (Ptr PgfLinearizationOutputIface -> Ptr PgfText -> IO ())
|
foreign import ccall "wrapper" wrapSymbol1 :: Wrapper (Ptr PgfLinearizationOutputIface -> Ptr PgfText -> IO ())
|
||||||
|
|||||||
Reference in New Issue
Block a user