mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-07 10:12:51 -06:00
Replace tabs for whitespace in source code
This commit is contained in:
@@ -130,5 +130,5 @@ cf2concr cfg = Concr Map.empty Map.empty
|
|||||||
|
|
||||||
mkRuleName rule =
|
mkRuleName rule =
|
||||||
case ruleName rule of
|
case ruleName rule of
|
||||||
CFObj n _ -> n
|
CFObj n _ -> n
|
||||||
_ -> wildCId
|
_ -> wildCId
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ checkInfo opts cwd sgr (m,mo) c info = checkInModule cwd mo NoLoc empty $ do
|
|||||||
checkTyp gr typ
|
checkTyp gr typ
|
||||||
case md of
|
case md of
|
||||||
Just eqs -> mapM_ (\(L loc eq) -> mkCheck loc "the definition of function" $
|
Just eqs -> mapM_ (\(L loc eq) -> mkCheck loc "the definition of function" $
|
||||||
checkDef gr (m,c) typ eq) eqs
|
checkDef gr (m,c) typ eq) eqs
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
return (AbsFun (Just (L loc typ)) ma md moper)
|
return (AbsFun (Just (L loc typ)) ma md moper)
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ linTypeOfType cnc m typ = do
|
|||||||
mkLinArg (i,(n,mc@(m,cat))) = do
|
mkLinArg (i,(n,mc@(m,cat))) = do
|
||||||
val <- lookLin mc
|
val <- lookLin mc
|
||||||
let vars = mkRecType varLabel $ replicate n typeStr
|
let vars = mkRecType varLabel $ replicate n typeStr
|
||||||
symb = argIdent n cat i
|
symb = argIdent n cat i
|
||||||
rec <- if n==0 then return val else
|
rec <- if n==0 then return val else
|
||||||
errIn (render ("extending" $$
|
errIn (render ("extending" $$
|
||||||
nest 2 vars $$
|
nest 2 vars $$
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Compile.Rename (
|
module GF.Compile.Rename (
|
||||||
renameSourceTerm,
|
renameSourceTerm,
|
||||||
renameModule
|
renameModule
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
import GF.Infra.CheckM
|
import GF.Infra.CheckM
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Compile.TypeCheck.Abstract (-- * top-level type checking functions; TC should not be called directly.
|
module GF.Compile.TypeCheck.Abstract (-- * top-level type checking functions; TC should not be called directly.
|
||||||
checkContext,
|
checkContext,
|
||||||
checkTyp,
|
checkTyp,
|
||||||
checkDef,
|
checkDef,
|
||||||
checkConstrs,
|
checkConstrs,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ computeLType gr g0 t = comp (reverse [(b,x, Vr x) | (b,x,_) <- g0] ++ g0) t
|
|||||||
lockRecType c t' ---- locking to be removed AR 20/6/2009
|
lockRecType c t' ---- locking to be removed AR 20/6/2009
|
||||||
|
|
||||||
_ | ty == typeTok -> return typeStr
|
_ | ty == typeTok -> return typeStr
|
||||||
_ | isPredefConstant ty -> return ty
|
|
||||||
|
|
||||||
_ -> composOp (comp g) ty
|
_ -> composOp (comp g) ty
|
||||||
|
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ tcRecTypeFields ge scope ((l,ty):rs) mb_ty = do
|
|||||||
return ((l,ty):rs,mb_ty)
|
return ((l,ty):rs,mb_ty)
|
||||||
|
|
||||||
-- | Invariant: if the third argument is (Just rho),
|
-- | Invariant: if the third argument is (Just rho),
|
||||||
-- then rho is in weak-prenex form
|
-- then rho is in weak-prenex form
|
||||||
instSigma :: GlobalEnv -> Scope -> Term -> Sigma -> Maybe Rho -> TcM (Term, Rho)
|
instSigma :: GlobalEnv -> Scope -> Term -> Sigma -> Maybe Rho -> TcM (Term, Rho)
|
||||||
instSigma ge scope t ty1 Nothing = return (t,ty1) -- INST1
|
instSigma ge scope t ty1 Nothing = return (t,ty1) -- INST1
|
||||||
instSigma ge scope t ty1 (Just ty2) = do -- INST2
|
instSigma ge scope t ty1 (Just ty2) = do -- INST2
|
||||||
@@ -631,8 +631,8 @@ allBinders = [ identS [x] | x <- ['a'..'z'] ] ++
|
|||||||
type Scope = [(Ident,Value)]
|
type Scope = [(Ident,Value)]
|
||||||
|
|
||||||
type Sigma = Value
|
type Sigma = Value
|
||||||
type Rho = Value -- No top-level ForAll
|
type Rho = Value -- No top-level ForAll
|
||||||
type Tau = Value -- No ForAlls anywhere
|
type Tau = Value -- No ForAlls anywhere
|
||||||
|
|
||||||
data MetaValue
|
data MetaValue
|
||||||
= Unbound Scope Sigma
|
= Unbound Scope Sigma
|
||||||
@@ -724,8 +724,8 @@ getMetaVars loc sc_tys = do
|
|||||||
go (Vr tv) acc = acc
|
go (Vr tv) acc = acc
|
||||||
go (App x y) acc = go x (go y acc)
|
go (App x y) acc = go x (go y acc)
|
||||||
go (Meta i) acc
|
go (Meta i) acc
|
||||||
| i `elem` acc = acc
|
| i `elem` acc = acc
|
||||||
| otherwise = i : acc
|
| otherwise = i : acc
|
||||||
go (Q _) acc = acc
|
go (Q _) acc = acc
|
||||||
go (QC _) acc = acc
|
go (QC _) acc = acc
|
||||||
go (Sort _) acc = acc
|
go (Sort _) acc = acc
|
||||||
@@ -742,9 +742,9 @@ getFreeVars loc sc_tys = do
|
|||||||
return (foldr (go []) [] tys)
|
return (foldr (go []) [] tys)
|
||||||
where
|
where
|
||||||
go bound (Vr tv) acc
|
go bound (Vr tv) acc
|
||||||
| tv `elem` bound = acc
|
| tv `elem` bound = acc
|
||||||
| tv `elem` acc = acc
|
| tv `elem` acc = acc
|
||||||
| otherwise = tv : acc
|
| otherwise = tv : acc
|
||||||
go bound (App x y) acc = go bound x (go bound y acc)
|
go bound (App x y) acc = go bound x (go bound y acc)
|
||||||
go bound (Meta _) acc = acc
|
go bound (Meta _) acc = acc
|
||||||
go bound (Q _) acc = acc
|
go bound (Q _) acc = acc
|
||||||
|
|||||||
@@ -12,14 +12,15 @@
|
|||||||
-- Thierry Coquand's type checking algorithm that creates a trace
|
-- Thierry Coquand's type checking algorithm that creates a trace
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Compile.TypeCheck.TC (AExp(..),
|
module GF.Compile.TypeCheck.TC (
|
||||||
Theory,
|
AExp(..),
|
||||||
checkExp,
|
Theory,
|
||||||
inferExp,
|
checkExp,
|
||||||
checkBranch,
|
inferExp,
|
||||||
eqVal,
|
checkBranch,
|
||||||
whnf
|
eqVal,
|
||||||
) where
|
whnf
|
||||||
|
) where
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
import GF.Grammar
|
import GF.Grammar
|
||||||
@@ -127,10 +128,10 @@ checkExp th tenv@(k,rho,gamma) e ty = do
|
|||||||
|
|
||||||
Abs _ x t -> case typ of
|
Abs _ x t -> case typ of
|
||||||
VClos env (Prod _ y a b) -> do
|
VClos env (Prod _ y a b) -> do
|
||||||
a' <- whnf $ VClos env a ---
|
a' <- whnf $ VClos env a ---
|
||||||
(t',cs) <- checkExp th
|
(t',cs) <- checkExp th
|
||||||
(k+1,(x,v x):rho, (x,a'):gamma) t (VClos ((y,v x):env) b)
|
(k+1,(x,v x):rho, (x,a'):gamma) t (VClos ((y,v x):env) b)
|
||||||
return (AAbs x a' t', cs)
|
return (AAbs x a' t', cs)
|
||||||
_ -> Bad (render ("function type expected for" <+> ppTerm Unqualified 0 e <+> "instead of" <+> ppValue Unqualified 0 typ))
|
_ -> Bad (render ("function type expected for" <+> ppTerm Unqualified 0 e <+> "instead of" <+> ppValue Unqualified 0 typ))
|
||||||
|
|
||||||
Let (x, (mb_typ, e1)) e2 -> do
|
Let (x, (mb_typ, e1)) e2 -> do
|
||||||
@@ -205,8 +206,8 @@ inferExp th tenv@(k,rho,gamma) e = case e of
|
|||||||
case typ of
|
case typ of
|
||||||
VClos env (Prod _ x a b) -> do
|
VClos env (Prod _ x a b) -> do
|
||||||
(a',csa) <- checkExp th tenv t (VClos env a)
|
(a',csa) <- checkExp th tenv t (VClos env a)
|
||||||
b' <- whnf $ VClos ((x,VClos rho t):env) b
|
b' <- whnf $ VClos ((x,VClos rho t):env) b
|
||||||
return $ (AApp f' a' b', b', csf ++ csa)
|
return $ (AApp f' a' b', b', csf ++ csa)
|
||||||
_ -> Bad (render ("Prod expected for function" <+> ppTerm Unqualified 0 f <+> "instead of" <+> ppValue Unqualified 0 typ))
|
_ -> Bad (render ("Prod expected for function" <+> ppTerm Unqualified 0 f <+> "instead of" <+> ppValue Unqualified 0 typ))
|
||||||
_ -> Bad (render ("cannot infer type of expression" <+> ppTerm Unqualified 0 e))
|
_ -> Bad (render ("cannot infer type of expression" <+> ppTerm Unqualified 0 e))
|
||||||
|
|
||||||
@@ -245,11 +246,11 @@ checkBranch th tenv b@(ps,t) ty = errIn ("branch" +++ show b) $
|
|||||||
typ <- whnf ty
|
typ <- whnf ty
|
||||||
case typ of
|
case typ of
|
||||||
VClos env (Prod _ y a b) -> do
|
VClos env (Prod _ y a b) -> do
|
||||||
a' <- whnf $ VClos env a
|
a' <- whnf $ VClos env a
|
||||||
(p', sigma, binds, cs1) <- checkP tenv p y a'
|
(p', sigma, binds, cs1) <- checkP tenv p y a'
|
||||||
let tenv' = (length binds, sigma ++ rho, binds ++ gamma)
|
let tenv' = (length binds, sigma ++ rho, binds ++ gamma)
|
||||||
((ps',exp),cs2) <- chB tenv' ps2 (VClos ((y,p'):env) b)
|
((ps',exp),cs2) <- chB tenv' ps2 (VClos ((y,p'):env) b)
|
||||||
return ((p:ps',exp), cs1 ++ cs2) -- don't change the patt
|
return ((p:ps',exp), cs1 ++ cs2) -- don't change the patt
|
||||||
_ -> Bad (render ("Product expected for definiens" <+> ppTerm Unqualified 0 t <+> "instead of" <+> ppValue Unqualified 0 typ))
|
_ -> Bad (render ("Product expected for definiens" <+> ppTerm Unqualified 0 t <+> "instead of" <+> ppValue Unqualified 0 typ))
|
||||||
[] -> do
|
[] -> do
|
||||||
(e,cs) <- checkExp th tenv t ty
|
(e,cs) <- checkExp th tenv t ty
|
||||||
@@ -307,8 +308,8 @@ checkPatt th tenv exp val = do
|
|||||||
case typ of
|
case typ of
|
||||||
VClos env (Prod _ x a b) -> do
|
VClos env (Prod _ x a b) -> do
|
||||||
(a',_,csa) <- checkExpP tenv t (VClos env a)
|
(a',_,csa) <- checkExpP tenv t (VClos env a)
|
||||||
b' <- whnf $ VClos ((x,VClos rho t):env) b
|
b' <- whnf $ VClos ((x,VClos rho t):env) b
|
||||||
return $ (AApp f' a' b', b', csf ++ csa)
|
return $ (AApp f' a' b', b', csf ++ csa)
|
||||||
_ -> Bad (render ("Prod expected for function" <+> ppTerm Unqualified 0 f <+> "instead of" <+> ppValue Unqualified 0 typ))
|
_ -> Bad (render ("Prod expected for function" <+> ppTerm Unqualified 0 f <+> "instead of" <+> ppValue Unqualified 0 typ))
|
||||||
_ -> Bad (render ("cannot typecheck pattern" <+> ppTerm Unqualified 0 exp))
|
_ -> Bad (render ("cannot typecheck pattern" <+> ppTerm Unqualified 0 exp))
|
||||||
|
|
||||||
@@ -321,4 +322,3 @@ mkAnnot :: (Val -> AExp) -> Err (Val,[(Val,Val)]) -> Err (AExp,Val,[(Val,Val)])
|
|||||||
mkAnnot a ti = do
|
mkAnnot a ti = do
|
||||||
(v,cs) <- ti
|
(v,cs) <- ti
|
||||||
return (a v, v, cs)
|
return (a v, v, cs)
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ buildAnyTree :: Fail.MonadFail m => ModuleName -> [(Ident,Info)] -> m (Map.Map I
|
|||||||
buildAnyTree m = go Map.empty
|
buildAnyTree m = go Map.empty
|
||||||
where
|
where
|
||||||
go map [] = return map
|
go map [] = return map
|
||||||
go map ((c,j):is) = do
|
go map ((c,j):is) =
|
||||||
case Map.lookup c map of
|
case Map.lookup c map of
|
||||||
Just i -> case unifyAnyInfo m i j of
|
Just i -> case unifyAnyInfo m i j of
|
||||||
Ok k -> go (Map.insert c k map) is
|
Ok k -> go (Map.insert c k map) is
|
||||||
Bad _ -> fail $ render ("conflicting information in module"<+>m $$
|
Bad _ -> fail $ render ("conflicting information in module"<+>m $$
|
||||||
nest 4 (ppJudgement Qualified (c,i)) $$
|
nest 4 (ppJudgement Qualified (c,i)) $$
|
||||||
"and" $+$
|
"and" $+$
|
||||||
nest 4 (ppJudgement Qualified (c,j)))
|
nest 4 (ppJudgement Qualified (c,j)))
|
||||||
Nothing -> go (Map.insert c j map) is
|
Nothing -> go (Map.insert c j map) is
|
||||||
|
|
||||||
extendModule :: FilePath -> SourceGrammar -> SourceModule -> Check SourceModule
|
extendModule :: FilePath -> SourceGrammar -> SourceModule -> Check SourceModule
|
||||||
@@ -147,18 +147,18 @@ extendMod gr isCompl ((name,mi),cond) base new = foldM try new $ Map.toList (jme
|
|||||||
| not (cond c) = return new
|
| not (cond c) = return new
|
||||||
| otherwise = case Map.lookup c new of
|
| otherwise = case Map.lookup c new of
|
||||||
Just j -> case unifyAnyInfo name i j of
|
Just j -> case unifyAnyInfo name i j of
|
||||||
Ok k -> return $ Map.insert c k new
|
Ok k -> return $ Map.insert c k new
|
||||||
Bad _ -> do (base,j) <- case j of
|
Bad _ -> do (base,j) <- case j of
|
||||||
AnyInd _ m -> lookupOrigInfo gr (m,c)
|
AnyInd _ m -> lookupOrigInfo gr (m,c)
|
||||||
_ -> return (base,j)
|
_ -> return (base,j)
|
||||||
(name,i) <- case i of
|
(name,i) <- case i of
|
||||||
AnyInd _ m -> lookupOrigInfo gr (m,c)
|
AnyInd _ m -> lookupOrigInfo gr (m,c)
|
||||||
_ -> return (name,i)
|
_ -> return (name,i)
|
||||||
checkError ("cannot unify the information" $$
|
checkError ("cannot unify the information" $$
|
||||||
nest 4 (ppJudgement Qualified (c,i)) $$
|
nest 4 (ppJudgement Qualified (c,i)) $$
|
||||||
"in module" <+> name <+> "with" $$
|
"in module" <+> name <+> "with" $$
|
||||||
nest 4 (ppJudgement Qualified (c,j)) $$
|
nest 4 (ppJudgement Qualified (c,j)) $$
|
||||||
"in module" <+> base)
|
"in module" <+> base)
|
||||||
Nothing-> if isCompl
|
Nothing-> if isCompl
|
||||||
then return $ Map.insert c (indirInfo name i) new
|
then return $ Map.insert c (indirInfo name i) new
|
||||||
else return $ Map.insert c i new
|
else return $ Map.insert c i new
|
||||||
|
|||||||
@@ -16,18 +16,18 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
module GF.Data.BacktrackM (
|
module GF.Data.BacktrackM (
|
||||||
-- * the backtracking state monad
|
-- * the backtracking state monad
|
||||||
BacktrackM,
|
BacktrackM,
|
||||||
-- * monad specific utilities
|
-- * monad specific utilities
|
||||||
member,
|
member,
|
||||||
cut,
|
cut,
|
||||||
-- * running the monad
|
-- * running the monad
|
||||||
foldBM, runBM,
|
foldBM, runBM,
|
||||||
foldSolutions, solutions,
|
foldSolutions, solutions,
|
||||||
foldFinalStates, finalStates,
|
foldFinalStates, finalStates,
|
||||||
|
|
||||||
-- * reexport the 'MonadState' class
|
-- * reexport the 'MonadState' class
|
||||||
module Control.Monad.State.Class,
|
module Control.Monad.State.Class,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
@@ -70,7 +70,7 @@ instance Applicative (BacktrackM s) where
|
|||||||
instance Monad (BacktrackM s) where
|
instance Monad (BacktrackM s) where
|
||||||
return a = BM (\c s b -> c a s b)
|
return a = BM (\c s b -> c a s b)
|
||||||
BM m >>= k = BM (\c s b -> m (\a s b -> unBM (k a) c s b) s b)
|
BM m >>= k = BM (\c s b -> m (\a s b -> unBM (k a) c s b) s b)
|
||||||
where unBM (BM m) = m
|
where unBM (BM m) = m
|
||||||
|
|
||||||
#if !(MIN_VERSION_base(4,13,0))
|
#if !(MIN_VERSION_base(4,13,0))
|
||||||
fail = Fail.fail
|
fail = Fail.fail
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import Data.Set (Set)
|
|||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
data Graph n a b = Graph [n] ![Node n a] ![Edge n b]
|
data Graph n a b = Graph [n] ![Node n a] ![Edge n b]
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
type Node n a = (n,a)
|
type Node n a = (n,a)
|
||||||
type Edge n b = (n,n,b)
|
type Edge n b = (n,n,b)
|
||||||
@@ -170,7 +170,7 @@ renameNodes :: (n -> m) -- ^ renaming function
|
|||||||
-> Graph n a b -> Graph m a b
|
-> Graph n a b -> Graph m a b
|
||||||
renameNodes newName c (Graph _ ns es) = Graph c ns' es'
|
renameNodes newName c (Graph _ ns es) = Graph c ns' es'
|
||||||
where ns' = map' (\ (n,x) -> (newName n,x)) ns
|
where ns' = map' (\ (n,x) -> (newName n,x)) ns
|
||||||
es' = map' (\ (f,t,l) -> (newName f, newName t, l)) es
|
es' = map' (\ (f,t,l) -> (newName f, newName t, l)) es
|
||||||
|
|
||||||
-- | A strict 'map'
|
-- | A strict 'map'
|
||||||
map' :: (a -> b) -> [a] -> [b]
|
map' :: (a -> b) -> [a] -> [b]
|
||||||
|
|||||||
@@ -13,14 +13,14 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Data.Graphviz (
|
module GF.Data.Graphviz (
|
||||||
Graph(..), GraphType(..),
|
Graph(..), GraphType(..),
|
||||||
Node(..), Edge(..),
|
Node(..), Edge(..),
|
||||||
Attr,
|
Attr,
|
||||||
addSubGraphs,
|
addSubGraphs,
|
||||||
setName,
|
setName,
|
||||||
setAttr,
|
setAttr,
|
||||||
prGraphviz
|
prGraphviz
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
|
||||||
@@ -76,8 +76,8 @@ prSubGraph g@(Graph _ i _ _ _ _) =
|
|||||||
prGraph :: Graph -> String
|
prGraph :: Graph -> String
|
||||||
prGraph (Graph t id at ns es ss) =
|
prGraph (Graph t id at ns es ss) =
|
||||||
unlines $ map (++";") (map prAttr at
|
unlines $ map (++";") (map prAttr at
|
||||||
++ map prNode ns
|
++ map prNode ns
|
||||||
++ map (prEdge t) es
|
++ map (prEdge t) es
|
||||||
++ map prSubGraph ss)
|
++ map prSubGraph ss)
|
||||||
|
|
||||||
graphtype :: GraphType -> String
|
graphtype :: GraphType -> String
|
||||||
@@ -96,7 +96,7 @@ edgeop Undirected = "--"
|
|||||||
|
|
||||||
prAttrList :: [Attr] -> String
|
prAttrList :: [Attr] -> String
|
||||||
prAttrList [] = ""
|
prAttrList [] = ""
|
||||||
prAttrList at = "[" ++ join "," (map prAttr at) ++ "]"
|
prAttrList at = "[" ++ join "," (map prAttr at) ++ "]"
|
||||||
|
|
||||||
prAttr :: Attr -> String
|
prAttr :: Attr -> String
|
||||||
prAttr (n,v) = esc n ++ " = " ++ esc v
|
prAttr (n,v) = esc n ++ " = " ++ esc v
|
||||||
|
|||||||
@@ -15,34 +15,34 @@
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Data.Operations (
|
module GF.Data.Operations (
|
||||||
-- ** The Error monad
|
-- ** The Error monad
|
||||||
Err(..), err, maybeErr, testErr, fromErr, errIn,
|
Err(..), err, maybeErr, testErr, fromErr, errIn,
|
||||||
lookupErr,
|
lookupErr,
|
||||||
|
|
||||||
-- ** Error monad class
|
-- ** Error monad class
|
||||||
ErrorMonad(..), checks, --doUntil, allChecks, checkAgain,
|
ErrorMonad(..), checks, --doUntil, allChecks, checkAgain,
|
||||||
liftErr,
|
liftErr,
|
||||||
|
|
||||||
-- ** Checking
|
-- ** Checking
|
||||||
checkUnique, unifyMaybeBy, unifyMaybe,
|
checkUnique, unifyMaybeBy, unifyMaybe,
|
||||||
|
|
||||||
-- ** Monadic operations on lists and pairs
|
-- ** Monadic operations on lists and pairs
|
||||||
mapPairsM, pairM,
|
mapPairsM, pairM,
|
||||||
|
|
||||||
-- ** Printing
|
-- ** Printing
|
||||||
indent, (+++), (++-), (++++), (+++-), (+++++),
|
indent, (+++), (++-), (++++), (+++-), (+++++),
|
||||||
prUpper, prReplicate, prTList, prQuotedString, prParenth, prCurly,
|
prUpper, prReplicate, prTList, prQuotedString, prParenth, prCurly,
|
||||||
prBracket, prArgList, prSemicList, prCurlyList, restoreEscapes,
|
prBracket, prArgList, prSemicList, prCurlyList, restoreEscapes,
|
||||||
numberedParagraphs, prConjList, prIfEmpty, wrapLines,
|
numberedParagraphs, prConjList, prIfEmpty, wrapLines,
|
||||||
|
|
||||||
-- ** Topological sorting
|
-- ** Topological sorting
|
||||||
topoTest, topoTest2,
|
topoTest, topoTest2,
|
||||||
|
|
||||||
-- ** Misc
|
-- ** Misc
|
||||||
readIntArg,
|
readIntArg,
|
||||||
iterFix, chunks,
|
iterFix, chunks,
|
||||||
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Char (isSpace, toUpper, isSpace, isDigit)
|
import Data.Char (isSpace, toUpper, isSpace, isDigit)
|
||||||
import Data.List (nub, partition, (\\))
|
import Data.List (nub, partition, (\\))
|
||||||
@@ -204,7 +204,7 @@ topoTest2 g0 = maybe (Right cycles) Left (tsort g)
|
|||||||
([],[]) -> Just []
|
([],[]) -> Just []
|
||||||
([],_) -> Nothing
|
([],_) -> Nothing
|
||||||
(ns,rest) -> (leaves:) `fmap` tsort [(n,es \\ leaves) | (n,es)<-rest]
|
(ns,rest) -> (leaves:) `fmap` tsort [(n,es \\ leaves) | (n,es)<-rest]
|
||||||
where leaves = map fst ns
|
where leaves = map fst ns
|
||||||
|
|
||||||
|
|
||||||
-- | Fix point iterator (for computing e.g. transitive closures or reachability)
|
-- | Fix point iterator (for computing e.g. transitive closures or reachability)
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ transitiveClosure r = fix (Map.map growSet) r
|
|||||||
where growSet ys = foldl Set.union ys (map (allRelated r) $ Set.toList ys)
|
where growSet ys = foldl Set.union ys (map (allRelated r) $ Set.toList ys)
|
||||||
|
|
||||||
reflexiveClosure_ :: Ord a => [a] -- ^ The set over which the relation is defined.
|
reflexiveClosure_ :: Ord a => [a] -- ^ The set over which the relation is defined.
|
||||||
-> Rel a -> Rel a
|
-> Rel a -> Rel a
|
||||||
reflexiveClosure_ u r = relates [(x,x) | x <- u] r
|
reflexiveClosure_ u r = relates [(x,x) | x <- u] r
|
||||||
|
|
||||||
-- | Uses 'domain'
|
-- | Uses 'domain'
|
||||||
@@ -117,8 +117,8 @@ equivalenceClasses :: Ord a => Rel a -> [Set a]
|
|||||||
equivalenceClasses r = equivalenceClasses_ (Map.keys r) r
|
equivalenceClasses r = equivalenceClasses_ (Map.keys r) r
|
||||||
where equivalenceClasses_ [] _ = []
|
where equivalenceClasses_ [] _ = []
|
||||||
equivalenceClasses_ (x:xs) r = ys:equivalenceClasses_ zs r
|
equivalenceClasses_ (x:xs) r = ys:equivalenceClasses_ zs r
|
||||||
where ys = allRelated r x
|
where ys = allRelated r x
|
||||||
zs = [x' | x' <- xs, not (x' `Set.member` ys)]
|
zs = [x' | x' <- xs, not (x' `Set.member` ys)]
|
||||||
|
|
||||||
isTransitive :: Ord a => Rel a -> Bool
|
isTransitive :: Ord a => Rel a -> Bool
|
||||||
isTransitive r = and [z `Set.member` ys | (x,ys) <- Map.toList r,
|
isTransitive r = and [z `Set.member` ys | (x,ys) <- Map.toList r,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ longerThan n = not . notLongerThan n
|
|||||||
lookupList :: Eq a => a -> [(a, b)] -> [b]
|
lookupList :: Eq a => a -> [(a, b)] -> [b]
|
||||||
lookupList a [] = []
|
lookupList a [] = []
|
||||||
lookupList a (p:ps) | a == fst p = snd p : lookupList a ps
|
lookupList a (p:ps) | a == fst p = snd p : lookupList a ps
|
||||||
| otherwise = lookupList a ps
|
| otherwise = lookupList a ps
|
||||||
|
|
||||||
split :: [a] -> ([a], [a])
|
split :: [a] -> ([a], [a])
|
||||||
split (x : y : as) = (x:xs, y:ys)
|
split (x : y : as) = (x:xs, y:ys)
|
||||||
@@ -48,8 +48,8 @@ splitBy p (a : as) = if p a then (a:xs, ys) else (xs, a:ys)
|
|||||||
foldMerge :: (a -> a -> a) -> a -> [a] -> a
|
foldMerge :: (a -> a -> a) -> a -> [a] -> a
|
||||||
foldMerge merge zero = fm
|
foldMerge merge zero = fm
|
||||||
where fm [] = zero
|
where fm [] = zero
|
||||||
fm [a] = a
|
fm [a] = a
|
||||||
fm abs = let (as, bs) = split abs in fm as `merge` fm bs
|
fm abs = let (as, bs) = split abs in fm as `merge` fm bs
|
||||||
|
|
||||||
select :: [a] -> [(a, [a])]
|
select :: [a] -> [(a, [a])]
|
||||||
select [] = []
|
select [] = []
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ type AlexInput2 = (AlexInput,AlexInput)
|
|||||||
|
|
||||||
data ParseResult a
|
data ParseResult a
|
||||||
= POk AlexInput2 a
|
= POk AlexInput2 a
|
||||||
| PFailed Posn -- The position of the error
|
| PFailed Posn -- The position of the error
|
||||||
String -- The error message
|
String -- The error message
|
||||||
|
|
||||||
newtype P a = P { unP :: AlexInput2 -> ParseResult a }
|
newtype P a = P { unP :: AlexInput2 -> ParseResult a }
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module GF.Grammar.Lookup (
|
|||||||
lookupFunType,
|
lookupFunType,
|
||||||
lookupCatContext,
|
lookupCatContext,
|
||||||
allOpers, allOpersTo
|
allOpers, allOpersTo
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
|
|||||||
@@ -12,11 +12,12 @@
|
|||||||
-- pattern matching for both concrete and abstract syntax. AR -- 16\/6\/2003
|
-- pattern matching for both concrete and abstract syntax. AR -- 16\/6\/2003
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Grammar.PatternMatch (matchPattern,
|
module GF.Grammar.PatternMatch (
|
||||||
testOvershadow,
|
matchPattern,
|
||||||
findMatch,
|
testOvershadow,
|
||||||
measurePatt
|
findMatch,
|
||||||
) where
|
measurePatt
|
||||||
|
) where
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
import GF.Grammar.Grammar
|
import GF.Grammar.Grammar
|
||||||
|
|||||||
@@ -175,18 +175,18 @@ ppTerm q d (Abs b v e) = let (xs,e') = getAbs (Abs b v e)
|
|||||||
in prec d 0 ('\\' <> commaPunct ppBind xs <+> "->" <+> ppTerm q 0 e')
|
in prec d 0 ('\\' <> commaPunct ppBind xs <+> "->" <+> ppTerm q 0 e')
|
||||||
ppTerm q d (T TRaw xs) = case getCTable (T TRaw xs) of
|
ppTerm q d (T TRaw xs) = case getCTable (T TRaw xs) of
|
||||||
([],_) -> "table" <+> '{' $$
|
([],_) -> "table" <+> '{' $$
|
||||||
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
||||||
'}'
|
'}'
|
||||||
(vs,e) -> prec d 0 ("\\\\" <> commaPunct pp vs <+> "=>" <+> ppTerm q 0 e)
|
(vs,e) -> prec d 0 ("\\\\" <> commaPunct pp vs <+> "=>" <+> ppTerm q 0 e)
|
||||||
ppTerm q d (T (TTyped t) xs) = "table" <+> ppTerm q 0 t <+> '{' $$
|
ppTerm q d (T (TTyped t) xs) = "table" <+> ppTerm q 0 t <+> '{' $$
|
||||||
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
||||||
'}'
|
'}'
|
||||||
ppTerm q d (T (TComp t) xs) = "table" <+> ppTerm q 0 t <+> '{' $$
|
ppTerm q d (T (TComp t) xs) = "table" <+> ppTerm q 0 t <+> '{' $$
|
||||||
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
||||||
'}'
|
'}'
|
||||||
ppTerm q d (T (TWild t) xs) = "table" <+> ppTerm q 0 t <+> '{' $$
|
ppTerm q d (T (TWild t) xs) = "table" <+> ppTerm q 0 t <+> '{' $$
|
||||||
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
||||||
'}'
|
'}'
|
||||||
ppTerm q d (Prod bt x a b)= if x == identW && bt == Explicit
|
ppTerm q d (Prod bt x a b)= if x == identW && bt == Explicit
|
||||||
then prec d 0 (ppTerm q 4 a <+> "->" <+> ppTerm q 0 b)
|
then prec d 0 (ppTerm q 4 a <+> "->" <+> ppTerm q 0 b)
|
||||||
else prec d 0 (parens (ppBind (bt,x) <+> ':' <+> ppTerm q 0 a) <+> "->" <+> ppTerm q 0 b)
|
else prec d 0 (parens (ppBind (bt,x) <+> ':' <+> ppTerm q 0 a) <+> "->" <+> ppTerm q 0 b)
|
||||||
@@ -198,14 +198,14 @@ ppTerm q d (C e1 e2) =prec d 1 (hang (ppTerm q 2 e1) 2 ("++" <+> ppTerm q 1 e
|
|||||||
ppTerm q d (Glue e1 e2) =prec d 2 (ppTerm q 3 e1 <+> '+' <+> ppTerm q 2 e2)
|
ppTerm q d (Glue e1 e2) =prec d 2 (ppTerm q 3 e1 <+> '+' <+> ppTerm q 2 e2)
|
||||||
ppTerm q d (S x y) = case x of
|
ppTerm q d (S x y) = case x of
|
||||||
T annot xs -> let e = case annot of
|
T annot xs -> let e = case annot of
|
||||||
TRaw -> y
|
TRaw -> y
|
||||||
TTyped t -> Typed y t
|
TTyped t -> Typed y t
|
||||||
TComp t -> Typed y t
|
TComp t -> Typed y t
|
||||||
TWild t -> Typed y t
|
TWild t -> Typed y t
|
||||||
in "case" <+> ppTerm q 0 e <+>"of" <+> '{' $$
|
in "case" <+> ppTerm q 0 e <+>"of" <+> '{' $$
|
||||||
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
nest 2 (vcat (punctuate ';' (map (ppCase q) xs))) $$
|
||||||
'}'
|
'}'
|
||||||
_ -> prec d 3 (hang (ppTerm q 3 x) 2 ("!" <+> ppTerm q 4 y))
|
_ -> prec d 3 (hang (ppTerm q 3 x) 2 ("!" <+> ppTerm q 4 y))
|
||||||
ppTerm q d (ExtR x y) = prec d 3 (ppTerm q 3 x <+> "**" <+> ppTerm q 4 y)
|
ppTerm q d (ExtR x y) = prec d 3 (ppTerm q 3 x <+> "**" <+> ppTerm q 4 y)
|
||||||
ppTerm q d (App x y) = prec d 4 (ppTerm q 4 x <+> ppTerm q 5 y)
|
ppTerm q d (App x y) = prec d 4 (ppTerm q 4 x <+> ppTerm q 5 y)
|
||||||
ppTerm q d (V e es) = hang "table" 2 (sep [ppTerm q 6 e,brackets (fsep (punctuate ';' (map (ppTerm q 0) es)))])
|
ppTerm q d (V e es) = hang "table" 2 (sep [ppTerm q 6 e,brackets (fsep (punctuate ';' (map (ppTerm q 0) es)))])
|
||||||
@@ -362,4 +362,3 @@ getLet :: Term -> ([LocalDef], Term)
|
|||||||
getLet (Let l e) = let (ls,e') = getLet e
|
getLet (Let l e) = let (ls,e') = getLet e
|
||||||
in (l:ls,e')
|
in (l:ls,e')
|
||||||
getLet e = ([],e)
|
getLet e = ([],e)
|
||||||
|
|
||||||
|
|||||||
@@ -12,15 +12,16 @@
|
|||||||
-- (Description of the module)
|
-- (Description of the module)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module GF.Grammar.Values (-- ** Values used in TC type checking
|
module GF.Grammar.Values (
|
||||||
Val(..), Env,
|
-- ** Values used in TC type checking
|
||||||
-- ** Annotated tree used in editing
|
Val(..), Env,
|
||||||
|
-- ** Annotated tree used in editing
|
||||||
Binds, Constraints, MetaSubst,
|
Binds, Constraints, MetaSubst,
|
||||||
-- ** For TC
|
-- ** For TC
|
||||||
valAbsInt, valAbsFloat, valAbsString, vType,
|
valAbsInt, valAbsFloat, valAbsString, vType,
|
||||||
isPredefCat,
|
isPredefCat,
|
||||||
eType,
|
eType,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import GF.Infra.Ident
|
import GF.Infra.Ident
|
||||||
import GF.Grammar.Grammar
|
import GF.Grammar.Grammar
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
module GF.Infra.CheckM
|
module GF.Infra.CheckM
|
||||||
(Check, CheckResult, Message, runCheck, runCheck',
|
(Check, CheckResult, Message, runCheck, runCheck',
|
||||||
checkError, checkCond, checkWarn, checkWarnings, checkAccumError,
|
checkError, checkCond, checkWarn, checkWarnings, checkAccumError,
|
||||||
checkIn, checkInModule, checkMap, checkMapRecover,
|
checkIn, checkInModule, checkMap, checkMapRecover,
|
||||||
parallelCheck, accumulateError, commitCheck,
|
parallelCheck, accumulateError, commitCheck,
|
||||||
) where
|
) where
|
||||||
import Prelude hiding ((<>)) -- GHC 8.4.1 clash with Text.PrettyPrint
|
import Prelude hiding ((<>)) -- GHC 8.4.1 clash with Text.PrettyPrint
|
||||||
|
|
||||||
import GF.Data.Operations
|
import GF.Data.Operations
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ wc_type = cmd_name
|
|||||||
x2 = takeWhile (\c -> isIdent c || isSpace c || c == '-' || c == '=' || c == '"') x1
|
x2 = takeWhile (\c -> isIdent c || isSpace c || c == '-' || c == '=' || c == '"') x1
|
||||||
|
|
||||||
cmd = case [x | (x,cs) <- RP.readP_to_S pCommand x2, all isSpace cs] of
|
cmd = case [x | (x,cs) <- RP.readP_to_S pCommand x2, all isSpace cs] of
|
||||||
[x] -> Just x
|
[x] -> Just x
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
isIdent c = c == '_' || c == '\'' || isAlphaNum c
|
isIdent c = c == '_' || c == '\'' || isAlphaNum c
|
||||||
|
|||||||
@@ -12,15 +12,15 @@
|
|||||||
-- A simple finite state network module.
|
-- A simple finite state network module.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
module GF.Speech.FiniteState (FA(..), State, NFA, DFA,
|
module GF.Speech.FiniteState (FA(..), State, NFA, DFA,
|
||||||
startState, finalStates,
|
startState, finalStates,
|
||||||
states, transitions,
|
states, transitions,
|
||||||
isInternal,
|
isInternal,
|
||||||
newFA, newFA_,
|
newFA, newFA_,
|
||||||
addFinalState,
|
addFinalState,
|
||||||
newState, newStates,
|
newState, newStates,
|
||||||
newTransition, newTransitions,
|
newTransition, newTransitions,
|
||||||
insertTransitionWith, insertTransitionsWith,
|
insertTransitionWith, insertTransitionsWith,
|
||||||
mapStates, mapTransitions,
|
mapStates, mapTransitions,
|
||||||
modifyTransitions,
|
modifyTransitions,
|
||||||
nonLoopTransitionsTo, nonLoopTransitionsFrom,
|
nonLoopTransitionsTo, nonLoopTransitionsFrom,
|
||||||
loops,
|
loops,
|
||||||
@@ -28,11 +28,11 @@ module GF.Speech.FiniteState (FA(..), State, NFA, DFA,
|
|||||||
oneFinalState,
|
oneFinalState,
|
||||||
insertNFA,
|
insertNFA,
|
||||||
onGraph,
|
onGraph,
|
||||||
moveLabelsToNodes, removeTrivialEmptyNodes,
|
moveLabelsToNodes, removeTrivialEmptyNodes,
|
||||||
minimize,
|
minimize,
|
||||||
dfa2nfa,
|
dfa2nfa,
|
||||||
unusedNames, renameStates,
|
unusedNames, renameStates,
|
||||||
prFAGraphviz, faToGraphviz) where
|
prFAGraphviz, faToGraphviz) where
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@@ -145,7 +145,7 @@ renameStates :: Ord x => [y] -- ^ Infinite supply of new names
|
|||||||
renameStates supply (FA g s fs) = FA (renameNodes newName rest g) s' fs'
|
renameStates supply (FA g s fs) = FA (renameNodes newName rest g) s' fs'
|
||||||
where (ns,rest) = splitAt (length (nodes g)) supply
|
where (ns,rest) = splitAt (length (nodes g)) supply
|
||||||
newNodes = Map.fromList (zip (map fst (nodes g)) ns)
|
newNodes = Map.fromList (zip (map fst (nodes g)) ns)
|
||||||
newName n = Map.findWithDefault (error "FiniteState.newName") n newNodes
|
newName n = Map.findWithDefault (error "FiniteState.newName") n newNodes
|
||||||
s' = newName s
|
s' = newName s
|
||||||
fs' = map newName fs
|
fs' = map newName fs
|
||||||
|
|
||||||
@@ -182,9 +182,9 @@ oneFinalState nl el fa =
|
|||||||
moveLabelsToNodes :: (Ord n,Eq a) => FA n () (Maybe a) -> FA n (Maybe a) ()
|
moveLabelsToNodes :: (Ord n,Eq a) => FA n () (Maybe a) -> FA n (Maybe a) ()
|
||||||
moveLabelsToNodes = onGraph f
|
moveLabelsToNodes = onGraph f
|
||||||
where f g@(Graph c _ _) = Graph c' ns (concat ess)
|
where f g@(Graph c _ _) = Graph c' ns (concat ess)
|
||||||
where is = [ ((n,l),inc) | (n, (l,inc,_)) <- Map.toList (nodeInfo g)]
|
where is = [ ((n,l),inc) | (n, (l,inc,_)) <- Map.toList (nodeInfo g)]
|
||||||
(c',is') = mapAccumL fixIncoming c is
|
(c',is') = mapAccumL fixIncoming c is
|
||||||
(ns,ess) = unzip (concat is')
|
(ns,ess) = unzip (concat is')
|
||||||
|
|
||||||
|
|
||||||
-- | Remove empty nodes which are not start or final, and have
|
-- | Remove empty nodes which are not start or final, and have
|
||||||
@@ -234,17 +234,17 @@ fixIncoming :: (Ord n, Eq a) => [n]
|
|||||||
-- incoming edges.
|
-- incoming edges.
|
||||||
fixIncoming cs c@((n,()),es) = (cs'', ((n,Nothing),es'):newContexts)
|
fixIncoming cs c@((n,()),es) = (cs'', ((n,Nothing),es'):newContexts)
|
||||||
where ls = nub $ map edgeLabel es
|
where ls = nub $ map edgeLabel es
|
||||||
(cs',cs'') = splitAt (length ls) cs
|
(cs',cs'') = splitAt (length ls) cs
|
||||||
newNodes = zip cs' ls
|
newNodes = zip cs' ls
|
||||||
es' = [ (x,n,()) | x <- map fst newNodes ]
|
es' = [ (x,n,()) | x <- map fst newNodes ]
|
||||||
-- separate cyclic and non-cyclic edges
|
-- separate cyclic and non-cyclic edges
|
||||||
(cyc,ncyc) = partition (\ (f,_,_) -> f == n) es
|
(cyc,ncyc) = partition (\ (f,_,_) -> f == n) es
|
||||||
-- keep all incoming non-cyclic edges with the right label
|
-- keep all incoming non-cyclic edges with the right label
|
||||||
to (x,l) = [ (f,x,()) | (f,_,l') <- ncyc, l == l']
|
to (x,l) = [ (f,x,()) | (f,_,l') <- ncyc, l == l']
|
||||||
-- for each cyclic edge with the right label,
|
-- for each cyclic edge with the right label,
|
||||||
-- add an edge from each of the new nodes (including this one)
|
-- add an edge from each of the new nodes (including this one)
|
||||||
++ [ (y,x,()) | (f,_,l') <- cyc, l == l', (y,_) <- newNodes]
|
++ [ (y,x,()) | (f,_,l') <- cyc, l == l', (y,_) <- newNodes]
|
||||||
newContexts = [ (v, to v) | v <- newNodes ]
|
newContexts = [ (v, to v) | v <- newNodes ]
|
||||||
|
|
||||||
--alphabet :: Eq b => Graph n a (Maybe b) -> [b]
|
--alphabet :: Eq b => Graph n a (Maybe b) -> [b]
|
||||||
--alphabet = nub . catMaybes . map edgeLabel . edges
|
--alphabet = nub . catMaybes . map edgeLabel . edges
|
||||||
@@ -254,18 +254,18 @@ determinize (FA g s f) = let (ns,es) = h (Set.singleton start) Set.empty Set.emp
|
|||||||
(ns',es') = (Set.toList ns, Set.toList es)
|
(ns',es') = (Set.toList ns, Set.toList es)
|
||||||
final = filter isDFAFinal ns'
|
final = filter isDFAFinal ns'
|
||||||
fa = FA (Graph undefined [(n,()) | n <- ns'] es') start final
|
fa = FA (Graph undefined [(n,()) | n <- ns'] es') start final
|
||||||
in renameStates [0..] fa
|
in renameStates [0..] fa
|
||||||
where info = nodeInfo g
|
where info = nodeInfo g
|
||||||
-- reach = nodesReachable out
|
-- reach = nodesReachable out
|
||||||
start = closure info $ Set.singleton s
|
start = closure info $ Set.singleton s
|
||||||
isDFAFinal n = not (Set.null (Set.fromList f `Set.intersection` n))
|
isDFAFinal n = not (Set.null (Set.fromList f `Set.intersection` n))
|
||||||
h currentStates oldStates es
|
h currentStates oldStates es
|
||||||
| Set.null currentStates = (oldStates,es)
|
| Set.null currentStates = (oldStates,es)
|
||||||
| otherwise = ((h $! uniqueNewStates) $! allOldStates) $! es'
|
| otherwise = ((h $! uniqueNewStates) $! allOldStates) $! es'
|
||||||
where
|
where
|
||||||
allOldStates = oldStates `Set.union` currentStates
|
allOldStates = oldStates `Set.union` currentStates
|
||||||
(newStates,es') = new (Set.toList currentStates) Set.empty es
|
(newStates,es') = new (Set.toList currentStates) Set.empty es
|
||||||
uniqueNewStates = newStates Set.\\ allOldStates
|
uniqueNewStates = newStates Set.\\ allOldStates
|
||||||
-- Get the sets of states reachable from the given states
|
-- Get the sets of states reachable from the given states
|
||||||
-- by consuming one symbol, and the associated edges.
|
-- by consuming one symbol, and the associated edges.
|
||||||
new [] rs es = (rs,es)
|
new [] rs es = (rs,es)
|
||||||
@@ -296,8 +296,8 @@ reachable1 info ns = Map.fromListWith (++) [(c, [y]) | n <- Set.toList ns, (_,y,
|
|||||||
reverseNFA :: NFA a -> NFA a
|
reverseNFA :: NFA a -> NFA a
|
||||||
reverseNFA (FA g s fs) = FA g''' s' [s]
|
reverseNFA (FA g s fs) = FA g''' s' [s]
|
||||||
where g' = reverseGraph g
|
where g' = reverseGraph g
|
||||||
(g'',s') = newNode () g'
|
(g'',s') = newNode () g'
|
||||||
g''' = newEdges [(s',f,Nothing) | f <- fs] g''
|
g''' = newEdges [(s',f,Nothing) | f <- fs] g''
|
||||||
|
|
||||||
dfa2nfa :: DFA a -> NFA a
|
dfa2nfa :: DFA a -> NFA a
|
||||||
dfa2nfa = mapTransitions Just
|
dfa2nfa = mapTransitions Just
|
||||||
@@ -316,10 +316,10 @@ faToGraphviz :: (Eq n,Show n) => FA n String String -> Dot.Graph
|
|||||||
faToGraphviz (FA (Graph _ ns es) s f)
|
faToGraphviz (FA (Graph _ ns es) s f)
|
||||||
= Dot.Graph Dot.Directed Nothing [] (map mkNode ns) (map mkEdge es) []
|
= Dot.Graph Dot.Directed Nothing [] (map mkNode ns) (map mkEdge es) []
|
||||||
where mkNode (n,l) = Dot.Node (show n) attrs
|
where mkNode (n,l) = Dot.Node (show n) attrs
|
||||||
where attrs = [("label",l)]
|
where attrs = [("label",l)]
|
||||||
++ if n == s then [("shape","box")] else []
|
++ if n == s then [("shape","box")] else []
|
||||||
++ if n `elem` f then [("style","bold")] else []
|
++ if n `elem` f then [("style","bold")] else []
|
||||||
mkEdge (x,y,l) = Dot.Edge (show x) (show y) [("label",l)]
|
mkEdge (x,y,l) = Dot.Edge (show x) (show y) [("label",l)]
|
||||||
|
|
||||||
--
|
--
|
||||||
-- * Utilities
|
-- * Utilities
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ prGSL :: SRG -> Doc
|
|||||||
prGSL srg = header $++$ mainCat $++$ foldr ($++$) empty (map prRule (srgRules srg))
|
prGSL srg = header $++$ mainCat $++$ foldr ($++$) empty (map prRule (srgRules srg))
|
||||||
where
|
where
|
||||||
header = ";GSL2.0" $$
|
header = ";GSL2.0" $$
|
||||||
comment ("Nuance speech recognition grammar for " ++ srgName srg) $$
|
comment ("Nuance speech recognition grammar for " ++ srgName srg) $$
|
||||||
comment ("Generated by GF")
|
comment ("Generated by GF")
|
||||||
mainCat = ".MAIN" <+> prCat (srgStartCat srg)
|
mainCat = ".MAIN" <+> prCat (srgStartCat srg)
|
||||||
prRule (SRGRule cat rhs) = prCat cat <+> union (map prAlt rhs)
|
prRule (SRGRule cat rhs) = prCat cat <+> union (map prAlt rhs)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ width :: Int
|
|||||||
width = 75
|
width = 75
|
||||||
|
|
||||||
jsgfPrinter :: Options
|
jsgfPrinter :: Options
|
||||||
-> PGF
|
-> PGF
|
||||||
-> CId -> String
|
-> CId -> String
|
||||||
jsgfPrinter opts pgf cnc = renderStyle st $ prJSGF sisr $ makeNonLeftRecursiveSRG opts pgf cnc
|
jsgfPrinter opts pgf cnc = renderStyle st $ prJSGF sisr $ makeNonLeftRecursiveSRG opts pgf cnc
|
||||||
where st = style { lineLength = width }
|
where st = style { lineLength = width }
|
||||||
@@ -44,7 +44,7 @@ prJSGF sisr srg
|
|||||||
header = "#JSGF" <+> "V1.0" <+> "UTF-8" <+> lang <> ';' $$
|
header = "#JSGF" <+> "V1.0" <+> "UTF-8" <+> lang <> ';' $$
|
||||||
comment ("JSGF speech recognition grammar for " ++ srgName srg) $$
|
comment ("JSGF speech recognition grammar for " ++ srgName srg) $$
|
||||||
comment "Generated by GF" $$
|
comment "Generated by GF" $$
|
||||||
("grammar " ++ srgName srg ++ ";")
|
("grammar " ++ srgName srg ++ ";")
|
||||||
lang = maybe empty pp (srgLanguage srg)
|
lang = maybe empty pp (srgLanguage srg)
|
||||||
mainCat = rule True "MAIN" [prCat (srgStartCat srg)]
|
mainCat = rule True "MAIN" [prCat (srgStartCat srg)]
|
||||||
prRule (SRGRule cat rhs) = rule (isExternalCat srg cat) cat (map prAlt rhs)
|
prRule (SRGRule cat rhs) = rule (isExternalCat srg cat) cat (map prAlt rhs)
|
||||||
@@ -110,4 +110,3 @@ prepunctuate p (x:xs) = x : map (p <>) xs
|
|||||||
|
|
||||||
($++$) :: Doc -> Doc -> Doc
|
($++$) :: Doc -> Doc -> Doc
|
||||||
x $++$ y = x $$ emptyLine $$ y
|
x $++$ y = x $$ emptyLine $$ y
|
||||||
|
|
||||||
|
|||||||
@@ -40,20 +40,20 @@ import qualified Data.Set as Set
|
|||||||
--import Debug.Trace
|
--import Debug.Trace
|
||||||
|
|
||||||
data SRG = SRG { srgName :: String -- ^ grammar name
|
data SRG = SRG { srgName :: String -- ^ grammar name
|
||||||
, srgStartCat :: Cat -- ^ start category name
|
, srgStartCat :: Cat -- ^ start category name
|
||||||
, srgExternalCats :: Set Cat
|
, srgExternalCats :: Set Cat
|
||||||
, srgLanguage :: Maybe String -- ^ The language for which the grammar
|
, srgLanguage :: Maybe String -- ^ The language for which the grammar
|
||||||
-- is intended, e.g. en-UK
|
-- is intended, e.g. en-UK
|
||||||
, srgRules :: [SRGRule]
|
, srgRules :: [SRGRule]
|
||||||
}
|
}
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
data SRGRule = SRGRule Cat [SRGAlt]
|
data SRGRule = SRGRule Cat [SRGAlt]
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
-- | maybe a probability, a rule name and an EBNF right-hand side
|
-- | maybe a probability, a rule name and an EBNF right-hand side
|
||||||
data SRGAlt = SRGAlt (Maybe Double) CFTerm SRGItem
|
data SRGAlt = SRGAlt (Maybe Double) CFTerm SRGItem
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show)
|
||||||
|
|
||||||
type SRGItem = RE SRGSymbol
|
type SRGItem = RE SRGSymbol
|
||||||
|
|
||||||
@@ -111,10 +111,10 @@ makeNonRecursiveSRG opts = mkSRG cfgToSRG id
|
|||||||
mkSRG :: (CFG -> [SRGRule]) -> (CFG -> CFG) -> PGF -> CId -> SRG
|
mkSRG :: (CFG -> [SRGRule]) -> (CFG -> CFG) -> PGF -> CId -> SRG
|
||||||
mkSRG mkRules preprocess pgf cnc =
|
mkSRG mkRules preprocess pgf cnc =
|
||||||
SRG { srgName = showCId cnc,
|
SRG { srgName = showCId cnc,
|
||||||
srgStartCat = cfgStartCat cfg,
|
srgStartCat = cfgStartCat cfg,
|
||||||
srgExternalCats = cfgExternalCats cfg,
|
srgExternalCats = cfgExternalCats cfg,
|
||||||
srgLanguage = languageCode pgf cnc,
|
srgLanguage = languageCode pgf cnc,
|
||||||
srgRules = mkRules cfg }
|
srgRules = mkRules cfg }
|
||||||
where cfg = renameCats (showCId cnc) $ preprocess $ pgfToCFG pgf cnc
|
where cfg = renameCats (showCId cnc) $ preprocess $ pgfToCFG pgf cnc
|
||||||
|
|
||||||
-- | Renames all external cats C to C_cat, and all internal cats C_X (where X is any string),
|
-- | Renames all external cats C to C_cat, and all internal cats C_X (where X is any string),
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ width :: Int
|
|||||||
width = 75
|
width = 75
|
||||||
|
|
||||||
srgsAbnfPrinter :: Options
|
srgsAbnfPrinter :: Options
|
||||||
-> PGF -> CId -> String
|
-> PGF -> CId -> String
|
||||||
srgsAbnfPrinter opts pgf cnc = showDoc $ prABNF sisr $ makeNonLeftRecursiveSRG opts pgf cnc
|
srgsAbnfPrinter opts pgf cnc = showDoc $ prABNF sisr $ makeNonLeftRecursiveSRG opts pgf cnc
|
||||||
where sisr = flag optSISR opts
|
where sisr = flag optSISR opts
|
||||||
|
|
||||||
@@ -125,4 +125,3 @@ prepunctuate p (x:xs) = x : map (p <>) xs
|
|||||||
|
|
||||||
($++$) :: Doc -> Doc -> Doc
|
($++$) :: Doc -> Doc -> Doc
|
||||||
x $++$ y = x $$ emptyLine $$ y
|
x $++$ y = x $$ emptyLine $$ y
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ prSrgsXml sisr srg = showXMLDoc (optimizeSRGS xmlGr)
|
|||||||
[meta "description"
|
[meta "description"
|
||||||
("SRGS XML speech recognition grammar for " ++ srgName srg ++ "."),
|
("SRGS XML speech recognition grammar for " ++ srgName srg ++ "."),
|
||||||
meta "generator" "Grammatical Framework"]
|
meta "generator" "Grammatical Framework"]
|
||||||
++ map ruleToXML (srgRules srg)
|
++ map ruleToXML (srgRules srg)
|
||||||
ruleToXML (SRGRule cat alts) = Tag "rule" ([("id",cat)]++pub) (prRhs alts)
|
ruleToXML (SRGRule cat alts) = Tag "rule" ([("id",cat)]++pub) (prRhs alts)
|
||||||
where pub = if isExternalCat srg cat then [("scope","public")] else []
|
where pub = if isExternalCat srg cat then [("scope","public")] else []
|
||||||
prRhs rhss = [oneOf (map (mkProd sisr) rhss)]
|
prRhs rhss = [oneOf (map (mkProd sisr) rhss)]
|
||||||
@@ -81,12 +81,12 @@ oneOf = Tag "one-of" []
|
|||||||
grammar :: Maybe SISRFormat
|
grammar :: Maybe SISRFormat
|
||||||
-> String -- ^ root
|
-> String -- ^ root
|
||||||
-> Maybe String -- ^language
|
-> Maybe String -- ^language
|
||||||
-> [XML] -> XML
|
-> [XML] -> XML
|
||||||
grammar sisr root ml =
|
grammar sisr root ml =
|
||||||
Tag "grammar" $ [("xmlns","http://www.w3.org/2001/06/grammar"),
|
Tag "grammar" $ [("xmlns","http://www.w3.org/2001/06/grammar"),
|
||||||
("version","1.0"),
|
("version","1.0"),
|
||||||
("mode","voice"),
|
("mode","voice"),
|
||||||
("root",root)]
|
("root",root)]
|
||||||
++ (if isJust sisr then [("tag-format","semantics/1.0")] else [])
|
++ (if isJust sisr then [("tag-format","semantics/1.0")] else [])
|
||||||
++ maybe [] (\l -> [("xml:lang", l)]) ml
|
++ maybe [] (\l -> [("xml:lang", l)]) ml
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ transUrdu =
|
|||||||
(mkTransliteration "Urdu" allTrans allCodes) where
|
(mkTransliteration "Urdu" allTrans allCodes) where
|
||||||
allCodes = [0x0622 .. 0x062f] ++ [0x0630 .. 0x063a] ++ [0x0641,0x0642] ++ [0x06A9] ++ [0x0644 .. 0x0648] ++
|
allCodes = [0x0622 .. 0x062f] ++ [0x0630 .. 0x063a] ++ [0x0641,0x0642] ++ [0x06A9] ++ [0x0644 .. 0x0648] ++
|
||||||
[0x0654,0x0658,0x0679,0x067e,0x0686,0x0688,0x0691,0x0698,0x06af,0x06c1,0x06c3,0x06cc,0x06ba,0x06be,0x06d2] ++
|
[0x0654,0x0658,0x0679,0x067e,0x0686,0x0688,0x0691,0x0698,0x06af,0x06c1,0x06c3,0x06cc,0x06ba,0x06be,0x06d2] ++
|
||||||
[0x06f0 .. 0x06f9] ++ [0x061f,0x06D4]
|
[0x06f0 .. 0x06f9] ++ [0x061f,0x06D4]
|
||||||
allTrans = words $
|
allTrans = words $
|
||||||
"A - w^ - y^ a b - t C j H K d " ++ -- 0622 - 062f
|
"A - w^ - y^ a b - t C j H K d " ++ -- 0622 - 062f
|
||||||
"Z r z s X S Z- t- z- e G " ++ -- 0630 - 063a
|
"Z r z s X S Z- t- z- e G " ++ -- 0630 - 063a
|
||||||
@@ -156,7 +156,7 @@ transSindhi =
|
|||||||
allCodes = [0x062e] ++ [0x0627 .. 0x062f] ++ [0x0630 .. 0x063a] ++ [0x0641 .. 0x0648] ++
|
allCodes = [0x062e] ++ [0x0627 .. 0x062f] ++ [0x0630 .. 0x063a] ++ [0x0641 .. 0x0648] ++
|
||||||
[0x067a,0x067b,0x067d,0x067e,0x067f] ++ [0x0680 .. 0x068f] ++
|
[0x067a,0x067b,0x067d,0x067e,0x067f] ++ [0x0680 .. 0x068f] ++
|
||||||
[0x0699,0x0918,0x06a6,0x061d,0x06a9,0x06af,0x06b3,0x06bb,0x06be,0x06f6,0x064a,0x06b1, 0x06aa, 0x06fd, 0x06fe] ++
|
[0x0699,0x0918,0x06a6,0x061d,0x06a9,0x06af,0x06b3,0x06bb,0x06be,0x06f6,0x064a,0x06b1, 0x06aa, 0x06fd, 0x06fe] ++
|
||||||
[0x06f0 .. 0x06f9] ++ [0x061f,0x06D4]
|
[0x06f0 .. 0x06f9] ++ [0x061f,0x06D4]
|
||||||
allTrans = words $
|
allTrans = words $
|
||||||
"K a b - t C j H - d " ++ -- 0626 - 062f
|
"K a b - t C j H - d " ++ -- 0626 - 062f
|
||||||
"Z r z s X S Z- t- z- e G " ++ -- 0630 - 063a
|
"Z r z s X S Z- t- z- e G " ++ -- 0630 - 063a
|
||||||
@@ -300,32 +300,30 @@ transAncientGreek = mkTransliteration "ancient Greek" allTrans allCodes where
|
|||||||
|
|
||||||
transAmharic :: Transliteration
|
transAmharic :: Transliteration
|
||||||
transAmharic = mkTransliteration "Amharic" allTrans allCodes where
|
transAmharic = mkTransliteration "Amharic" allTrans allCodes where
|
||||||
|
allTrans = words $
|
||||||
allTrans = words $
|
" h. h- h' h( h) h h? h* l. l- l' l( l) l l? l* "++
|
||||||
|
" H. H- H' H( H) H H? H* m. m- m' m( m) m m? m* "++
|
||||||
" h. h- h' h( h) h h? h* l. l- l' l( l) l l? l* "++
|
" s. s- s' s( s) s s? s* r. r- r' r( r) r r? r* "++
|
||||||
" H. H- H' H( H) H H? H* m. m- m' m( m) m m? m* "++
|
" - - - - - - - - x. x- x' x( x) x x? x* "++
|
||||||
" s. s- s' s( s) s s? s* r. r- r' r( r) r r? r* "++
|
" q. q- q' q( q) q q? q* - - - - - - - - "++
|
||||||
" - - - - - - - - x. x- x' x( x) x x? x* "++
|
" - - - - - - - - - - - - - - - - "++
|
||||||
" q. q- q' q( q) q q? q* - - - - - - - - "++
|
" b. b- b' b( b) b b? b* v. v- v' v( v) v v? v* "++
|
||||||
" - - - - - - - - - - - - - - - - "++
|
" t. t- t' t( t) t t? t* c. c- c' c( c) c c? c* "++
|
||||||
" b. b- b' b( b) b b? b* v. v- v' v( v) v v? v* "++
|
" X. X- X' X( X) X X? - - - - X* - - - - "++
|
||||||
" t. t- t' t( t) t t? t* c. c- c' c( c) c c? c* "++
|
" n. n- n' n( n) n n? n* N. N- N' N( N) N N? N* "++
|
||||||
" X. X- X' X( X) X X? - - - - X* - - - - "++
|
" a u i A E e o e* k. k- k' k( k) k k? - "++
|
||||||
" n. n- n' n( n) n n? n* N. N- N' N( N) N N? N* "++
|
" - - - k* - - - - - - - - - - - - "++
|
||||||
" a u i A E e o e* k. k- k' k( k) k k? - "++
|
" - - - - - - - - w. w- w' w( w) w w? w* "++
|
||||||
" - - - k* - - - - - - - - - - - - "++
|
" - - - - - - - - z. z- z' z( z) z z? z* "++
|
||||||
" - - - - - - - - w. w- w' w( w) w w? w* "++
|
" Z. Z- Z' Z( Z) Z Z? Z* y. y- y' y( y) y y? y* "++
|
||||||
" - - - - - - - - z. z- z' z( z) z z? z* "++
|
" d. d- d' d( d) d d? d* - - - - - - - - "++
|
||||||
" Z. Z- Z' Z( Z) Z Z? Z* y. y- y' y( y) y y? y* "++
|
" j. j- j' j( j) j j? j* g. g- g' g( g) g g? - "++
|
||||||
" d. d- d' d( d) d d? d* - - - - - - - - "++
|
" - - - g* - - - - - - - - - - - - "++
|
||||||
" j. j- j' j( j) j j? j* g. g- g' g( g) g g? - "++
|
" T. T- T' T( T) T T? T* C. C- C' C( C) C C? C* "++
|
||||||
" - - - g* - - - - - - - - - - - - "++
|
" P. P- P' P( P) P P? P* S. S- S' S( S) S S? S* "++
|
||||||
" T. T- T' T( T) T T? T* C. C- C' C( C) C C? C* "++
|
" - - - - - - - - f. f- f' f( f) f f? f*"++
|
||||||
" P. P- P' P( P) P P? P* S. S- S' S( S) S S? S* "++
|
" p. p- p' p( p) p p? p*"
|
||||||
" - - - - - - - - f. f- f' f( f) f f? f*"++
|
allCodes = [0x1200..0x1357]
|
||||||
" p. p- p' p( p) p p? p*"
|
|
||||||
allCodes = [0x1200..0x1357]
|
|
||||||
|
|
||||||
-- by Prasad 31/5/2013
|
-- by Prasad 31/5/2013
|
||||||
transSanskrit :: Transliteration
|
transSanskrit :: Transliteration
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ library
|
|||||||
PGF2.Expr,
|
PGF2.Expr,
|
||||||
PGF2.Type
|
PGF2.Type
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.9.1 && <4.15,
|
base >= 4.9.1 && < 4.15,
|
||||||
containers >= 0.5.7 && < 0.7,
|
containers >= 0.5.7 && < 0.7,
|
||||||
pretty >= 1.1.3 && < 1.2
|
pretty >= 1.1.3 && < 1.2
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.10.4
|
|||||||
library
|
library
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4.9.1 && <4.15,
|
base >= 4.9.1 && < 4.15,
|
||||||
array >= 0.5.1 && < 0.6,
|
array >= 0.5.1 && < 0.6,
|
||||||
containers >= 0.5.7 && < 0.7,
|
containers >= 0.5.7 && < 0.7,
|
||||||
bytestring >= 0.10.8 && < 0.11,
|
bytestring >= 0.10.8 && < 0.11,
|
||||||
|
|||||||
Reference in New Issue
Block a user