mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 09:32:53 -06:00
Merge branch 'master' of https://github.com/GrammaticalFramework/GF
This commit is contained in:
@@ -98,14 +98,13 @@ execute command args =
|
|||||||
showArg arg = if ' ' `elem` arg then "'" ++ arg ++ "'" else arg
|
showArg arg = if ' ' `elem` arg then "'" ++ arg ++ "'" else arg
|
||||||
|
|
||||||
-- | This function is used to enable parallel compilation of the RGL and
|
-- | This function is used to enable parallel compilation of the RGL and
|
||||||
-- example grammars, but it is commented out by default
|
-- example grammars
|
||||||
-- to avoid casing problems for developers using Cabal<1.20
|
|
||||||
numJobs flags =
|
numJobs flags =
|
||||||
if null n
|
if null n
|
||||||
then ["-j","+RTS","-A20M","-N","-RTS"]
|
then ["-j","+RTS","-A20M","-N","-RTS"]
|
||||||
else ["-j="++n,"+RTS","-A20M","-N"++n,"-RTS"]
|
else ["-j="++n,"+RTS","-A20M","-N"++n,"-RTS"]
|
||||||
where
|
where
|
||||||
-- buildNumJobs is only available in Cabal>=1.20
|
-- buildNumJobs is only available in Cabal>=1.20
|
||||||
n = {-case buildNumJobs flags of
|
n = case buildNumJobs flags of
|
||||||
Flag mn | mn/=Just 1-> maybe "" show mn
|
Flag mn | mn/=Just 1-> maybe "" show mn
|
||||||
_ ->-} ""
|
_ -> ""
|
||||||
|
|||||||
8
gf.cabal
8
gf.cabal
@@ -1,7 +1,7 @@
|
|||||||
name: gf
|
name: gf
|
||||||
version: 3.9
|
version: 3.9-git
|
||||||
|
|
||||||
cabal-version: >= 1.10
|
cabal-version: >= 1.20
|
||||||
build-type: Custom
|
build-type: Custom
|
||||||
license: OtherLicense
|
license: OtherLicense
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
@@ -57,6 +57,7 @@ flag interrupt
|
|||||||
flag server
|
flag server
|
||||||
Description: Include --server mode
|
Description: Include --server mode
|
||||||
Default: True
|
Default: True
|
||||||
|
|
||||||
flag network-uri
|
flag network-uri
|
||||||
description: Get Network.URI from the network-uri package
|
description: Get Network.URI from the network-uri package
|
||||||
default: True
|
default: True
|
||||||
@@ -68,6 +69,7 @@ flag network-uri
|
|||||||
flag custom-binary
|
flag custom-binary
|
||||||
Description: Use a customised version of the binary package
|
Description: Use a customised version of the binary package
|
||||||
Default: True
|
Default: True
|
||||||
|
Manual: True
|
||||||
|
|
||||||
flag c-runtime
|
flag c-runtime
|
||||||
Description: Include functionality from the C run-time library (which must be installed already)
|
Description: Include functionality from the C run-time library (which must be installed already)
|
||||||
@@ -75,7 +77,7 @@ flag c-runtime
|
|||||||
|
|
||||||
Library
|
Library
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
build-depends: base >= 4.5 && <5,
|
build-depends: base >= 4.6 && <5,
|
||||||
array,
|
array,
|
||||||
containers,
|
containers,
|
||||||
bytestring,
|
bytestring,
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ function sitesearch() {
|
|||||||
</ul>
|
</ul>
|
||||||
<h4>Develop Applications</h4>
|
<h4>Develop Applications</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="http://hackage.haskell.org/package/gf-3.7.1/docs/PGF.html">PGF library API (Haskell)</a>
|
<li><a href="http://hackage.haskell.org/package/gf-3.9/docs/PGF.html">PGF library API (Haskell)</a>
|
||||||
<li><a href="doc/python-api.html">PGF library API (Python)</a>
|
<li><a href="doc/python-api.html">PGF library API (Python)</a>
|
||||||
<li><a href="doc/java-api/index.html">PGF library API (Java)</a>
|
<li><a href="doc/java-api/index.html">PGF library API (Java)</a>
|
||||||
<li><a href="doc/dotNet-api/index.html">PGF library API (.NET)</a>
|
<li><a href="doc/dotNet-api/index.html">PGF library API (.NET)</a>
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
-- | Isolate backwards incompatible library changes to 'catch' and 'try'
|
-- | Backwards compatible 'catch' and 'try'
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
module GF.System.Catch where
|
module GF.System.Catch where
|
||||||
import qualified System.IO.Error as S
|
import qualified System.IO.Error as S
|
||||||
|
|
||||||
-- ** Backwards compatible try and catch
|
-- ** Backwards compatible try and catch
|
||||||
#if MIN_VERSION_base(4,4,0)
|
|
||||||
catch = S.catchIOError
|
catch = S.catchIOError
|
||||||
try = S.tryIOError
|
try = S.tryIOError
|
||||||
#else
|
|
||||||
catch = S.catch
|
|
||||||
try = S.try
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{-# LANGUAGE CPP,ForeignFunctionInterface #-}
|
{-# LANGUAGE ForeignFunctionInterface #-}
|
||||||
-- | A variant of 'Control.Concurrent.setNumCapabilities' that automatically
|
-- | A variant of 'Control.Concurrent.setNumCapabilities' that automatically
|
||||||
-- detects the number of processors in the system, and is available
|
-- detects the number of processors in the system.
|
||||||
-- even when compiling with GHC<7.6.
|
|
||||||
module GF.System.Concurrency(
|
module GF.System.Concurrency(
|
||||||
-- * Controlling parallelism
|
-- * Controlling parallelism
|
||||||
setNumCapabilities,getNumberOfProcessors) where
|
setNumCapabilities,getNumberOfProcessors) where
|
||||||
@@ -16,13 +15,8 @@ import Foreign.C.Types(CInt(..))
|
|||||||
-- hasn't already been set with @+RTS -N/n/ -RTS@.
|
-- hasn't already been set with @+RTS -N/n/ -RTS@.
|
||||||
setNumCapabilities opt_n =
|
setNumCapabilities opt_n =
|
||||||
do n <- maybe getNumberOfProcessors return opt_n
|
do n <- maybe getNumberOfProcessors return opt_n
|
||||||
#if MIN_VERSION_base(4,6,0)
|
|
||||||
C.setNumCapabilities n
|
C.setNumCapabilities n
|
||||||
return True
|
return True
|
||||||
#else
|
|
||||||
n_now <- C.getNumCapabilities
|
|
||||||
return (n==n_now)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Returns the number of processors in the system.
|
-- | Returns the number of processors in the system.
|
||||||
getNumberOfProcessors = fmap fromEnum c_getNumberOfProcessors
|
getNumberOfProcessors = fmap fromEnum c_getNumberOfProcessors
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
AC_INIT(Portable Grammar Format library, 0.1.pre,
|
AC_INIT(Portable Grammar Format library, 0.1-pre,
|
||||||
https://code.google.com/p/grammatical-framework/,
|
http://www.grammaticalframework.org/,
|
||||||
libpgf)
|
libpgf)
|
||||||
AC_PREREQ(2.58)
|
AC_PREREQ(2.58)
|
||||||
|
|
||||||
|
|||||||
@@ -124,11 +124,12 @@ readLanguage = readCId
|
|||||||
showLanguage :: Language -> String
|
showLanguage :: Language -> String
|
||||||
showLanguage = showCId
|
showLanguage = showCId
|
||||||
|
|
||||||
fidString, fidInt, fidFloat, fidVar :: FId
|
fidString, fidInt, fidFloat, fidVar, fidStart :: FId
|
||||||
fidString = (-1)
|
fidString = (-1)
|
||||||
fidInt = (-2)
|
fidInt = (-2)
|
||||||
fidFloat = (-3)
|
fidFloat = (-3)
|
||||||
fidVar = (-4)
|
fidVar = (-4)
|
||||||
|
fidStart = (-5)
|
||||||
|
|
||||||
isPredefFId :: FId -> Bool
|
isPredefFId :: FId -> Bool
|
||||||
isPredefFId = (`elem` [fidString, fidInt, fidFloat, fidVar])
|
isPredefFId = (`elem` [fidString, fidInt, fidFloat, fidVar])
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE CPP, BangPatterns #-}
|
{-# LANGUAGE BangPatterns #-}
|
||||||
module PGF.Optimize
|
module PGF.Optimize
|
||||||
( optimizePGF
|
( optimizePGF
|
||||||
, updateProductionIndices
|
, updateProductionIndices
|
||||||
@@ -11,11 +11,7 @@ import PGF.Macros
|
|||||||
import Data.List (mapAccumL)
|
import Data.List (mapAccumL)
|
||||||
import Data.Array.IArray
|
import Data.Array.IArray
|
||||||
import Data.Array.MArray
|
import Data.Array.MArray
|
||||||
#if MIN_VERSION_base(4,6,0)
|
|
||||||
import Data.Array.Unsafe as U(unsafeFreeze)
|
import Data.Array.Unsafe as U(unsafeFreeze)
|
||||||
#else
|
|
||||||
import Data.Array.ST as U(unsafeFreeze)
|
|
||||||
#endif
|
|
||||||
import Data.Array.ST
|
import Data.Array.ST
|
||||||
import Data.Array.Unboxed
|
import Data.Array.Unboxed
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
|||||||
@@ -77,34 +77,27 @@ parseWithRecovery pgf lang typ open_typs dp toks = accept (initState pgf lang ty
|
|||||||
Just ps -> accept ps ts
|
Just ps -> accept ps ts
|
||||||
Nothing -> skip ps_map ts
|
Nothing -> skip ps_map ts
|
||||||
|
|
||||||
|
|
||||||
-- | Creates an initial parsing state for a given language and
|
-- | Creates an initial parsing state for a given language and
|
||||||
-- startup category.
|
-- startup category.
|
||||||
initState :: PGF -> Language -> Type -> ParseState
|
initState :: PGF -> Language -> Type -> ParseState
|
||||||
initState pgf lang (DTyp _ start _) =
|
initState pgf lang (DTyp _ start _) =
|
||||||
let (acc,items) = case Map.lookup start (cnccats cnc) of
|
let items = case Map.lookup start (cnccats cnc) of
|
||||||
Just (CncCat s e labels) ->
|
Just (CncCat s e labels) ->
|
||||||
let keys = do fid <- range (s,e)
|
do fid <- range (s,e)
|
||||||
lbl <- indices labels
|
funid <- fromMaybe [] (IntMap.lookup fid (linrefs cnc))
|
||||||
return (AK fid lbl)
|
let lbl = 0
|
||||||
in foldl' (\(acc,items) key -> predict flit ftok cnc
|
CncFun _ lins = unsafeAt (cncfuns cnc) funid
|
||||||
(pproductions cnc)
|
return (Active 0 0 funid (unsafeAt lins lbl) [PArg [] fid] (AK fidStart lbl))
|
||||||
key key 0
|
Nothing -> []
|
||||||
acc items)
|
|
||||||
(Map.empty,[])
|
|
||||||
keys
|
|
||||||
Nothing -> (Map.empty,[])
|
|
||||||
in PState abs
|
in PState abs
|
||||||
cnc
|
cnc
|
||||||
(Chart emptyAC [] emptyPC (pproductions cnc) (totalCats cnc) 0)
|
(Chart emptyAC [] emptyPC (pproductions cnc) (totalCats cnc) 0)
|
||||||
(TrieMap.compose (Just (Set.fromList items)) acc)
|
(TrieMap.compose (Just (Set.fromList items)) Map.empty)
|
||||||
where
|
where
|
||||||
abs = abstract pgf
|
abs = abstract pgf
|
||||||
cnc = lookConcrComplete pgf lang
|
cnc = lookConcrComplete pgf lang
|
||||||
|
|
||||||
flit _ = Nothing
|
|
||||||
|
|
||||||
ftok = Map.unionWith (TrieMap.unionWith Set.union)
|
|
||||||
|
|
||||||
|
|
||||||
-- | This function constructs the simplest possible parser input.
|
-- | This function constructs the simplest possible parser input.
|
||||||
-- It checks the tokens for exact matching and recognizes only @String@, @Int@ and @Float@ literals.
|
-- It checks the tokens for exact matching and recognizes only @String@, @Int@ and @Float@ literals.
|
||||||
@@ -218,7 +211,7 @@ recoveryStates open_types (EState abs cnc chart) =
|
|||||||
-- limited by the category specified, which is usually
|
-- limited by the category specified, which is usually
|
||||||
-- the same as the startup category.
|
-- the same as the startup category.
|
||||||
getParseOutput :: ParseState -> Type -> Maybe Int -> (ParseOutput,BracketedString)
|
getParseOutput :: ParseState -> Type -> Maybe Int -> (ParseOutput,BracketedString)
|
||||||
getParseOutput (PState abs cnc chart cnt) ty@(DTyp _ start _) dp =
|
getParseOutput (PState abs cnc chart cnt) ty dp =
|
||||||
let froots | null roots = getPartialSeq (sequences cnc) (reverse (active chart1 : actives chart1)) seq
|
let froots | null roots = getPartialSeq (sequences cnc) (reverse (active chart1 : actives chart1)) seq
|
||||||
| otherwise = [([SymCat 0 lbl],[PArg [] fid]) | AK fid lbl <- roots]
|
| otherwise = [([SymCat 0 lbl],[PArg [] fid]) | AK fid lbl <- roots]
|
||||||
|
|
||||||
@@ -253,12 +246,11 @@ getParseOutput (PState abs cnc chart cnt) ty@(DTyp _ start _) dp =
|
|||||||
sym -> []
|
sym -> []
|
||||||
in init ++ tail
|
in init ++ tail
|
||||||
|
|
||||||
roots = case Map.lookup start (cnccats cnc) of
|
roots = do let lbl = 0
|
||||||
Just (CncCat s e lbls) -> do cat <- range (s,e)
|
fid <- maybeToList (lookupPC (PK fidStart lbl 0) (passive chart1))
|
||||||
lbl <- indices lbls
|
PApply _ [PArg _ fid] <- maybe [] Set.toList (IntMap.lookup fid (forest chart1))
|
||||||
fid <- maybeToList (lookupPC (PK cat lbl 0) (passive chart1))
|
|
||||||
return (AK fid lbl)
|
return (AK fid lbl)
|
||||||
Nothing -> mzero
|
|
||||||
|
|
||||||
getPartialSeq seqs actives = expand Set.empty
|
getPartialSeq seqs actives = expand Set.empty
|
||||||
where
|
where
|
||||||
@@ -417,10 +409,6 @@ predict flit ftok cnc forest key0 key@(AK fid lbl) k acc items =
|
|||||||
foldProd (PApply funid args) (acc,items) = (acc,Active k 0 funid (rhs funid lbl) args key0 : items)
|
foldProd (PApply funid args) (acc,items) = (acc,Active k 0 funid (rhs funid lbl) args key0 : items)
|
||||||
foldProd (PConst _ const toks) (acc,items) = (acc,items)
|
foldProd (PConst _ const toks) (acc,items) = (acc,items)
|
||||||
|
|
||||||
rhs funid lbl = unsafeAt lins lbl
|
|
||||||
where
|
|
||||||
CncFun _ lins = unsafeAt (cncfuns cnc) funid
|
|
||||||
|
|
||||||
toItems key@(AK fid lbl) k funids =
|
toItems key@(AK fid lbl) k funids =
|
||||||
Set.fromList [Active k 1 funid (rhs funid lbl) [] key | funid <- IntSet.toList funids]
|
Set.fromList [Active k 1 funid (rhs funid lbl) [] key | funid <- IntSet.toList funids]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user