mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
Sync FCFG with the latest repo version
This commit is contained in:
@@ -37,9 +37,8 @@ import Data.Array
|
|||||||
parse :: (Ord c, Ord n, Ord t) => String -> FCFParser c n t
|
parse :: (Ord c, Ord n, Ord t) => String -> FCFParser c n t
|
||||||
parse strategy pinfo starts toks = xchart2syntaxchart chart pinfo
|
parse strategy pinfo starts toks = xchart2syntaxchart chart pinfo
|
||||||
where chart = process strategy pinfo toks axioms emptyXChart
|
where chart = process strategy pinfo toks axioms emptyXChart
|
||||||
|
axioms | isBU strategy = literals pinfo toks ++ initialBU pinfo toks
|
||||||
axioms | isBU strategy = terminal pinfo toks ++ initialScan pinfo toks
|
| isTD strategy = literals pinfo toks ++ initialTD pinfo starts toks
|
||||||
| isTD strategy = initial pinfo starts toks
|
|
||||||
|
|
||||||
isBU s = s=="b"
|
isBU s = s=="b"
|
||||||
isTD s = s=="t"
|
isTD s = s=="t"
|
||||||
@@ -149,13 +148,16 @@ xchart2syntaxchart (XChart actives finals) pinfo =
|
|||||||
| (cat, Final found node) <- chartAssocs finals
|
| (cat, Final found node) <- chartAssocs finals
|
||||||
]
|
]
|
||||||
|
|
||||||
|
literals :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> Input t -> [(c,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)]
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
-- Earley --
|
-- Earley --
|
||||||
|
|
||||||
-- anropas med alla startkategorier
|
-- called with all starting categories
|
||||||
initial :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> [c] -> Input t -> [Item]
|
initialTD :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> [c] -> Input t -> [(c,Item)]
|
||||||
initial pinfo starts toks =
|
initialTD pinfo starts toks =
|
||||||
tracePrt "MCFG.Active (Earley) - initial rules" (prt . length) $
|
|
||||||
do cat <- starts
|
do cat <- starts
|
||||||
ruleid <- topdownRules pinfo ? cat
|
ruleid <- topdownRules pinfo ? cat
|
||||||
return (cat,Active [] (Range 0 0) 0 0 (emptyChildren ruleid pinfo))
|
return (cat,Active [] (Range 0 0) 0 0 (emptyChildren ruleid pinfo))
|
||||||
@@ -164,24 +166,10 @@ initial pinfo starts toks =
|
|||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
-- Kilbury --
|
-- Kilbury --
|
||||||
|
|
||||||
terminal :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> Input t -> [Item]
|
initialBU :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> Input t -> [(c,Item)]
|
||||||
terminal pinfo toks =
|
initialBU pinfo toks =
|
||||||
tracePrt "MCFG.Active (Kilbury) - initial terminal rules" (prt . length) $
|
|
||||||
do ruleid <- emptyRules pinfo
|
|
||||||
let FRule abs lins = allRules pinfo ! ruleid
|
|
||||||
rrec <- mapM (rangeRestSyms toks EmptyRange . elems) (elems lins)
|
|
||||||
return $ Final ruleid rrec []
|
|
||||||
where
|
|
||||||
rangeRestSyms toks rng [] = return rng
|
|
||||||
rangeRestSyms toks rng (FSymTok tok:syms) = do (i,j) <- inputToken toks ? tok
|
|
||||||
rng' <- concatRange rng (makeRange i j)
|
|
||||||
rangeRestSyms toks rng' syms
|
|
||||||
|
|
||||||
initialScan :: (Ord c, Ord n, Ord t) => FCFPInfo c n t -> Input t -> [Item]
|
|
||||||
initialScan pinfo toks =
|
|
||||||
tracePrt "MCFG.Active (Kilbury) - initial scanned rules" (prt . length) $
|
|
||||||
do tok <- aElems (inputToken toks)
|
do tok <- aElems (inputToken toks)
|
||||||
ruleid <- leftcornerTokens pinfo ? tok ++
|
ruleid <- leftcornerTokens pinfo ? tok ++
|
||||||
epsilonRules pinfo
|
epsilonRules pinfo
|
||||||
let FRule abs lins = allRules pinfo ! ruleid
|
let FRule (Abs cat _ _) _ = allRules pinfo ! ruleid
|
||||||
return $ Active ruleid [] EmptyRange 0 0 (emptyChildren abs)
|
return (cat,Active [] EmptyRange 0 0 (emptyChildren ruleid pinfo))
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ import Data.Array
|
|||||||
|
|
||||||
-- parse :: (Ord c, Ord n, Ord l, Ord t) => String -> MCFParser c n l t
|
-- parse :: (Ord c, Ord n, Ord l, Ord t) => String -> MCFParser c n l t
|
||||||
parse strategy pinfo starts =
|
parse strategy pinfo starts =
|
||||||
[ Abs (cat, found) (zip rhs rrecs) fun |
|
accumAssoc groupSyntaxNodes $
|
||||||
Final (Abs cat rhs fun) found rrecs <- listXChartFinal chart ]
|
[ ((cat, found), SNode fun (zip rhs rrecs)) |
|
||||||
|
Final (Abs cat rhs fun) found rrecs <- listXChartFinal chart ]
|
||||||
where chart = process strategy pinfo axioms emptyXChart
|
where chart = process strategy pinfo axioms emptyXChart
|
||||||
|
|
||||||
-- axioms | isBU strategy = terminal pinfo toks ++ initialScan pinfo toks
|
-- axioms | isBU strategy = terminal pinfo toks ++ initialScan pinfo toks
|
||||||
|
|||||||
Reference in New Issue
Block a user