mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 00:22:51 -06:00
started on the Haskell binding
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
#include "data.h"
|
||||
#include "reader.h"
|
||||
|
||||
static void
|
||||
pgf_exn_clear(PgfExn* err)
|
||||
{
|
||||
err->type = PGF_EXN_NONE;
|
||||
err->code = 0;
|
||||
err->msg = NULL;
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfPGF *pgf_read(const char* fpath, PgfExn* err)
|
||||
{
|
||||
PgfPGF *pgf = NULL;
|
||||
|
||||
pgf_exn_clear(err);
|
||||
|
||||
try {
|
||||
std::string fpath_n = fpath;
|
||||
size_t len = fpath_n.length();
|
||||
@@ -30,11 +40,11 @@ PgfPGF *pgf_read(const char* fpath, PgfExn* err)
|
||||
|
||||
return pgf;
|
||||
} catch (std::system_error& e) {
|
||||
err->type = "system_error";
|
||||
err->msg = NULL;
|
||||
err->type = PGF_EXN_SYSTEM_ERROR;
|
||||
err->code = e.code().value();
|
||||
} catch (pgf_error& e) {
|
||||
err->type = "pgf_error";
|
||||
err->msg = e.what();
|
||||
err->type = PGF_EXN_PGF_ERROR;
|
||||
err->msg = strdup(e.what());
|
||||
}
|
||||
|
||||
if (pgf != NULL)
|
||||
@@ -49,3 +59,9 @@ void PgfPGF::set_root() {
|
||||
root->minor_version = minor_version;
|
||||
DB::set_root(root);
|
||||
}
|
||||
|
||||
PGF_API
|
||||
void pgf_free(PgfPGF *pgf)
|
||||
{
|
||||
delete pgf;
|
||||
}
|
||||
|
||||
@@ -39,12 +39,22 @@
|
||||
|
||||
typedef struct PgfPGF PgfPGF;
|
||||
|
||||
typedef enum {
|
||||
PGF_EXN_NONE,
|
||||
PGF_EXN_SYSTEM_ERROR,
|
||||
PGF_EXN_PGF_ERROR
|
||||
} PgfExnType;
|
||||
|
||||
typedef struct {
|
||||
const char *type;
|
||||
PgfExnType type;
|
||||
int code;
|
||||
const char *msg;
|
||||
} PgfExn;
|
||||
|
||||
PGF_API_DECL
|
||||
PgfPGF *pgf_read(const char* fpath, PgfExn* err);
|
||||
|
||||
PGF_API_DECL
|
||||
void pgf_free(PgfPGF *pgf);
|
||||
|
||||
#endif // PGF_H_
|
||||
|
||||
Reference in New Issue
Block a user