diff --git a/src/compiler/GF/Compile/GrammarToLPGF.hs b/src/compiler/GF/Compile/GrammarToLPGF.hs index ad33ecdc1..342cfb098 100644 --- a/src/compiler/GF/Compile/GrammarToLPGF.hs +++ b/src/compiler/GF/Compile/GrammarToLPGF.hs @@ -90,7 +90,7 @@ mkCanon2lpgf opts gr am = do term = foldl L.LFProjection tuple (L.LFInt (pidIx+1):pids') return term - -- PredefValue PredefId -- TODO predef not supported + C.PredefValue (C.PredefId "BIND") -> return L.LFBind C.RecordValue rrvs -> do ts <- sequence [ val2lin lv | C.RecordRow lid lv <- rrvs ] diff --git a/src/runtime/haskell/LPGF.hs b/src/runtime/haskell/LPGF.hs index 9bbab7f31..b004ecf44 100644 --- a/src/runtime/haskell/LPGF.hs +++ b/src/runtime/haskell/LPGF.hs @@ -45,7 +45,9 @@ data Concr = Concr { -- | Linearisation function data LinFun = - LFError String + LFError String -- ^ a runtime error, should probably not be supported at all + | LFBind -- ^ bind token + | LFEmpty | LFToken String | LFConcat LinFun LinFun @@ -121,6 +123,8 @@ type Context = [LinFun] eval :: Context -> LinFun -> LinFun eval cxt t = case t of LFError err -> error err + LFBind -> LFBind + LFEmpty -> LFEmpty LFToken tok -> LFToken tok LFConcat s t -> LFConcat v w @@ -141,8 +145,10 @@ eval cxt t = case t of lin2string :: LinFun -> String lin2string l = case l of LFEmpty -> "" + LFBind -> "" -- when encountered at beginning/end LFToken tok -> tok LFTuple [l] -> lin2string l + LFConcat l1 (LFConcat LFBind l2) -> lin2string l1 ++ lin2string l2 LFConcat l1 l2 -> unwords $ filter (not.null) [lin2string l1, lin2string l2] x -> printf "[%s]" (show x) diff --git a/testsuite/lpgf/Bind.gf b/testsuite/lpgf/Bind.gf new file mode 100644 index 000000000..2d90ba1b5 --- /dev/null +++ b/testsuite/lpgf/Bind.gf @@ -0,0 +1,7 @@ +abstract Bind = { + cat S ; F ; + fun + FtoS : F -> S ; + f1 : F ; + f2 : F ; +} diff --git a/testsuite/lpgf/Bind.treebank b/testsuite/lpgf/Bind.treebank new file mode 100644 index 000000000..5d3a30e11 --- /dev/null +++ b/testsuite/lpgf/Bind.treebank @@ -0,0 +1,6 @@ +Bind: FtoS f1 +BindCnc: hello there + +Bind: FtoS f2 +BindCnc: good bye + diff --git a/testsuite/lpgf/Bind.trees b/testsuite/lpgf/Bind.trees new file mode 100644 index 000000000..dd3b55e19 --- /dev/null +++ b/testsuite/lpgf/Bind.trees @@ -0,0 +1,2 @@ +FtoS f1 +FtoS f2 diff --git a/testsuite/lpgf/BindCnc.gf b/testsuite/lpgf/BindCnc.gf new file mode 100644 index 000000000..efca9b94d --- /dev/null +++ b/testsuite/lpgf/BindCnc.gf @@ -0,0 +1,9 @@ +concrete BindCnc of Bind = open Prelude in { + lincat + S = Str ; + F = { s : Str } ; + lin + f1 = { s = "hello the" ++ BIND ++ "re" } ; + f2 = { s = "good" ++ "bye" } ; + FtoS f = f.s ; +} diff --git a/testsuite/lpgf/mkTreebank.sh b/testsuite/lpgf/mkTreebank.sh index 890c42558..a79f91542 100755 --- a/testsuite/lpgf/mkTreebank.sh +++ b/testsuite/lpgf/mkTreebank.sh @@ -12,7 +12,7 @@ TREEBANK="$ABSNAME.treebank" : > $TREEBANK while read tree; do - echo "linearize -treebank $tree | write_file -file=$TREEBANK -append" | gf --run $ABSNAME*.gf > /dev/null + echo "linearize -treebank -bind $tree | write_file -file=$TREEBANK -append" | gf --run $ABSNAME*.gf | awk NF echo "" >> $TREEBANK done < $TREES diff --git a/testsuite/lpgf/run.hs b/testsuite/lpgf/run.hs index b47bb17e5..4e7b3c1fe 100644 --- a/testsuite/lpgf/run.hs +++ b/testsuite/lpgf/run.hs @@ -15,6 +15,7 @@ dir = "testsuite" "lpgf" main :: IO () main = do + doGrammar "Bind" doGrammar "Tables" doGrammar "Params" doGrammar "Walking"