mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-09 19:22:50 -06:00
added startCat
This commit is contained in:
@@ -161,13 +161,47 @@ PgfText *pgf_abstract_name(PgfPGF* pgf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
void pgf_iter_categories(PgfPGF* pgf, PgfItor* itor)
|
void pgf_iter_categories(PgfPGF *pgf, PgfItor *itor)
|
||||||
{
|
{
|
||||||
DB_scope scope(pgf, READER_SCOPE);
|
DB_scope scope(pgf, READER_SCOPE);
|
||||||
|
|
||||||
namespace_iter(pgf->get_root<PgfPGFRoot>()->abstract.cats, itor);
|
namespace_iter(pgf->get_root<PgfPGFRoot>()->abstract.cats, itor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API
|
||||||
|
uintptr_t pgf_start_cat(PgfPGF *pgf)
|
||||||
|
{
|
||||||
|
DB_scope scope(pgf, READER_SCOPE);
|
||||||
|
|
||||||
|
PgfText *startcat = (PgfText *)
|
||||||
|
alloca(sizeof(PgfText)+9);
|
||||||
|
startcat->size = 8;
|
||||||
|
strcpy(startcat->text, "startcat");
|
||||||
|
|
||||||
|
ref<PgfFlag> flag =
|
||||||
|
namespace_lookup(pgf->get_root<PgfPGFRoot>()->abstract.aflags, startcat);
|
||||||
|
|
||||||
|
if (flag != 0) {
|
||||||
|
switch (ref<PgfLiteral>::get_tag(flag->value)) {
|
||||||
|
case PgfLiteralStr::tag: {
|
||||||
|
auto lstr = ref<PgfLiteralStr>::untagged(flag->value);
|
||||||
|
|
||||||
|
uintptr_t type = pgf_read_type(&lstr->val, pgf->u);
|
||||||
|
if (type == 0)
|
||||||
|
break;
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PgfText *s = (PgfText *)
|
||||||
|
alloca(sizeof(PgfText)+2);
|
||||||
|
s->size = 1;
|
||||||
|
s->text[0] = 'S';
|
||||||
|
s->text[1] = 0;
|
||||||
|
return pgf->u->dtyp(0,NULL,s,0,NULL);
|
||||||
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos)
|
PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -157,10 +157,13 @@ PGF_API_DECL
|
|||||||
void pgf_free(PgfPGF *pgf);
|
void pgf_free(PgfPGF *pgf);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfText *pgf_abstract_name(PgfPGF* pgf);
|
PgfText *pgf_abstract_name(PgfPGF *pgf);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
void pgf_iter_categories(PgfPGF* pgf, PgfItor* itor);
|
void pgf_iter_categories(PgfPGF *pgf, PgfItor *itor);
|
||||||
|
|
||||||
|
PGF_API_DECL
|
||||||
|
uintptr_t pgf_start_cat(PgfPGF *pgf);
|
||||||
|
|
||||||
PGF_API_DECL PgfTypeHypo*
|
PGF_API_DECL PgfTypeHypo*
|
||||||
pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos);
|
pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module PGF ( PGF2.PGF, readPGF
|
|||||||
|
|
||||||
, CId, mkCId, wildCId, showCId, readCId
|
, CId, mkCId, wildCId, showCId, readCId
|
||||||
|
|
||||||
, categories
|
, PGF2.categories, PGF2.categoryContext, PGF2.startCat
|
||||||
, functions, functionsByCat
|
, functions, functionsByCat
|
||||||
|
|
||||||
, PGF2.Expr(..), PGF2.Literal(..), Tree
|
, PGF2.Expr(..), PGF2.Literal(..), Tree
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ module PGF2 (-- * PGF
|
|||||||
mkFloat, unFloat,
|
mkFloat, unFloat,
|
||||||
mkMeta, unMeta,
|
mkMeta, unMeta,
|
||||||
-- ** Types
|
-- ** Types
|
||||||
Type(..), Hypo, BindType(..),
|
Type(..), Hypo, BindType(..), startCat,
|
||||||
readType,
|
readType,
|
||||||
mkType, unType,
|
mkType, unType,
|
||||||
mkHypo, mkDepHypo, mkImplHypo,
|
mkHypo, mkDepHypo, mkImplHypo,
|
||||||
@@ -139,6 +139,20 @@ abstractName p =
|
|||||||
bracket (pgf_abstract_name p_pgf) free $ \c_text ->
|
bracket (pgf_abstract_name p_pgf) free $ \c_text ->
|
||||||
peekText c_text
|
peekText c_text
|
||||||
|
|
||||||
|
-- | The start category is defined in the grammar with
|
||||||
|
-- the \'startcat\' flag. This is usually the sentence category
|
||||||
|
-- but it is not necessary. Despite that there is a start category
|
||||||
|
-- defined you can parse with any category. The start category
|
||||||
|
-- definition is just for convenience.
|
||||||
|
startCat :: PGF -> Type
|
||||||
|
startCat p =
|
||||||
|
unsafePerformIO $
|
||||||
|
withForeignPtr (a_pgf p) $ \c_pgf -> do
|
||||||
|
c_typ <- pgf_start_cat c_pgf
|
||||||
|
typ <- deRefStablePtr c_typ
|
||||||
|
freeStablePtr c_typ
|
||||||
|
return typ
|
||||||
|
|
||||||
-- | The type of a function
|
-- | The type of a function
|
||||||
functionType :: PGF -> Fun -> Maybe Type
|
functionType :: PGF -> Fun -> Maybe Type
|
||||||
functionType p fn =
|
functionType p fn =
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ foreign import ccall "wrapper"
|
|||||||
foreign import ccall "pgf_iter_categories"
|
foreign import ccall "pgf_iter_categories"
|
||||||
pgf_iter_categories :: Ptr PgfPGF -> Ptr PgfItor -> IO ()
|
pgf_iter_categories :: Ptr PgfPGF -> Ptr PgfItor -> IO ()
|
||||||
|
|
||||||
|
foreign import ccall "pgf_start_cat"
|
||||||
|
pgf_start_cat :: Ptr PgfPGF -> IO (StablePtr Type)
|
||||||
|
|
||||||
foreign import ccall "pgf/pgf.h pgf_category_context"
|
foreign import ccall "pgf/pgf.h pgf_category_context"
|
||||||
pgf_category_context :: Ptr PgfPGF -> Ptr PgfText -> Ptr CSize -> IO (Ptr PgfTypeHypo)
|
pgf_category_context :: Ptr PgfPGF -> Ptr PgfText -> Ptr CSize -> IO (Ptr PgfTypeHypo)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user