mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-08 10:42:50 -06:00
a number of new API functions for the concrete syntax.
This commit is contained in:
@@ -106,6 +106,9 @@ typedef struct {
|
||||
|
||||
struct PGF_INTERNAL_DECL PgfConcrLincat {
|
||||
size_t ref_count;
|
||||
|
||||
ref<PgfAbsCat> abscat;
|
||||
|
||||
ref<Vector<ref<PgfText>>> fields;
|
||||
PgfText name;
|
||||
|
||||
|
||||
@@ -955,6 +955,56 @@ void pgf_drop_concrete(PgfDB *db, PgfRevision revision,
|
||||
} PGF_API_END
|
||||
}
|
||||
|
||||
PGF_API
|
||||
void pgf_create_lincat(PgfDB *db,
|
||||
PgfRevision revision, PgfConcrRevision cnc_revision,
|
||||
PgfText *name, size_t n_fields, PgfExn *err)
|
||||
{
|
||||
PGF_API_BEGIN {
|
||||
DB_scope scope(db, WRITER_SCOPE);
|
||||
|
||||
ref<PgfPGF> pgf = PgfDB::revision2pgf(revision);
|
||||
ref<PgfConcr> concr = PgfDB::revision2concr(cnc_revision);
|
||||
|
||||
ref<PgfAbsCat> abscat =
|
||||
namespace_lookup(pgf->abstract.cats, name);
|
||||
if (abscat == 0) {
|
||||
throw pgf_error("There is no corresponding category in the abstract syntax");
|
||||
}
|
||||
|
||||
ref<PgfConcrLincat> lincat = PgfDB::malloc<PgfConcrLincat>(name->size+1);
|
||||
memcpy(&lincat->name, name, sizeof(PgfText)+name->size+1);
|
||||
lincat->ref_count = 1;
|
||||
lincat->abscat = abscat;
|
||||
lincat->fields = vector_new<ref<PgfText>>(n_fields);
|
||||
|
||||
for (size_t i = 0; i < n_fields; i++) {
|
||||
}
|
||||
|
||||
Namespace<PgfConcrLincat> lincats =
|
||||
namespace_insert(concr->lincats, lincat);
|
||||
namespace_release(concr->lincats);
|
||||
concr->lincats = lincats;
|
||||
} PGF_API_END
|
||||
}
|
||||
|
||||
PGF_API
|
||||
void pgf_drop_lincat(PgfDB *db,
|
||||
PgfConcrRevision revision,
|
||||
PgfText *name, PgfExn *err)
|
||||
{
|
||||
PGF_API_BEGIN {
|
||||
DB_scope scope(db, WRITER_SCOPE);
|
||||
|
||||
ref<PgfConcr> concr = PgfDB::revision2concr(revision);
|
||||
|
||||
Namespace<PgfConcrLincat> lincats =
|
||||
namespace_delete(concr->lincats, name);
|
||||
namespace_release(concr->lincats);
|
||||
concr->lincats = lincats;
|
||||
} PGF_API_END
|
||||
}
|
||||
|
||||
PGF_API
|
||||
void pgf_create_lin(PgfDB *db,
|
||||
PgfRevision revision, PgfConcrRevision cnc_revision,
|
||||
@@ -996,6 +1046,41 @@ void pgf_create_lin(PgfDB *db,
|
||||
} PGF_API_END
|
||||
}
|
||||
|
||||
PGF_API
|
||||
void pgf_drop_lin(PgfDB *db,
|
||||
PgfConcrRevision revision,
|
||||
PgfText *name, PgfExn *err)
|
||||
{
|
||||
PGF_API_BEGIN {
|
||||
DB_scope scope(db, WRITER_SCOPE);
|
||||
|
||||
ref<PgfConcr> concr = PgfDB::revision2concr(revision);
|
||||
|
||||
Namespace<PgfConcrLin> lins =
|
||||
namespace_delete(concr->lins, name);
|
||||
namespace_release(concr->lins);
|
||||
concr->lins = lins;
|
||||
} PGF_API_END
|
||||
}
|
||||
|
||||
PGF_API
|
||||
int pgf_has_linearization(PgfDB *db, PgfConcrRevision revision,
|
||||
PgfText *name, PgfExn *err)
|
||||
{
|
||||
PGF_API_BEGIN {
|
||||
DB_scope scope(db, READER_SCOPE);
|
||||
|
||||
ref<PgfConcr> concr = PgfDB::revision2concr(revision);
|
||||
|
||||
ref<PgfConcrLin> lin =
|
||||
namespace_lookup(concr->lins, name);
|
||||
|
||||
return (lin != 0);
|
||||
} PGF_API_END
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfLiteral pgf_get_global_flag(PgfDB *db, PgfRevision revision,
|
||||
PgfText *name,
|
||||
|
||||
@@ -418,11 +418,28 @@ void pgf_drop_concrete(PgfDB *db, PgfRevision revision,
|
||||
PgfText *name,
|
||||
PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
void pgf_create_lincat(PgfDB *db,
|
||||
PgfRevision revision, PgfConcrRevision cnc_revision,
|
||||
PgfText *name, size_t n_fields, PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
void pgf_drop_lincat(PgfDB *db, PgfConcrRevision revision,
|
||||
PgfText *name, PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
void pgf_create_lin(PgfDB *db,
|
||||
PgfRevision revision, PgfConcrRevision cnc_revision,
|
||||
PgfText *name, size_t n_prods, PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
void pgf_drop_lin(PgfDB *db, PgfConcrRevision revision,
|
||||
PgfText *name, PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
int pgf_has_linearization(PgfDB *db, PgfConcrRevision revision,
|
||||
PgfText *name, PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
PgfLiteral pgf_get_global_flag(PgfDB *db, PgfRevision revision,
|
||||
PgfText *name,
|
||||
|
||||
@@ -544,6 +544,7 @@ ref<PgfConcrLincat> PgfReader::read_lincat()
|
||||
{
|
||||
ref<PgfConcrLincat> lincat = read_name(&PgfConcrLincat::name);
|
||||
lincat->ref_count = 1;
|
||||
lincat->abscat = namespace_lookup(abstract->cats, &lincat->name);
|
||||
lincat->fields = read_vector(&PgfReader::read_text2);
|
||||
return lincat;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user