mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-14 07:19:31 -06:00
Add support for BIND
This commit is contained in:
@@ -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 ]
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
7
testsuite/lpgf/Bind.gf
Normal file
7
testsuite/lpgf/Bind.gf
Normal file
@@ -0,0 +1,7 @@
|
||||
abstract Bind = {
|
||||
cat S ; F ;
|
||||
fun
|
||||
FtoS : F -> S ;
|
||||
f1 : F ;
|
||||
f2 : F ;
|
||||
}
|
||||
6
testsuite/lpgf/Bind.treebank
Normal file
6
testsuite/lpgf/Bind.treebank
Normal file
@@ -0,0 +1,6 @@
|
||||
Bind: FtoS f1
|
||||
BindCnc: hello there
|
||||
|
||||
Bind: FtoS f2
|
||||
BindCnc: good bye
|
||||
|
||||
2
testsuite/lpgf/Bind.trees
Normal file
2
testsuite/lpgf/Bind.trees
Normal file
@@ -0,0 +1,2 @@
|
||||
FtoS f1
|
||||
FtoS f2
|
||||
9
testsuite/lpgf/BindCnc.gf
Normal file
9
testsuite/lpgf/BindCnc.gf
Normal file
@@ -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 ;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ dir = "testsuite" </> "lpgf"
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
doGrammar "Bind"
|
||||
doGrammar "Tables"
|
||||
doGrammar "Params"
|
||||
doGrammar "Walking"
|
||||
|
||||
Reference in New Issue
Block a user