Add support for BIND

This commit is contained in:
John J. Camilleri
2021-02-13 00:14:35 +01:00
parent 8cfaa69b6e
commit 98f6136ebd
8 changed files with 34 additions and 3 deletions

View File

@@ -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 ]

View File

@@ -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
View File

@@ -0,0 +1,7 @@
abstract Bind = {
cat S ; F ;
fun
FtoS : F -> S ;
f1 : F ;
f2 : F ;
}

View File

@@ -0,0 +1,6 @@
Bind: FtoS f1
BindCnc: hello there
Bind: FtoS f2
BindCnc: good bye

View File

@@ -0,0 +1,2 @@
FtoS f1
FtoS f2

View 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 ;
}

View File

@@ -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

View File

@@ -15,6 +15,7 @@ dir = "testsuite" </> "lpgf"
main :: IO ()
main = do
doGrammar "Bind"
doGrammar "Tables"
doGrammar "Params"
doGrammar "Walking"