-
Notifications
You must be signed in to change notification settings - Fork 15
/
ParParse.hs
45 lines (39 loc) · 1.13 KB
/
ParParse.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Main where
import PGF2
import System.Environment (getArgs)
import Control.Concurrent
import Control.Monad
import qualified Data.Map as M
-- to get parallel processing:
-- Build with -threaded -rtsopts
-- Run with +RTS -N$cores -RTS
main = do
xx <- getArgs
case xx of
pgfile:lang:_ -> do
pgf <- readPGF pgfile
ls <- getContents >>= return . lines
rs <- parparse pgf lang ls
return ()
_ -> putStrLn "usage (from stdin to stdout): parparse pgf lan +RTS -N6 -RTS"
parparse pgf lang = manyLater (putStrLn . prse)
where
Just concr = M.lookup lang (languages pgf)
prse s = case parse concr (startCat pgf) s of -- with C runtime
ParseOk ((t,_):_) -> showExpr [] t ++ "\t" ++ s
_ -> "NO PARSE:\t" ++ s
{-
prse1 s = case parse pgf (mkCId lang) (startCat pgf) s of -- with Haskell runtime
t:_ -> showExpr [] t ++ "\t" ++ s
_ -> "NO PARSE:\t" ++ s
-}
-- from Anton Ekblad 2020-01-09
manyLater :: (a -> IO b) -> [a] -> IO [b]
manyLater f chunks = do
vs <- forM chunks $ \chunk -> do
v <- newEmptyMVar
forkIO $ do
x <- f chunk
x `seq` putMVar v x
return v
mapM takeMVar vs