forked from GitHub/gf-core
store the total number of PMCFG categories in the PGF file
This commit is contained in:
@@ -330,6 +330,7 @@ getParserInfo (GrammarEnv last_id catSet seqSet funSet prodSet) =
|
|||||||
, sequences = mkArray seqSet
|
, sequences = mkArray seqSet
|
||||||
, productions = prodSet
|
, productions = prodSet
|
||||||
, startCats = Map.map getFCatList catSet
|
, startCats = Map.map getFCatList catSet
|
||||||
|
, totalCats = last_id+1
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
mkArray map = array (0,Map.size map-1) [(v,k) | (k,v) <- Map.toList map]
|
mkArray map = array (0,Map.size map-1) [(v,k) | (k,v) <- Map.toList map]
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ getParserInfo (GrammarEnv last_id catSet seqSet funSet crcSet prodSet) =
|
|||||||
, sequences = mkArray seqSet
|
, sequences = mkArray seqSet
|
||||||
, productions = IntMap.union prodSet coercions
|
, productions = IntMap.union prodSet coercions
|
||||||
, startCats = Map.map (\(start,end,_) -> range (start,end)) catSet
|
, startCats = Map.map (\(start,end,_) -> range (start,end)) catSet
|
||||||
|
, totalCats = last_id+1
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
mkArray map = array (0,Map.size map-1) [(v,k) | (k,v) <- Map.toList map]
|
mkArray map = array (0,Map.size map-1) [(v,k) | (k,v) <- Map.toList map]
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ data ParserInfo
|
|||||||
, sequences :: Array SeqId FSeq
|
, sequences :: Array SeqId FSeq
|
||||||
, productions :: IntMap.IntMap (Set.Set Production)
|
, productions :: IntMap.IntMap (Set.Set Production)
|
||||||
, startCats :: Map.Map CId [FCat]
|
, startCats :: Map.Map CId [FCat]
|
||||||
|
, totalCats :: {-# UNPACK #-} !FCat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,12 +35,8 @@ initState pinfo start =
|
|||||||
(lbl,seqid) <- assocs lins
|
(lbl,seqid) <- assocs lins
|
||||||
return (Active 0 0 funid seqid args (AK cat lbl))
|
return (Active 0 0 funid seqid args (AK cat lbl))
|
||||||
|
|
||||||
max_fid = maximum (0:[maximum (cat:args) | (cat, set) <- IntMap.toList (productions pinfo)
|
|
||||||
, p <- Set.toList set
|
|
||||||
, let args = case p of {FApply _ args -> args; FCoerce cat -> [cat]}])+1
|
|
||||||
|
|
||||||
in State pinfo
|
in State pinfo
|
||||||
(Chart emptyAC [] emptyPC (productions pinfo) max_fid 0)
|
(Chart emptyAC [] emptyPC (productions pinfo) (totalCats pinfo) 0)
|
||||||
(Set.fromList items)
|
(Set.fromList items)
|
||||||
|
|
||||||
-- | From the current state and the next token
|
-- | From the current state and the next token
|
||||||
|
|||||||
@@ -72,11 +72,12 @@ toConcr pgf rexp =
|
|||||||
add cnc (App "parser" ts) = cnc { parser = Just (toPInfo ts) }
|
add cnc (App "parser" ts) = cnc { parser = Just (toPInfo ts) }
|
||||||
|
|
||||||
toPInfo :: [RExp] -> ParserInfo
|
toPInfo :: [RExp] -> ParserInfo
|
||||||
toPInfo [App "functions" fs, App "sequences" ss, App "productions" ps,App "startcats" cs] =
|
toPInfo [App "functions" fs, App "sequences" ss, App "productions" ps,App "categories" (t:cs)] =
|
||||||
ParserInfo { functions = functions
|
ParserInfo { functions = functions
|
||||||
, sequences = seqs
|
, sequences = seqs
|
||||||
, productions = productions
|
, productions = productions
|
||||||
, startCats = cats
|
, startCats = cats
|
||||||
|
, totalCats = expToInt t
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
functions = mkArray (map toFFun fs)
|
functions = mkArray (map toFFun fs)
|
||||||
@@ -229,7 +230,7 @@ fromPInfo p = App "parser" [
|
|||||||
App "functions" [fromFFun fun | fun <- elems (functions p)],
|
App "functions" [fromFFun fun | fun <- elems (functions p)],
|
||||||
App "sequences" [fromFSeq seq | seq <- elems (sequences p)],
|
App "sequences" [fromFSeq seq | seq <- elems (sequences p)],
|
||||||
App "productions" [fromProductionSet xs | xs <- IntMap.toList (productions p)],
|
App "productions" [fromProductionSet xs | xs <- IntMap.toList (productions p)],
|
||||||
App "startcats" [App (prCId f) (map intToExp xs) | (f,xs) <- Map.toList (startCats p)]
|
App "categories" (intToExp (totalCats p) : [App (prCId f) (map intToExp xs) | (f,xs) <- Map.toList (startCats p)])
|
||||||
]
|
]
|
||||||
|
|
||||||
fromFFun :: FFun -> RExp
|
fromFFun :: FFun -> RExp
|
||||||
|
|||||||
Reference in New Issue
Block a user