mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
added showContext
This commit is contained in:
@@ -467,6 +467,20 @@ PgfText *pgf_print_type(PgfType ty,
|
|||||||
return printer.get_text();
|
return printer.get_text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGF_API
|
||||||
|
PgfText *pgf_print_context(size_t n_hypos, PgfTypeHypo *hypos,
|
||||||
|
PgfPrintContext *ctxt, int prio,
|
||||||
|
PgfMarshaller *m)
|
||||||
|
{
|
||||||
|
PgfPrinter printer(ctxt,prio,m);
|
||||||
|
for (size_t i = 0; i < n_hypos; i++) {
|
||||||
|
if (i > 0)
|
||||||
|
printer.puts(" ");
|
||||||
|
printer.hypo(&hypos[i]);
|
||||||
|
}
|
||||||
|
return printer.get_text();
|
||||||
|
}
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u)
|
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -331,6 +331,11 @@ PgfText *pgf_print_type(PgfType ty,
|
|||||||
PgfPrintContext *ctxt, int prio,
|
PgfPrintContext *ctxt, int prio,
|
||||||
PgfMarshaller *m);
|
PgfMarshaller *m);
|
||||||
|
|
||||||
|
PGF_API_DECL
|
||||||
|
PgfText *pgf_print_context(size_t n_hypos, PgfTypeHypo *hypos,
|
||||||
|
PgfPrintContext *ctxt, int prio,
|
||||||
|
PgfMarshaller *m);
|
||||||
|
|
||||||
PGF_API_DECL
|
PGF_API_DECL
|
||||||
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u);
|
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u);
|
||||||
|
|
||||||
|
|||||||
@@ -380,6 +380,26 @@ PgfLiteral PgfPrinter::lstr(PgfText *v)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PgfPrinter::hypo(PgfTypeHypo *hypo)
|
||||||
|
{
|
||||||
|
if (textcmp(hypo->cid, &wildcard) == 0) {
|
||||||
|
prio = 1;
|
||||||
|
m->match_type(this, hypo->type);
|
||||||
|
} else {
|
||||||
|
push_variable(hypo->cid);
|
||||||
|
|
||||||
|
puts("(");
|
||||||
|
if (hypo->bind_type == PGF_BIND_TYPE_IMPLICIT)
|
||||||
|
puts("{");
|
||||||
|
puts(&ctxt->name);
|
||||||
|
if (hypo->bind_type == PGF_BIND_TYPE_IMPLICIT)
|
||||||
|
puts("}");
|
||||||
|
puts(" : ");
|
||||||
|
m->match_type(this, hypo->type);
|
||||||
|
puts(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PgfType PgfPrinter::dtyp(size_t n_hypos, PgfTypeHypo *hypos,
|
PgfType PgfPrinter::dtyp(size_t n_hypos, PgfTypeHypo *hypos,
|
||||||
PgfText *cat,
|
PgfText *cat,
|
||||||
size_t n_exprs, PgfExpr *exprs)
|
size_t n_exprs, PgfExpr *exprs)
|
||||||
@@ -391,23 +411,7 @@ PgfType PgfPrinter::dtyp(size_t n_hypos, PgfTypeHypo *hypos,
|
|||||||
PgfPrintContext *save_ctxt = ctxt;
|
PgfPrintContext *save_ctxt = ctxt;
|
||||||
|
|
||||||
for (int i = 0; i < n_hypos; i++) {
|
for (int i = 0; i < n_hypos; i++) {
|
||||||
if (textcmp(hypos[i].cid, &wildcard) == 0) {
|
hypo(&hypos[i]);
|
||||||
prio = 1;
|
|
||||||
m->match_type(this, hypos[i].type);
|
|
||||||
} else {
|
|
||||||
push_variable(hypos[i].cid);
|
|
||||||
|
|
||||||
puts("(");
|
|
||||||
if (hypos[i].bind_type == PGF_BIND_TYPE_IMPLICIT)
|
|
||||||
puts("{");
|
|
||||||
puts(&ctxt->name);
|
|
||||||
if (hypos[i].bind_type == PGF_BIND_TYPE_IMPLICIT)
|
|
||||||
puts("}");
|
|
||||||
puts(" : ");
|
|
||||||
m->match_type(this, hypos[i].type);
|
|
||||||
puts(")");
|
|
||||||
}
|
|
||||||
|
|
||||||
puts(" -> ");
|
puts(" -> ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
|
|
||||||
PgfText *get_text();
|
PgfText *get_text();
|
||||||
|
|
||||||
|
void hypo(PgfTypeHypo *hypo);
|
||||||
|
|
||||||
virtual PgfExpr eabs(PgfBindType btype, PgfText *name, PgfExpr body);
|
virtual PgfExpr eabs(PgfBindType btype, PgfText *name, PgfExpr body);
|
||||||
virtual PgfExpr eapp(PgfExpr fun, PgfExpr arg);
|
virtual PgfExpr eapp(PgfExpr fun, PgfExpr arg);
|
||||||
virtual PgfExpr elit(PgfLiteral lit);
|
virtual PgfExpr elit(PgfLiteral lit);
|
||||||
|
|||||||
@@ -912,7 +912,13 @@ showType scope ty =
|
|||||||
peekText c_text
|
peekText c_text
|
||||||
|
|
||||||
showContext :: [Var] -> [(BindType,Var,Type)] -> String
|
showContext :: [Var] -> [(BindType,Var,Type)] -> String
|
||||||
showContext = error "TODO: showContext"
|
showContext scope hypos =
|
||||||
|
unsafePerformIO $
|
||||||
|
withHypos hypos $ \n_hypos c_hypos ->
|
||||||
|
bracket (newPrintCtxt scope) freePrintCtxt $ \pctxt ->
|
||||||
|
withForeignPtr marshaller $ \m ->
|
||||||
|
bracket (pgf_print_context n_hypos c_hypos pctxt 0 m) free $ \c_text ->
|
||||||
|
peekText c_text
|
||||||
|
|
||||||
-- | parses a 'String' as a type
|
-- | parses a 'String' as a type
|
||||||
readType :: String -> Maybe Type
|
readType :: String -> Maybe Type
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ foreign import ccall pgf_read_expr_ex :: Ptr PgfText -> Ptr CString -> Ptr PgfUn
|
|||||||
foreign import ccall "pgf_print_type"
|
foreign import ccall "pgf_print_type"
|
||||||
pgf_print_type :: StablePtr Type -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
|
pgf_print_type :: StablePtr Type -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
|
||||||
|
|
||||||
|
foreign import ccall pgf_print_context :: CSize -> Ptr PgfTypeHypo -> Ptr PgfPrintContext -> CInt -> Ptr PgfMarshaller -> IO (Ptr PgfText)
|
||||||
|
|
||||||
foreign import ccall "pgf_read_type"
|
foreign import ccall "pgf_read_type"
|
||||||
pgf_read_type :: Ptr PgfText -> Ptr PgfUnmarshaller -> IO (StablePtr Type)
|
pgf_read_type :: Ptr PgfText -> Ptr PgfUnmarshaller -> IO (StablePtr Type)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user