summaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/c/Makefile.am5
-rw-r--r--src/runtime/c/pgf/linearizer.c90
-rw-r--r--src/runtime/c/pgf/linearizer.h1
-rw-r--r--src/runtime/c/pgf/parser.c6
-rw-r--r--src/runtime/c/sg/sqlite3Btree.c1
-rw-r--r--src/runtime/haskell-bind/PGF2.hsc106
-rw-r--r--src/runtime/haskell-bind/PGF2/FFI.hsc4
-rw-r--r--src/runtime/haskell/PGF.hs2
-rw-r--r--src/runtime/haskell/PGF/Linearize.hs7
-rw-r--r--src/runtime/java/INSTALL15
-rw-r--r--src/runtime/java/Makefile9
-rw-r--r--src/runtime/python/examples/README2
-rw-r--r--src/runtime/typescript/gflib.d.ts337
13 files changed, 486 insertions, 99 deletions
diff --git a/src/runtime/c/Makefile.am b/src/runtime/c/Makefile.am
index edc4f88b2..8f9c8bf56 100644
--- a/src/runtime/c/Makefile.am
+++ b/src/runtime/c/Makefile.am
@@ -87,13 +87,14 @@ libpgf_la_SOURCES = \
pgf/graphviz.c \
pgf/aligner.c \
pgf/pgf.c \
- pgf/pgf.h \
-libpgf_la_LDFLAGS = "-no-undefined"
+ pgf/pgf.h
+libpgf_la_LDFLAGS = -no-undefined
libpgf_la_LIBADD = libgu.la
libsg_la_SOURCES = \
sg/sqlite3Btree.c \
sg/sg.c
+libsg_la_LDFLAGS = -no-undefined
libsg_la_LIBADD = libgu.la libpgf.la
bin_PROGRAMS =
diff --git a/src/runtime/c/pgf/linearizer.c b/src/runtime/c/pgf/linearizer.c
index ced2a8cf2..12b047b13 100644
--- a/src/runtime/c/pgf/linearizer.c
+++ b/src/runtime/c/pgf/linearizer.c
@@ -175,8 +175,9 @@ redo:;
gu_buf_get(buf, PgfProductionApply*, index);
gu_assert(n_args == gu_seq_length(papply->args));
- capp->fun = papply->fun;
- capp->fid = 0;
+ capp->abs_id = papply->fun->absfun->name;
+ capp->fun = papply->fun;
+ capp->fid = 0;
capp->n_args = n_args;
for (size_t i = 0; i < n_args; i++) {
@@ -222,10 +223,10 @@ redo:;
static PgfCncTree
pgf_cnc_resolve_def(PgfCnc* cnc,
size_t n_vars, PgfPrintContext* context,
- PgfCCat* ccat, GuString s, GuPool* pool)
+ PgfCId abs_id, PgfCCat* ccat, GuString s, GuPool* pool)
{
- PgfCncTree lit = gu_null_variant;
PgfCncTree ret = gu_null_variant;
+ PgfCncTree lit = gu_null_variant;
PgfCncTreeLit* clit =
gu_new_variant(PGF_CNC_TREE_LIT,
@@ -233,7 +234,7 @@ pgf_cnc_resolve_def(PgfCnc* cnc,
&lit, pool);
clit->n_vars = 0;
clit->context = context;
- clit->fid = cnc->fid++;
+ clit->fid = -1; // don't report the literal in the bracket
PgfLiteralStr* lit_str =
gu_new_flex_variant(PGF_LITERAL_STR,
PgfLiteralStr,
@@ -241,7 +242,7 @@ pgf_cnc_resolve_def(PgfCnc* cnc,
&clit->lit, pool);
strcpy((char*) lit_str->val, (char*) s);
- if (ccat->lindefs == NULL)
+ if (ccat == NULL || ccat->lindefs == NULL)
return lit;
int index =
@@ -253,9 +254,10 @@ pgf_cnc_resolve_def(PgfCnc* cnc,
gu_new_flex_variant(PGF_CNC_TREE_APP,
PgfCncTreeApp,
args, 1, &ret, pool);
- capp->ccat = ccat;
- capp->fun = gu_seq_get(ccat->lindefs, PgfCncFun*, index);
- capp->fid = cnc->fid++;
+ capp->ccat = ccat;
+ capp->abs_id= abs_id;
+ capp->fun = gu_seq_get(ccat->lindefs, PgfCncFun*, index);
+ capp->fid = cnc->fid++;
capp->n_vars = n_vars;
capp->context = context;
capp->n_args = 1;
@@ -295,7 +297,7 @@ pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool)
PgfCncTreeApp* capp = cti.data;
assert(gu_seq_length(capp->ccat->linrefs) > 0);
-
+
// here we must apply the linref function
PgfCncTree new_ctree;
PgfCncTreeApp* new_capp =
@@ -303,6 +305,7 @@ pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool)
PgfCncTreeApp,
args, 1, &new_ctree, pool);
new_capp->ccat = NULL;
+ new_capp->abs_id = NULL;
new_capp->fun = gu_seq_get(capp->ccat->linrefs, PgfCncFun*, 0);
new_capp->fid = -1;
new_capp->n_vars = 0;
@@ -314,7 +317,7 @@ pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool)
break;
}
}
-
+
return ctree;
}
@@ -396,6 +399,17 @@ pgf_cnc_resolve(PgfCnc* cnc,
goto done;
}
+ PgfCId abs_id = "?";
+ if (emeta->id > 0) {
+ GuPool* tmp_pool = gu_local_pool();
+ GuExn* err = gu_new_exn(tmp_pool);
+ GuStringBuf* sbuf = gu_new_string_buf(tmp_pool);
+ GuOut* out = gu_string_buf_out(sbuf);
+
+ gu_printf(out, err, "?%d", emeta->id);
+ abs_id = gu_string_buf_freeze(sbuf, pool);
+ }
+
int index =
gu_choice_next(cnc->ch, gu_seq_length(ccat->lindefs));
if (index < 0) {
@@ -406,6 +420,7 @@ pgf_cnc_resolve(PgfCnc* cnc,
PgfCncTreeApp,
args, 1, &ret, pool);
capp->ccat = ccat;
+ capp->abs_id = abs_id;
capp->fun = gu_seq_get(ccat->lindefs, PgfCncFun*, index);
capp->fid = cnc->fid++;
capp->n_vars = 0;
@@ -435,23 +450,7 @@ pgf_cnc_resolve(PgfCnc* cnc,
gu_putc(']', out, err);
GuString s = gu_string_buf_freeze(sbuf, tmp_pool);
- if (ccat != NULL) {
- ret = pgf_cnc_resolve_def(cnc, n_vars, context, ccat, s, pool);
- } else {
- PgfCncTreeLit* clit =
- gu_new_variant(PGF_CNC_TREE_LIT,
- PgfCncTreeLit,
- &ret, pool);
- clit->n_vars = 0;
- clit->context = context;
- clit->fid = cnc->fid++;
- PgfLiteralStr* lit =
- gu_new_flex_variant(PGF_LITERAL_STR,
- PgfLiteralStr,
- val, strlen(s)+1,
- &clit->lit, pool);
- strcpy(lit->val, s);
- }
+ ret = pgf_cnc_resolve_def(cnc, n_vars, context, efun->fun, ccat, s, pool);
gu_pool_free(tmp_pool);
goto done;
@@ -499,28 +498,7 @@ redo:;
index--;
}
- if (ccat != NULL && ccat->lindefs == NULL) {
- goto done;
- }
-
- if (ccat != NULL) {
- ret = pgf_cnc_resolve_def(cnc, n_vars, context, ccat, ctxt->name, pool);
- } else {
- PgfCncTreeLit* clit =
- gu_new_variant(PGF_CNC_TREE_LIT,
- PgfCncTreeLit,
- &ret, pool);
- clit->n_vars = 0;
- clit->context = context;
- clit->fid = cnc->fid++;
- PgfLiteralStr* lit =
- gu_new_flex_variant(PGF_LITERAL_STR,
- PgfLiteralStr,
- val, strlen(ctxt->name)+1,
- &clit->lit, pool);
- strcpy(lit->val, ctxt->name);
- }
-
+ ret = pgf_cnc_resolve_def(cnc, n_vars, context, ctxt->name, ccat, ctxt->name, pool);
goto done;
}
case PGF_EXPR_TYPED: {
@@ -939,9 +917,9 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
if ((*lzr->funcs)->begin_phrase && fapp->ccat != NULL) {
(*lzr->funcs)->begin_phrase(lzr->funcs,
- fun->absfun->type->cid,
+ fapp->ccat->cnccat->abscat->name,
fapp->fid, lin_idx,
- fun->absfun->name);
+ fapp->abs_id);
}
gu_require(lin_idx < fun->n_lins);
@@ -949,9 +927,9 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
if ((*lzr->funcs)->end_phrase && fapp->ccat != NULL) {
(*lzr->funcs)->end_phrase(lzr->funcs,
- fun->absfun->type->cid,
+ fapp->ccat->cnccat->abscat->name,
fapp->fid, lin_idx,
- fun->absfun->name);
+ fapp->abs_id);
}
break;
}
@@ -977,7 +955,7 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
PgfCId cat =
pgf_literal_cat(lzr->concr, flit->lit)->cnccat->abscat->name;
- if ((*lzr->funcs)->begin_phrase) {
+ if ((*lzr->funcs)->begin_phrase && flit->fid >= 0) {
(*lzr->funcs)->begin_phrase(lzr->funcs,
cat, flit->fid, 0,
"");
@@ -1009,7 +987,7 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
(*lzr->funcs)->symbol_token(lzr->funcs, tok);
}
- if ((*lzr->funcs)->end_phrase) {
+ if ((*lzr->funcs)->end_phrase && flit->fid >= 0) {
(*lzr->funcs)->end_phrase(lzr->funcs,
cat, flit->fid, 0,
"");
diff --git a/src/runtime/c/pgf/linearizer.h b/src/runtime/c/pgf/linearizer.h
index 57fad962f..790dd5800 100644
--- a/src/runtime/c/pgf/linearizer.h
+++ b/src/runtime/c/pgf/linearizer.h
@@ -22,6 +22,7 @@ typedef enum {
typedef struct {
PgfCCat* ccat;
+ PgfCId abs_id;
PgfCncFun* fun;
int fid;
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c
index d12852a71..cb59b2a55 100644
--- a/src/runtime/c/pgf/parser.c
+++ b/src/runtime/c/pgf/parser.c
@@ -1070,7 +1070,7 @@ pgf_symbols_cmp(GuString* psent, PgfSymbols* syms, size_t* sym_idx, bool case_se
if (*sym_idx > 0) {
if (!skip_space(psent)) {
if (**psent == 0)
- return 0;
+ return -1;
return 1;
}
@@ -1086,13 +1086,13 @@ pgf_symbols_cmp(GuString* psent, PgfSymbols* syms, size_t* sym_idx, bool case_se
case PGF_SYMBOL_LIT:
case PGF_SYMBOL_VAR: {
if (**psent == 0)
- return 0;
+ return -1;
return 1;
}
case PGF_SYMBOL_KS: {
PgfSymbolKS* pks = inf.data;
if (**psent == 0)
- return 0;
+ return -1;
int cmp = cmp_string(psent, pks->token, case_sensitive);
if (cmp != 0)
diff --git a/src/runtime/c/sg/sqlite3Btree.c b/src/runtime/c/sg/sqlite3Btree.c
index a75cfd62b..ee6bd206a 100644
--- a/src/runtime/c/sg/sqlite3Btree.c
+++ b/src/runtime/c/sg/sqlite3Btree.c
@@ -4918,6 +4918,7 @@ SQLITE_PRIVATE int sqlite3PendingByte;
# define SQLITE_UTF16NATIVE SQLITE_UTF16BE
#endif
#if !defined(SQLITE_BYTEORDER)
+const int sqlite3one = 1;
# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
# define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
diff --git a/src/runtime/haskell-bind/PGF2.hsc b/src/runtime/haskell-bind/PGF2.hsc
index 895d13ca4..186aa2b31 100644
--- a/src/runtime/haskell-bind/PGF2.hsc
+++ b/src/runtime/haskell-bind/PGF2.hsc
@@ -58,7 +58,7 @@ module PGF2 (-- * PGF
ConcName,Concr,languages,concreteName,languageCode,
-- ** Linearization
- linearize,linearizeAll,tabularLinearize,tabularLinearizeAll,bracketedLinearize,
+ linearize,linearizeAll,tabularLinearize,tabularLinearizeAll,bracketedLinearize,bracketedLinearizeAll,
FId, LIndex, BracketedString(..), showBracketedString, flattenBracketedString,
printName,
@@ -862,6 +862,7 @@ type LIndex = Int
-- mark the beginning and the end of each constituent.
data BracketedString
= Leaf String -- ^ this is the leaf i.e. a single token
+ | BIND -- ^ the surrounding tokens must be bound together
| Bracket CId {-# UNPACK #-} !FId {-# UNPACK #-} !LIndex CId [BracketedString]
-- ^ this is a bracket. The 'CId' is the category of
-- the phrase. The 'FId' is an unique identifier for
@@ -884,11 +885,13 @@ showBracketedString :: BracketedString -> String
showBracketedString = render . ppBracketedString
ppBracketedString (Leaf t) = text t
+ppBracketedString BIND = text "&+"
ppBracketedString (Bracket cat fid index _ bss) = parens (text cat <> colon <> int fid <+> hsep (map ppBracketedString bss))
-- | Extracts the sequence of tokens from the bracketed string
flattenBracketedString :: BracketedString -> [String]
flattenBracketedString (Leaf w) = [w]
+flattenBracketedString BIND = []
flattenBracketedString (Bracket _ _ _ _ bss) = concatMap flattenBracketedString bss
bracketedLinearize :: Concr -> Expr -> [BracketedString]
@@ -906,27 +909,8 @@ bracketedLinearize lang e = unsafePerformIO $
return []
else do ctree <- pgf_lzr_wrap_linref ctree pl
ref <- newIORef ([],[])
- allocaBytes (#size PgfLinFuncs) $ \pLinFuncs ->
- alloca $ \ppLinFuncs -> do
- fptr_symbol_token <- wrapSymbolTokenCallback (symbol_token ref)
- fptr_begin_phrase <- wrapPhraseCallback (begin_phrase ref)
- fptr_end_phrase <- wrapPhraseCallback (end_phrase ref)
- fptr_symbol_ne <- wrapSymbolNonExistCallback (symbol_ne exn)
- fptr_symbol_meta <- wrapSymbolMetaCallback (symbol_meta ref)
- (#poke PgfLinFuncs, symbol_token) pLinFuncs fptr_symbol_token
- (#poke PgfLinFuncs, begin_phrase) pLinFuncs fptr_begin_phrase
- (#poke PgfLinFuncs, end_phrase) pLinFuncs fptr_end_phrase
- (#poke PgfLinFuncs, symbol_ne) pLinFuncs fptr_symbol_ne
- (#poke PgfLinFuncs, symbol_bind) pLinFuncs nullPtr
- (#poke PgfLinFuncs, symbol_capit) pLinFuncs nullPtr
- (#poke PgfLinFuncs, symbol_meta) pLinFuncs fptr_symbol_meta
- poke ppLinFuncs pLinFuncs
- pgf_lzr_linearize (concr lang) ctree 0 ppLinFuncs pl
- freeHaskellFunPtr fptr_symbol_token
- freeHaskellFunPtr fptr_begin_phrase
- freeHaskellFunPtr fptr_end_phrase
- freeHaskellFunPtr fptr_symbol_ne
- freeHaskellFunPtr fptr_symbol_meta
+ withBracketLinFuncs ref exn $ \ppLinFuncs ->
+ pgf_lzr_linearize (concr lang) ctree 0 ppLinFuncs pl
failed <- gu_exn_is_raised exn
if failed
then do is_nonexist <- gu_exn_caught exn gu_exn_type_PgfLinNonExist
@@ -935,6 +919,65 @@ bracketedLinearize lang e = unsafePerformIO $
else throwExn exn
else do (_,bs) <- readIORef ref
return (reverse bs)
+
+bracketedLinearizeAll :: Concr -> Expr -> [[BracketedString]]
+bracketedLinearizeAll lang e = unsafePerformIO $
+ withGuPool $ \pl ->
+ do exn <- gu_new_exn pl
+ cts <- pgf_lzr_concretize (concr lang) (expr e) exn pl
+ failed <- gu_exn_is_raised exn
+ if failed
+ then do touchExpr e
+ throwExn exn
+ else do ref <- newIORef ([],[])
+ bss <- withBracketLinFuncs ref exn $ \ppLinFuncs ->
+ collect ref cts ppLinFuncs exn pl
+ touchExpr e
+ return bss
+ where
+ collect ref cts ppLinFuncs exn pl = withGuPool $ \tmpPl -> do
+ ctree <- alloca $ \ptr -> do gu_enum_next cts ptr tmpPl
+ peek ptr
+ if ctree == nullPtr
+ then return []
+ else do ctree <- pgf_lzr_wrap_linref ctree pl
+ pgf_lzr_linearize (concr lang) ctree 0 ppLinFuncs pl
+ failed <- gu_exn_is_raised exn
+ if failed
+ then do is_nonexist <- gu_exn_caught exn gu_exn_type_PgfLinNonExist
+ if is_nonexist
+ then collect ref cts ppLinFuncs exn pl
+ else throwExn exn
+ else do (_,bs) <- readIORef ref
+ writeIORef ref ([],[])
+ bss <- collect ref cts ppLinFuncs exn pl
+ return (reverse bs : bss)
+
+withBracketLinFuncs ref exn f =
+ allocaBytes (#size PgfLinFuncs) $ \pLinFuncs ->
+ alloca $ \ppLinFuncs -> do
+ fptr_symbol_token <- wrapSymbolTokenCallback (symbol_token ref)
+ fptr_begin_phrase <- wrapPhraseCallback (begin_phrase ref)
+ fptr_end_phrase <- wrapPhraseCallback (end_phrase ref)
+ fptr_symbol_ne <- wrapSymbolNonExistCallback (symbol_ne exn)
+ fptr_symbol_bind <- wrapSymbolBindCallback (symbol_bind ref)
+ fptr_symbol_meta <- wrapSymbolMetaCallback (symbol_meta ref)
+ (#poke PgfLinFuncs, symbol_token) pLinFuncs fptr_symbol_token
+ (#poke PgfLinFuncs, begin_phrase) pLinFuncs fptr_begin_phrase
+ (#poke PgfLinFuncs, end_phrase) pLinFuncs fptr_end_phrase
+ (#poke PgfLinFuncs, symbol_ne) pLinFuncs fptr_symbol_ne
+ (#poke PgfLinFuncs, symbol_bind) pLinFuncs fptr_symbol_bind
+ (#poke PgfLinFuncs, symbol_capit) pLinFuncs nullPtr
+ (#poke PgfLinFuncs, symbol_meta) pLinFuncs fptr_symbol_meta
+ poke ppLinFuncs pLinFuncs
+ res <- f ppLinFuncs
+ freeHaskellFunPtr fptr_symbol_token
+ freeHaskellFunPtr fptr_begin_phrase
+ freeHaskellFunPtr fptr_end_phrase
+ freeHaskellFunPtr fptr_symbol_ne
+ freeHaskellFunPtr fptr_symbol_bind
+ freeHaskellFunPtr fptr_symbol_meta
+ return res
where
symbol_token ref _ c_token = do
(stack,bs) <- readIORef ref
@@ -957,17 +1000,22 @@ bracketedLinearize lang e = unsafePerformIO $
gu_exn_raise exn gu_exn_type_PgfLinNonExist
return ()
+ symbol_bind ref _ = do
+ (stack,bs) <- readIORef ref
+ writeIORef ref (stack,BIND : bs)
+ return ()
+
symbol_meta ref _ meta_id = do
(stack,bs) <- readIORef ref
writeIORef ref (stack,Leaf "?" : bs)
- throwExn exn = do
- is_exn <- gu_exn_caught exn gu_exn_type_PgfExn
- if is_exn
- then do c_msg <- (#peek GuExn, data.data) exn
- msg <- peekUtf8CString c_msg
- throwIO (PGFError msg)
- else do throwIO (PGFError "The abstract tree cannot be linearized")
+throwExn exn = do
+ is_exn <- gu_exn_caught exn gu_exn_type_PgfExn
+ if is_exn
+ then do c_msg <- (#peek GuExn, data.data) exn
+ msg <- peekUtf8CString c_msg
+ throwIO (PGFError msg)
+ else do throwIO (PGFError "The abstract tree cannot be linearized")
alignWords :: Concr -> Expr -> [(String, [Int])]
alignWords lang e = unsafePerformIO $
diff --git a/src/runtime/haskell-bind/PGF2/FFI.hsc b/src/runtime/haskell-bind/PGF2/FFI.hsc
index c33f1da50..39b18fcf3 100644
--- a/src/runtime/haskell-bind/PGF2/FFI.hsc
+++ b/src/runtime/haskell-bind/PGF2/FFI.hsc
@@ -340,6 +340,7 @@ foreign import ccall "pgf/pgf.h pgf_lzr_get_table"
type SymbolTokenCallback = Ptr (Ptr PgfLinFuncs) -> CString -> IO ()
type PhraseCallback = Ptr (Ptr PgfLinFuncs) -> CString -> CInt -> CSizeT -> CString -> IO ()
type NonExistCallback = Ptr (Ptr PgfLinFuncs) -> IO ()
+type BindCallback = Ptr (Ptr PgfLinFuncs) -> IO ()
type MetaCallback = Ptr (Ptr PgfLinFuncs) -> CInt -> IO ()
foreign import ccall "wrapper"
@@ -352,6 +353,9 @@ foreign import ccall "wrapper"
wrapSymbolNonExistCallback :: NonExistCallback -> IO (FunPtr NonExistCallback)
foreign import ccall "wrapper"
+ wrapSymbolBindCallback :: BindCallback -> IO (FunPtr BindCallback)
+
+foreign import ccall "wrapper"
wrapSymbolMetaCallback :: MetaCallback -> IO (FunPtr MetaCallback)
foreign import ccall "pgf/pgf.h pgf_align_words"
diff --git a/src/runtime/haskell/PGF.hs b/src/runtime/haskell/PGF.hs
index 6c0002a8a..134a13c3b 100644
--- a/src/runtime/haskell/PGF.hs
+++ b/src/runtime/haskell/PGF.hs
@@ -58,7 +58,7 @@ module PGF(
-- * Operations
-- ** Linearization
- linearize, linearizeAllLang, linearizeAll, bracketedLinearize, tabularLinearizes,
+ linearize, linearizeAllLang, linearizeAll, bracketedLinearize, bracketedLinearizeAll, tabularLinearizes,
groupResults, -- lins of trees by language, removing duplicates
showPrintName,
diff --git a/src/runtime/haskell/PGF/Linearize.hs b/src/runtime/haskell/PGF/Linearize.hs
index e3e8d92db..5fdb186c1 100644
--- a/src/runtime/haskell/PGF/Linearize.hs
+++ b/src/runtime/haskell/PGF/Linearize.hs
@@ -4,6 +4,7 @@ module PGF.Linearize
, linearizeAll
, linearizeAllLang
, bracketedLinearize
+ , bracketedLinearizeAll
, tabularLinearizes
) where
@@ -47,6 +48,12 @@ bracketedLinearize pgf lang = head . map (snd . untokn Nothing . firstLin cnc) .
head [] = []
head (bs:bss) = bs
+-- | Linearizes given expression as a bracketed string in the language
+bracketedLinearizeAll :: PGF -> Language -> Tree -> [[BracketedString]]
+bracketedLinearizeAll pgf lang = map (snd . untokn Nothing . firstLin cnc) . linTree pgf cnc
+ where
+ cnc = lookMap (error "no lang") lang (concretes pgf)
+
firstLin cnc arg@(ct@(cat,n_fid),fid,fun,es,(xs,lin)) =
case IntMap.lookup fid (linrefs cnc) of
Just (funid:_) -> snd (mkLinTable cnc (const True) [] funid [arg]) ! 0
diff --git a/src/runtime/java/INSTALL b/src/runtime/java/INSTALL
index 6d97dd279..3facef134 100644
--- a/src/runtime/java/INSTALL
+++ b/src/runtime/java/INSTALL
@@ -1,10 +1,15 @@
-Before compiling the Java binding you first need to have the C runtime
+Before compiling the Java binding you first need to have the C runtime
compiled and installed. You also need to find where your jni.h header
is installed. It is part of the Java JDK, but it might be placed
-in different places on different platforms. The path to the jni.h
-header should be assigned to the JNI_PATH variable in the beginning
-of the Makefile that you will find in the root directory of
-the binding. Once this is done type:
+in different places on different platforms.
+The Makefile in this directory will try to figure out the location of
+jni.h, but if it doesn't succeed you should add it manually to the
+JNI_INCLUDES variable in the beginning of the Makefile.
+
+Once this is done type:
$ make
$ make install
+
+For Windows you might have to uncomment the lines around
+WINDOWS_FLAGS in the Makefile.
diff --git a/src/runtime/java/Makefile b/src/runtime/java/Makefile
index b7a7264cc..d5a25a2f6 100644
--- a/src/runtime/java/Makefile
+++ b/src/runtime/java/Makefile
@@ -3,10 +3,15 @@ JAVA_SOURCES = $(wildcard org/grammaticalframework/pgf/*.java) \
$(wildcard org/grammaticalframework/sg/*.java)
JNI_INCLUDES = $(if $(wildcard /usr/lib/jvm/default-java/include/.*), -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux, \
- $(if $(wildcard /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/.*), /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers, \
+ $(if $(wildcard /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/.*), -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers, \
$(if $(wildcard /Library/Java/Home/include/.*), -I/Library/Java/Home/include/ -I/Library/Java/Home/include/darwin, \
$(error No JNI headers found))))
+# For Windows replace the previous line with something like this:
+#
+# JNI_INCLUDES = -I "C:/Program Files/Java/jdk1.8.0_171/include" -I "C:/Program Files/Java/jdk1.8.0_171/include/win32" -I "C:/MinGW/msys/1.0/local/include"
+# WINDOWS_FLAGS = -L"C:/MinGW/msys/1.0/local/lib" -no-undefined
+
INSTALL_PATH = /usr/local/lib
LIBTOOL = glibtool --tag=CC
@@ -15,7 +20,7 @@ LIBTOOL = $(if $(shell command -v glibtool 2>/dev/null), glibtool --tag=CC, libt
all: libjpgf.la jpgf.jar
libjpgf.la: $(patsubst %.c, %.lo, $(C_SOURCES))
- $(LIBTOOL) --mode=link gcc $(CFLAGS) -g -O -o libjpgf.la -shared $^ -rpath $(INSTALL_PATH) -lgu -lpgf -lsg
+ $(LIBTOOL) --mode=link gcc $(CFLAGS) -g -O -o libjpgf.la -shared $^ -rpath $(INSTALL_PATH) -lgu -lpgf -lsg $(WINDOWS_FLAGS)
%.lo : %.c
$(LIBTOOL) --mode=compile gcc $(CFLAGS) -g -O -c $(JNI_INCLUDES) -std=c99 -shared $< -o $@
diff --git a/src/runtime/python/examples/README b/src/runtime/python/examples/README
index b6791a368..813c2f9c9 100644
--- a/src/runtime/python/examples/README
+++ b/src/runtime/python/examples/README
@@ -9,7 +9,7 @@ TRANSLATION PIPELINE
The module translation_pipeline.py is a Python replica of the
translation pipeline used in Wide-coverage Translation demo.
The pipeline allows for
- 1. simulataneous batch translation from one language into multiple languages
+ 1. simultaneous batch translation from one language into multiple languages
2. K-best translations
3. translate both text files and sgm files.
diff --git a/src/runtime/typescript/gflib.d.ts b/src/runtime/typescript/gflib.d.ts
new file mode 100644
index 000000000..4249e66d2
--- /dev/null
+++ b/src/runtime/typescript/gflib.d.ts
@@ -0,0 +1,337 @@
+/**
+ * gflib.dt.s
+ *
+ * by John J. Camilleri
+ *
+ * TypeScript type definitions for the "original" JS GF runtime (GF:src/runtime/javascript/gflib.js)
+ */
+
+// Note: the String prototype is extended with:
+// String.prototype.tag = "";
+// String.prototype.setTag = function (tag) { this.tag = tag; };
+
+/**
+ * A GF grammar is one abstract and multiple concretes
+ */
+declare class GFGrammar {
+ abstract: GFAbstract
+ concretes: {[key: string]: GFConcrete}
+
+ constructor(abstract: GFAbstract, concretes: {[key: string]: GFConcrete})
+
+ translate(
+ input: string,
+ fromLang: string,
+ toLang: string
+ ): {[key: string]: {[key: string]: string}}
+}
+
+/**
+ * Abstract Syntax Tree
+ */
+declare class Fun {
+ name: string
+ args: Fun[]
+
+ constructor(name: string, ...args: Fun[])
+
+ print(): string
+ show(): string
+ getArg(i: number): Fun
+ setArg(i: number, c: Fun): void
+ isMeta(): boolean
+ isComplete(): boolean
+ isLiteral(): boolean
+ isString(): boolean
+ isInt(): boolean
+ isFloat(): boolean
+ isEqual(obj: any): boolean
+}
+
+/**
+ * Abstract syntax
+ */
+declare class GFAbstract {
+ startcat: string
+ types: {[key: string]: Type} // key is function name
+
+ constructor(startcat: string, types: {[key: string]: Type})
+
+ addType(fun: string, args: string[], cat: string): void
+ getArgs(fun: string): string[]
+ getCat(fun: string): string
+ annotate(tree: Fun, type: string): Fun
+ handleLiterals(tree: Fun, type: Type): Fun
+ copyTree(x: Fun): Fun
+ parseTree(str: string, type: string): Fun
+ parseTree_(tokens: string[], prec: number): Fun
+}
+
+/**
+ * Type
+ */
+declare class Type {
+ args: string[]
+ cat: string
+
+ constructor(args: string[], cat: string)
+}
+
+type ApplyOrCoerce = Apply | Coerce
+
+/**
+ * Concrete syntax
+ */
+declare class GFConcrete {
+ flags: {[key: string]: string}
+ productions: {[key: number]: ApplyOrCoerce[]}
+ functions: CncFun[]
+ sequences: Array<Array<Sym>>
+ startCats: {[key: string]: {s: number, e: number}}
+ totalFIds: number
+ pproductions: {[key: number]: ApplyOrCoerce[]}
+ lproductions: {[key: string]: {fid: FId, fun: CncFun}}
+
+ constructor(
+ flags: {[key: string]: string},
+ productions: {[key: number]: ApplyOrCoerce[]},
+ functions: CncFun[],
+ sequences: Array<Array<Sym>>,
+ startCats: {[key: string]: {s: number, e: number}},
+ totalFIds: number
+ )
+
+ linearizeSyms(tree: Fun, tag: string): Array<{fid: FId, table: any}>
+ syms2toks(syms: Sym[]): string[]
+ linearizeAll(tree: Fun): string[]
+ linearize(tree: Fun): string
+ tagAndLinearize(tree: Fun): string[]
+ unlex(ts: string): string
+ tagIt(obj: any, tag: string): any
+ // showRules(): string // Uncaught TypeError: Cannot read property 'length' of undefined at gflib.js:451
+ tokenize(string: string): string[]
+ parseString(string: string, cat: string): Fun[]
+ complete(
+ input: string,
+ cat: string
+ ): {consumed: string[], suggestions: string[]}
+}
+
+/**
+ * Function ID
+ */
+type FId = number
+
+/**
+ * Apply
+ */
+declare class Apply {
+ id: string
+ fun: FId
+ args: PArg[]
+
+ constructor(fun: FId, args: PArg[])
+
+ show(cat: string): string
+ isEqual(obj: any): boolean
+}
+
+/**
+ * PArg
+ */
+declare class PArg {
+ fid: FId
+ hypos: any[]
+
+ constructor(fid: FId, ...hypos: any[])
+}
+
+/**
+ * Coerce
+ */
+declare class Coerce {
+ id: string
+ arg: FId
+
+ constructor(arg: FId)
+
+ show(cat: string): string
+}
+
+/**
+ * Const
+ */
+declare class Const {
+ id: string
+ lit: Fun
+ toks: any[]
+
+ constructor(lit: Fun, toks: any[])
+
+ show(cat: string): string
+ isEqual(obj: any): boolean
+}
+
+/**
+ * CncFun
+ */
+declare class CncFun {
+ name: string
+ lins: FId[]
+
+ constructor(name: string, lins: FId[])
+}
+
+type Sym = SymCat | SymKS | SymKP | SymLit
+
+/**
+ * SymCat
+ */
+declare class SymCat {
+ id: string
+ i: number
+ label: number
+
+ constructor(i: number, label: number)
+
+ getId(): string
+ getArgNum(): number
+ show(): string
+}
+
+/**
+ * SymKS
+ */
+declare class SymKS {
+ id: string
+ tokens: string[]
+
+ constructor(...tokens: string[])
+
+ getId(): string
+ show(): string
+}
+
+/**
+ * SymKP
+ */
+declare class SymKP {
+ id: string
+ tokens: string[]
+ alts: Alt[]
+
+ constructor(tokens: string[], alts: Alt[])
+
+ getId(): string
+ show(): string
+}
+
+/**
+ * Alt
+ */
+declare class Alt {
+ tokens: string[]
+ prefixes: string[]
+
+ constructor(tokens: string[], prefixes: string[])
+}
+
+/**
+ * SymLit
+ */
+declare class SymLit {
+ id: string
+ i: number
+ label: number
+
+ constructor(i: number, label: number)
+
+ getId(): string
+ show(): string
+}
+
+/**
+ * Trie
+ */
+declare class Trie {
+ value: any
+ items: Trie[]
+
+ insertChain(keys, obj): void
+ insertChain1(keys, obj): void
+ lookup(key, obj): any
+ isEmpty(): boolean
+}
+
+/**
+ * ParseState
+ */
+declare class ParseState {
+ concrete: GFConcrete
+ startCat: string
+ items: Trie
+ chart: Chart
+
+ constructor(concrete: GFConcrete, startCat: string)
+
+ next(token: string): boolean
+ complete(correntToken: string): Trie
+ extractTrees(): any[]
+ process(
+ agenda,
+ literalCallback: (fid: FId) => any,
+ tokenCallback: (tokens: string[], item: any) => any
+ ): void
+}
+
+/**
+ * Chart
+ */
+declare class Chart {
+ active: any
+ actives: {[key: number]: any}
+ passive: any
+ forest: {[key: number]: ApplyOrCoerce[]}
+ nextId: number
+ offset: number
+
+ constructor(concrete: GFConcrete)
+
+ lookupAC(fid: FId,label)
+ lookupACo(offset, fid: FId, label)
+
+ labelsAC(fid: FId)
+ insertAC(fid: FId, label, items): void
+
+ lookupPC(fid: FId, label, offset)
+ insertPC(fid1: FId, label, offset, fid2: FId): void
+ shift(): void
+ expandForest(fid: FId): any[]
+}
+
+/**
+ * ActiveItem
+ */
+declare class ActiveItem {
+ offset: number
+ dot: number
+ fun: CncFun
+ seq: Array<Sym>
+ args: PArg[]
+ fid: FId
+ lbl: number
+
+ constructor(
+ offset: number,
+ dot: number,
+ fun: CncFun,
+ seq: Array<Sym>,
+ args: PArg[],
+ fid: FId,
+ lbl: number
+ )
+
+ isEqual(obj: any): boolean
+ shiftOverArg(i: number, fid: FId): ActiveItem
+ shiftOverTokn(): ActiveItem
+}