mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 09:32:53 -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')
|
term = foldl L.LFProjection tuple (L.LFInt (pidIx+1):pids')
|
||||||
return term
|
return term
|
||||||
|
|
||||||
-- PredefValue PredefId -- TODO predef not supported
|
C.PredefValue (C.PredefId "BIND") -> return L.LFBind
|
||||||
|
|
||||||
C.RecordValue rrvs -> do
|
C.RecordValue rrvs -> do
|
||||||
ts <- sequence [ val2lin lv | C.RecordRow lid lv <- rrvs ]
|
ts <- sequence [ val2lin lv | C.RecordRow lid lv <- rrvs ]
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ data Concr = Concr {
|
|||||||
|
|
||||||
-- | Linearisation function
|
-- | Linearisation function
|
||||||
data LinFun =
|
data LinFun =
|
||||||
LFError String
|
LFError String -- ^ a runtime error, should probably not be supported at all
|
||||||
|
| LFBind -- ^ bind token
|
||||||
|
|
||||||
| LFEmpty
|
| LFEmpty
|
||||||
| LFToken String
|
| LFToken String
|
||||||
| LFConcat LinFun LinFun
|
| LFConcat LinFun LinFun
|
||||||
@@ -121,6 +123,8 @@ type Context = [LinFun]
|
|||||||
eval :: Context -> LinFun -> LinFun
|
eval :: Context -> LinFun -> LinFun
|
||||||
eval cxt t = case t of
|
eval cxt t = case t of
|
||||||
LFError err -> error err
|
LFError err -> error err
|
||||||
|
LFBind -> LFBind
|
||||||
|
|
||||||
LFEmpty -> LFEmpty
|
LFEmpty -> LFEmpty
|
||||||
LFToken tok -> LFToken tok
|
LFToken tok -> LFToken tok
|
||||||
LFConcat s t -> LFConcat v w
|
LFConcat s t -> LFConcat v w
|
||||||
@@ -141,8 +145,10 @@ eval cxt t = case t of
|
|||||||
lin2string :: LinFun -> String
|
lin2string :: LinFun -> String
|
||||||
lin2string l = case l of
|
lin2string l = case l of
|
||||||
LFEmpty -> ""
|
LFEmpty -> ""
|
||||||
|
LFBind -> "" -- when encountered at beginning/end
|
||||||
LFToken tok -> tok
|
LFToken tok -> tok
|
||||||
LFTuple [l] -> lin2string l
|
LFTuple [l] -> lin2string l
|
||||||
|
LFConcat l1 (LFConcat LFBind l2) -> lin2string l1 ++ lin2string l2
|
||||||
LFConcat l1 l2 -> unwords $ filter (not.null) [lin2string l1, lin2string l2]
|
LFConcat l1 l2 -> unwords $ filter (not.null) [lin2string l1, lin2string l2]
|
||||||
x -> printf "[%s]" (show x)
|
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
|
: > $TREEBANK
|
||||||
while read tree; do
|
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
|
echo "" >> $TREEBANK
|
||||||
done < $TREES
|
done < $TREES
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ dir = "testsuite" </> "lpgf"
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
doGrammar "Bind"
|
||||||
doGrammar "Tables"
|
doGrammar "Tables"
|
||||||
doGrammar "Params"
|
doGrammar "Params"
|
||||||
doGrammar "Walking"
|
doGrammar "Walking"
|
||||||
|
|||||||
Reference in New Issue
Block a user