summaryrefslogtreecommitdiff
path: root/src/GF/Parsing
diff options
context:
space:
mode:
Diffstat (limited to 'src/GF/Parsing')
-rw-r--r--src/GF/Parsing/FCFG.hs4
-rw-r--r--src/GF/Parsing/FCFG/Active.hs16
-rw-r--r--src/GF/Parsing/FCFG/PInfo.hs30
-rw-r--r--src/GF/Parsing/GFC.hs5
4 files changed, 27 insertions, 28 deletions
diff --git a/src/GF/Parsing/FCFG.hs b/src/GF/Parsing/FCFG.hs
index dfe26d0b3..91b4201b7 100644
--- a/src/GF/Parsing/FCFG.hs
+++ b/src/GF/Parsing/FCFG.hs
@@ -21,12 +21,12 @@ import GF.Infra.PrintClass
----------------------------------------------------------------------
-- parsing
-parseFCF :: (Print c, Ord c, Ord n, Print t, Ord t) => String -> Err (FCFParser c n t)
+parseFCF :: String -> Err (FCFParser)
parseFCF prs | prs `elem` strategies = Ok $ parseFCF' prs
| otherwise = Bad $ "FCFG parsing strategy not defined: " ++ prs
strategies = words "bottomup topdown"
-parseFCF' :: (Print c, Ord c, Ord n, Print t, Ord t) => String -> FCFParser c n t
+parseFCF' :: String -> FCFParser
parseFCF' "bottomup" pinfo starts toks = Active.parse "b" pinfo starts toks
parseFCF' "topdown" pinfo starts toks = Active.parse "t" pinfo starts toks
diff --git a/src/GF/Parsing/FCFG/Active.hs b/src/GF/Parsing/FCFG/Active.hs
index d315ca1cc..fbbf3736d 100644
--- a/src/GF/Parsing/FCFG/Active.hs
+++ b/src/GF/Parsing/FCFG/Active.hs
@@ -32,7 +32,7 @@ import Data.Array
----------------------------------------------------------------------
-- * parsing
-parse :: (Print c, Ord c, Ord n, Print t, Ord t) => String -> FCFParser c n t
+parse :: String -> FCFParser
parse strategy pinfo starts toks = xchart2syntaxchart chart pinfo
where chart = process strategy pinfo toks axioms emptyXChart
axioms | isBU strategy = literals pinfo toks ++ initialBU pinfo toks
@@ -42,7 +42,7 @@ isBU s = s=="b"
isTD s = s=="t"
-- used in prediction
-emptyChildren :: RuleId -> FCFPInfo c n t -> SyntaxNode RuleId RangeRec
+emptyChildren :: RuleId -> FCFPInfo -> SyntaxNode RuleId RangeRec
emptyChildren ruleid pinfo = SNode ruleid (replicate (length rhs) [])
where
FRule _ rhs _ _ = allRules pinfo ! ruleid
@@ -57,7 +57,7 @@ updateChildren (SNode ruleid recs) i rec = do
makeMaxRange (Range _ j) = Range j j
makeMaxRange EmptyRange = EmptyRange
-process :: (Print c, Ord c, Ord n, Print t, Ord t) => String -> FCFPInfo c n t -> Input t -> [(c,Item)] -> XChart c -> XChart c
+process :: String -> FCFPInfo -> Input FToken -> [(FCat,Item)] -> XChart FCat -> XChart FCat
process strategy pinfo toks [] chart = chart
process strategy pinfo toks ((c,item):items) chart = process strategy pinfo toks items $! univRule c item chart
where
@@ -110,7 +110,7 @@ process strategy pinfo toks ((c,item):items) chart = process strategy pinfo toks
data Item
= Active RangeRec
Range
- {-# UNPACK #-} !FLabel
+ {-# UNPACK #-} !FIndex
{-# UNPACK #-} !FPointPos
(SyntaxNode RuleId RangeRec)
| Final RangeRec (SyntaxNode RuleId RangeRec)
@@ -134,7 +134,7 @@ insertXChart (XChart actives finals) item@(Final _ _) c =
lookupXChartAct (XChart actives finals) c = chartLookup actives c
lookupXChartFinal (XChart actives finals) c = chartLookup finals c
-xchart2syntaxchart :: (Ord c, Ord n, Ord t) => XChart c -> FCFPInfo c n t -> SyntaxChart n (c,RangeRec)
+xchart2syntaxchart :: XChart FCat -> FCFPInfo -> SyntaxChart FName (FCat,RangeRec)
xchart2syntaxchart (XChart actives finals) pinfo =
accumAssoc groupSyntaxNodes $
[ case node of
@@ -146,7 +146,7 @@ xchart2syntaxchart (XChart actives finals) pinfo =
| (cat, Final found node) <- chartAssocs finals
]
-literals :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> Input t -> [(c,Item)]
+literals :: FCFPInfo -> Input FToken -> [(FCat,Item)]
literals pinfo toks =
[let (c,node) = grammarLexer pinfo t in (c,Final [makeRange i j] node) | Edge i j t <- inputEdges toks, not (t `elem` grammarToks pinfo)]
@@ -154,7 +154,7 @@ literals pinfo toks =
-- Earley --
-- called with all starting categories
-initialTD :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> [c] -> Input t -> [(c,Item)]
+initialTD :: FCFPInfo -> [FCat] -> Input FToken -> [(FCat,Item)]
initialTD pinfo starts toks =
do cat <- starts
ruleid <- topdownRules pinfo ? cat
@@ -164,7 +164,7 @@ initialTD pinfo starts toks =
----------------------------------------------------------------------
-- Kilbury --
-initialBU :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> Input t -> [(c,Item)]
+initialBU :: FCFPInfo -> Input FToken -> [(FCat,Item)]
initialBU pinfo toks =
do tok <- aElems (inputToken toks)
ruleid <- leftcornerTokens pinfo ? tok ++
diff --git a/src/GF/Parsing/FCFG/PInfo.hs b/src/GF/Parsing/FCFG/PInfo.hs
index e463cf65a..8a45b651a 100644
--- a/src/GF/Parsing/FCFG/PInfo.hs
+++ b/src/GF/Parsing/FCFG/PInfo.hs
@@ -23,10 +23,10 @@ import Data.Maybe
-- type declarations
-- | the list of categories = possible starting categories
-type FCFParser c n t = FCFPInfo c n t
- -> [c]
- -> Input t
- -> SyntaxChart n (c,RangeRec)
+type FCFParser = FCFPInfo
+ -> [FCat]
+ -> Input FToken
+ -> SyntaxChart FName (FCat,RangeRec)
makeFinalEdge cat 0 0 = (cat, [EmptyRange])
makeFinalEdge cat i j = (cat, [makeRange i j])
@@ -36,19 +36,19 @@ makeFinalEdge cat i j = (cat, [makeRange i j])
type RuleId = Int
-data FCFPInfo c n t
- = FCFPInfo { allRules :: Array RuleId (FCFRule c n t)
- , topdownRules :: Assoc c (SList RuleId)
+data FCFPInfo
+ = FCFPInfo { allRules :: Array RuleId FRule
+ , topdownRules :: Assoc FCat (SList RuleId)
-- ^ used in 'GF.Parsing.MCFG.Active' (Earley):
- -- , emptyRules :: [RuleId]
+ -- , emptyRules :: [RuleId]
, epsilonRules :: [RuleId]
-- ^ used in 'GF.Parsing.MCFG.Active' (Kilbury):
- , leftcornerCats :: Assoc c (SList RuleId)
- , leftcornerTokens :: Assoc t (SList RuleId)
+ , leftcornerCats :: Assoc FCat (SList RuleId)
+ , leftcornerTokens :: Assoc FToken (SList RuleId)
-- ^ used in 'GF.Parsing.MCFG.Active' (Kilbury):
- , grammarCats :: SList c
- , grammarToks :: SList t
- , grammarLexer :: t -> (c,SyntaxNode RuleId RangeRec)
+ , grammarCats :: SList FCat
+ , grammarToks :: SList FToken
+ , grammarLexer :: FToken -> (FCat,SyntaxNode RuleId RangeRec)
}
@@ -68,7 +68,7 @@ getLeftCornerCat lins
where
syms = lins ! 0
-buildFCFPInfo :: (Ord c, Ord n, Ord t) => (t -> (c,SyntaxNode RuleId RangeRec)) -> FCFGrammar c n t -> FCFPInfo c n t
+buildFCFPInfo :: (FToken -> (FCat,SyntaxNode RuleId RangeRec)) -> FGrammar -> FCFPInfo
buildFCFPInfo lexer grammar =
FCFPInfo { allRules = allrules
, topdownRules = topdownrules
@@ -98,7 +98,7 @@ buildFCFPInfo lexer grammar =
----------------------------------------------------------------------
-- pretty-printing of statistics
-instance (Ord c, Ord n, Ord t) => Print (FCFPInfo c n t) where
+instance Print FCFPInfo where
prt pI = "[ allRules=" ++ sl (elems . allRules) ++
"; tdRules=" ++ sla topdownRules ++
-- "; emptyRules=" ++ sl emptyRules ++
diff --git a/src/GF/Parsing/GFC.hs b/src/GF/Parsing/GFC.hs
index 6d6c662c0..90ba718c7 100644
--- a/src/GF/Parsing/GFC.hs
+++ b/src/GF/Parsing/GFC.hs
@@ -32,11 +32,11 @@ import GF.Data.SortedList
import GF.Data.Assoc
import GF.Formalism.Utilities
import GF.Conversion.Types
-import GF.Conversion.FTypes
import qualified GF.Formalism.GCFG as G
import qualified GF.Formalism.SimpleGFC as S
import qualified GF.Formalism.MCFG as M
+import GF.Formalism.FCFG
import qualified GF.Formalism.CFG as C
import qualified GF.Parsing.MCFG as PM
import qualified GF.Parsing.FCFG as PF
@@ -46,12 +46,11 @@ import qualified GF.Parsing.CFG as PC
-- parsing information
data PInfo = PInfo { mcfPInfo :: MCFPInfo
- , fcfPInfo :: FCFPInfo
+ , fcfPInfo :: PF.FCFPInfo
, cfPInfo :: CFPInfo
}
type MCFPInfo = PM.MCFPInfo MCat Name MLabel Token
-type FCFPInfo = PF.FCFPInfo FCat FName Token
type CFPInfo = PC.CFPInfo CCat Name Token
buildPInfo :: MGrammar -> FGrammar -> CGrammar -> PInfo