mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
added tabularLinearizeAll
This commit is contained in:
@@ -2049,8 +2049,7 @@ PgfText **pgf_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
|||||||
PGF_API
|
PGF_API
|
||||||
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, size_t *n_fields,
|
PgfMarshaller *m, PgfExn* err)
|
||||||
PgfExn* err)
|
|
||||||
{
|
{
|
||||||
PGF_API_BEGIN {
|
PGF_API_BEGIN {
|
||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
@@ -2063,19 +2062,19 @@ PgfText **pgf_tabular_linearize(PgfDB *db, PgfConcrRevision revision,
|
|||||||
if (linearizer.resolve()) {
|
if (linearizer.resolve()) {
|
||||||
ref<PgfConcrLincat> lincat = linearizer.get_lincat();
|
ref<PgfConcrLincat> lincat = linearizer.get_lincat();
|
||||||
PgfText **res = (PgfText **)
|
PgfText **res = (PgfText **)
|
||||||
malloc(lincat->fields->len*2*sizeof(PgfText*));
|
malloc((lincat->fields->len+1)*2*sizeof(PgfText*));
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
for (size_t i = 0; i < lincat->fields->len; i++) {
|
for (size_t i = 0; i < lincat->fields->len; i++) {
|
||||||
linearizer.linearize(&out, i);
|
linearizer.linearize(&out, i);
|
||||||
|
|
||||||
PgfText *text = out.get_text();
|
PgfText *text = out.get_text();
|
||||||
if (text != NULL) {
|
if (text != NULL) {
|
||||||
res[pos] = textdup(&(*lincat->fields->data[i]));
|
res[pos++] = textdup(&(*lincat->fields->data[i]));
|
||||||
res[pos+1] = text;
|
res[pos++] = text;
|
||||||
pos += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*n_fields = pos/2;
|
res[pos++] = NULL;
|
||||||
|
res[pos++] = NULL;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
@@ -2083,6 +2082,44 @@ PgfText **pgf_tabular_linearize(PgfDB *db, PgfConcrRevision revision,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API
|
||||||
|
PgfText **pgf_tabular_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
|
PgfMarshaller *m, PgfExn* err)
|
||||||
|
{
|
||||||
|
PGF_API_BEGIN {
|
||||||
|
DB_scope scope(db, READER_SCOPE);
|
||||||
|
|
||||||
|
ref<PgfConcr> concr = PgfDB::revision2concr(revision);
|
||||||
|
PgfLinearizationOutput out;
|
||||||
|
PgfLinearizer linearizer(ctxt, concr, m);
|
||||||
|
m->match_expr(&linearizer, expr);
|
||||||
|
linearizer.reverse_and_label(false);
|
||||||
|
|
||||||
|
size_t pos = 0;
|
||||||
|
PgfText **res = NULL;
|
||||||
|
while (linearizer.resolve()) {
|
||||||
|
ref<PgfConcrLincat> lincat = linearizer.get_lincat();
|
||||||
|
res = (PgfText **)
|
||||||
|
realloc(res, (pos+(lincat->fields->len+1)*2)*sizeof(PgfText*));
|
||||||
|
for (size_t i = 0; i < lincat->fields->len; i++) {
|
||||||
|
linearizer.linearize(&out, i);
|
||||||
|
|
||||||
|
PgfText *text = out.get_text();
|
||||||
|
if (text != NULL) {
|
||||||
|
res[pos++] = textdup(&(*lincat->fields->data[i]));
|
||||||
|
res[pos++] = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res[pos++] = NULL;
|
||||||
|
}
|
||||||
|
res[pos++] = NULL;
|
||||||
|
return res;
|
||||||
|
} PGF_API_END
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_bracketed_linearize(PgfDB *db, PgfConcrRevision revision,
|
void pgf_bracketed_linearize(PgfDB *db, PgfConcrRevision revision,
|
||||||
PgfExpr expr, PgfPrintContext *ctxt,
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
|
|||||||
@@ -635,8 +635,12 @@ PgfText *pgf_linearize(PgfDB *db, PgfConcrRevision revision,
|
|||||||
PGF_API
|
PGF_API
|
||||||
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, size_t *n_fields,
|
PgfMarshaller *m, PgfExn* err);
|
||||||
PgfExn* err);
|
|
||||||
|
PGF_API
|
||||||
|
PgfText **pgf_tabular_linearize_all(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
PgfExpr expr, PgfPrintContext *ctxt,
|
||||||
|
PgfMarshaller *m, PgfExn* err);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_bracketed_linearize(PgfDB *db, PgfConcrRevision revision,
|
void pgf_bracketed_linearize(PgfDB *db, PgfConcrRevision revision,
|
||||||
|
|||||||
@@ -647,25 +647,43 @@ tabularLinearize c e =
|
|||||||
withForeignPtr (c_revision c) $ \c_revision ->
|
withForeignPtr (c_revision c) $ \c_revision ->
|
||||||
bracket (newStablePtr e) freeStablePtr $ \c_e ->
|
bracket (newStablePtr e) freeStablePtr $ \c_e ->
|
||||||
withForeignPtr marshaller $ \m ->
|
withForeignPtr marshaller $ \m ->
|
||||||
alloca $ \p_n_fields ->
|
bracket (withPgfExn "tabularLinearize" (pgf_tabular_linearize (c_db c) c_revision c_e nullPtr m)) free peekTable
|
||||||
bracket (withPgfExn "tabularLinearize" (pgf_tabular_linearize (c_db c) c_revision c_e nullPtr m p_n_fields)) free $ \c_texts -> do
|
|
||||||
n_fields <- peek p_n_fields
|
|
||||||
peekTable n_fields c_texts
|
|
||||||
where
|
where
|
||||||
peekTable 0 c_texts = return []
|
peekTable c_texts = do
|
||||||
peekTable n c_texts = do
|
c_field <- peekElemOff c_texts 0
|
||||||
c_field <- peek c_texts
|
c_lin <- peekElemOff c_texts 1
|
||||||
field <- peekText c_field
|
if c_field == nullPtr && c_lin == nullPtr
|
||||||
free c_field
|
then return []
|
||||||
c_lin <- peek (c_texts `plusPtr` (#size PgfText*))
|
else do field <- peekText c_field
|
||||||
lin <- peekText c_lin
|
free c_field
|
||||||
free c_lin
|
lin <- peekText c_lin
|
||||||
table <- peekTable (n-1) (c_texts `plusPtr` (2*(#size PgfText*)))
|
free c_lin
|
||||||
return ((field,lin):table)
|
table <- peekTable (c_texts `plusPtr` (2*(#size PgfText*)))
|
||||||
|
return ((field,lin):table)
|
||||||
|
|
||||||
-- | Generates a table of linearizations for an expression
|
-- | Generates a table of linearizations for an expression
|
||||||
tabularLinearizeAll :: Concr -> Expr -> [[(String, String)]]
|
tabularLinearizeAll :: Concr -> Expr -> [[(String, String)]]
|
||||||
tabularLinearizeAll lang e = error "TODO: tabularLinearizeAll"
|
tabularLinearizeAll c e =
|
||||||
|
unsafePerformIO $
|
||||||
|
withForeignPtr (c_revision c) $ \c_revision ->
|
||||||
|
bracket (newStablePtr e) freeStablePtr $ \c_e ->
|
||||||
|
withForeignPtr marshaller $ \m ->
|
||||||
|
bracket (withPgfExn "tabularLinearizeAll" (pgf_tabular_linearize_all (c_db c) c_revision c_e nullPtr m)) free peekTables
|
||||||
|
where
|
||||||
|
peekTables c_texts = do
|
||||||
|
c_field <- peekElemOff c_texts 0
|
||||||
|
c_lin <- peekElemOff c_texts 1
|
||||||
|
if c_field == nullPtr && c_lin == nullPtr
|
||||||
|
then return [[]]
|
||||||
|
else if c_field == nullPtr
|
||||||
|
then do tables <- peekTables (c_texts `plusPtr` (#size PgfText*))
|
||||||
|
return ([]:tables)
|
||||||
|
else do field <- peekText c_field
|
||||||
|
free c_field
|
||||||
|
lin <- peekText c_lin
|
||||||
|
free c_lin
|
||||||
|
(table:tables) <- peekTables (c_texts `plusPtr` (2*(#size PgfText*)))
|
||||||
|
return (((field,lin):table):tables)
|
||||||
|
|
||||||
type FId = Int
|
type FId = Int
|
||||||
|
|
||||||
|
|||||||
@@ -211,7 +211,9 @@ foreign import ccall pgf_linearize :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -
|
|||||||
|
|
||||||
foreign import ccall pgf_linearize_all :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr CSize -> Ptr PgfExn -> IO (Ptr (Ptr PgfText))
|
foreign import ccall pgf_linearize_all :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr CSize -> Ptr PgfExn -> IO (Ptr (Ptr PgfText))
|
||||||
|
|
||||||
foreign import ccall pgf_tabular_linearize :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr CSize -> Ptr PgfExn -> IO (Ptr (Ptr PgfText))
|
foreign import ccall pgf_tabular_linearize :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfExn -> IO (Ptr (Ptr PgfText))
|
||||||
|
|
||||||
|
foreign import ccall pgf_tabular_linearize_all :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr -> Ptr PgfPrintContext -> Ptr PgfMarshaller -> Ptr PgfExn -> IO (Ptr (Ptr PgfText))
|
||||||
|
|
||||||
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 ()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user