forked from GitHub/gf-core
split the testsuite to different directories for compiler, runtime and libraries
This commit is contained in:
26
testsuite/runtime/paraphrase/City.gf
Normal file
26
testsuite/runtime/paraphrase/City.gf
Normal file
@@ -0,0 +1,26 @@
|
||||
abstract City = {
|
||||
|
||||
cat S ; City ; Country ; Adj ;
|
||||
|
||||
data
|
||||
PredIn : City -> Country -> S ;
|
||||
fun
|
||||
PredAdj : City -> Adj -> S ;
|
||||
Capital : Country -> City ;
|
||||
CountryAdj : Adj -> Country ;
|
||||
data
|
||||
Stockholm, Helsinki : City ;
|
||||
Sweden, Finland : Country ;
|
||||
Swedish, Finnish : Adj ;
|
||||
|
||||
def
|
||||
PredAdj city x = PredIn city (CountryAdj x) ;
|
||||
|
||||
Capital Finland = Helsinki ;
|
||||
Capital Sweden = Stockholm ;
|
||||
|
||||
CountryAdj Finnish = Finland ;
|
||||
CountryAdj Swedish = Sweden ;
|
||||
|
||||
|
||||
}
|
||||
16
testsuite/runtime/paraphrase/CityEng.gf
Normal file
16
testsuite/runtime/paraphrase/CityEng.gf
Normal file
@@ -0,0 +1,16 @@
|
||||
concrete CityEng of City = {
|
||||
|
||||
lincat S, City, Country, Adj = Str ;
|
||||
|
||||
lin
|
||||
PredIn ci co = ci ++ "is in" ++ co ;
|
||||
PredAdj ci ad = ci ++ "is" ++ ad ;
|
||||
Capital co = "the capital of" ++ co ;
|
||||
CountryAdj ad = "the" ++ ad ++ "country" ;
|
||||
Stockholm = "Stockholm" ;
|
||||
Helsinki = "Helsinki" ;
|
||||
Sweden = "Sweden" ;
|
||||
Finland = "Finland" ;
|
||||
Swedish = "Swedish" ;
|
||||
Finnish = "Finnish" ;
|
||||
}
|
||||
34
testsuite/runtime/paraphrase/Nat.gf
Normal file
34
testsuite/runtime/paraphrase/Nat.gf
Normal file
@@ -0,0 +1,34 @@
|
||||
abstract Nat = {
|
||||
|
||||
cat Nat ;
|
||||
|
||||
data
|
||||
Zero : Nat ;
|
||||
Succ : Nat -> Nat ;
|
||||
|
||||
fun one : Nat ;
|
||||
def one = Succ Zero ;
|
||||
|
||||
fun plus : Nat -> Nat -> Nat ;
|
||||
def plus x Zero = x ;
|
||||
def plus x (Succ y) = Succ (plus x y) ;
|
||||
|
||||
fun twice : Nat -> Nat ;
|
||||
def twice x = plus x x ;
|
||||
|
||||
fun times : Nat -> Nat -> Nat ;
|
||||
def times x Zero = Zero ;
|
||||
def times x (Succ y) = plus (times x y) x ;
|
||||
|
||||
fun four : Nat ;
|
||||
def four = twice (twice one) ;
|
||||
|
||||
fun exp : Nat -> Nat ;
|
||||
def exp Zero = one ;
|
||||
def exp (Succ x) = twice (exp x) ;
|
||||
|
||||
fun plus' : Nat -> Nat -> Nat ;
|
||||
def plus' Zero = \y -> y ;
|
||||
def plus' (Succ x) = \y -> Succ (plus x y) ;
|
||||
|
||||
}
|
||||
17
testsuite/runtime/paraphrase/lambda.gf
Normal file
17
testsuite/runtime/paraphrase/lambda.gf
Normal file
@@ -0,0 +1,17 @@
|
||||
abstract lambda = {
|
||||
|
||||
fun f1 : Int -> Int ;
|
||||
def f1 = (\x -> x) ;
|
||||
|
||||
fun f2 : Int ;
|
||||
def f2 = f1 1 ;
|
||||
|
||||
cat D ;
|
||||
data D1 : D ;
|
||||
D2 : D ;
|
||||
|
||||
fun d : D -> Int -> Int ;
|
||||
def d D1 = \x -> x ;
|
||||
d D2 = \x -> 2 ;
|
||||
|
||||
}
|
||||
9
testsuite/runtime/paraphrase/lambda.gfs
Normal file
9
testsuite/runtime/paraphrase/lambda.gfs
Normal file
@@ -0,0 +1,9 @@
|
||||
i testsuite/runtime/paraphrase/lambda.gf
|
||||
|
||||
pt -compute f1
|
||||
pt -compute f2
|
||||
|
||||
pt -compute d D1
|
||||
pt -compute d D2
|
||||
pt -compute d D1 1
|
||||
pt -compute d D2 1
|
||||
12
testsuite/runtime/paraphrase/lambda.gfs.gold
Normal file
12
testsuite/runtime/paraphrase/lambda.gfs.gold
Normal file
@@ -0,0 +1,12 @@
|
||||
\v0 -> v0
|
||||
|
||||
|
||||
|
||||
1
|
||||
|
||||
|
||||
|
||||
\v0 -> v0
|
||||
|
||||
|
||||
|
||||
7
testsuite/runtime/paraphrase/test.gfs.gold
Normal file
7
testsuite/runtime/paraphrase/test.gfs.gold
Normal file
@@ -0,0 +1,7 @@
|
||||
Succ (Succ Zero)
|
||||
|
||||
|
||||
|
||||
Succ (Succ (Succ Zero))
|
||||
|
||||
|
||||
34
testsuite/runtime/parser/Parse.hs
Normal file
34
testsuite/runtime/parser/Parse.hs
Normal file
@@ -0,0 +1,34 @@
|
||||
import PGF
|
||||
import Data.Maybe
|
||||
import System.IO
|
||||
import System.CPUTime
|
||||
import Control.Monad
|
||||
|
||||
main = do
|
||||
pgf <- readPGF "grammar.pgf"
|
||||
ts <- fmap (map (fromJust . readTree) . lines) $ readFile "trees.txt"
|
||||
ss <- foldM (doTest pgf (mkCId "LangGer") (fromJust (readType "Phr"))) [] ts
|
||||
mapM_ (hPutStrLn stderr . show) [(fromIntegral s / fromIntegral n)/1000000000 | (s,n) <- ss]
|
||||
putStrLn "Done."
|
||||
|
||||
doTest pgf lang cat ss t = do
|
||||
let s = linearize pgf lang t
|
||||
putStr (s ++ " ... ")
|
||||
let st = initState pgf lang cat
|
||||
t1 <- getCPUTime
|
||||
res <- doParse st t1 [] (words s)
|
||||
case res of
|
||||
Just (st,ts) -> putStrLn "Ok" >> return (accum ts ss)
|
||||
Nothing -> putStrLn "Fail" >> return ss
|
||||
|
||||
|
||||
doParse st t1 ts [] = return (Just (st,reverse ts))
|
||||
doParse st t1 ts (tk:tks) = do
|
||||
case nextState st tk of
|
||||
Nothing -> return Nothing
|
||||
Just st -> do t2 <- getCPUTime
|
||||
doParse st t1 ((t2-t1):ts) tks
|
||||
|
||||
accum [] ss = ss
|
||||
accum (t:ts) [] = (t,1) : accum ts []
|
||||
accum (t:ts) ((s,n):ss) = (s+t,n+1) : accum ts ss
|
||||
34272
testsuite/runtime/parser/trees.txt
Normal file
34272
testsuite/runtime/parser/trees.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user