mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-25 10:48:54 -06:00
rename isLiteralFCat -> isPredefFId, fcat(String|Int|Float) -> fid(String|Int|Float)
This commit is contained in:
@@ -450,9 +450,9 @@ emptyGrammarEnv gr (m,mo) =
|
|||||||
in GrammarEnv last_id (IntMap.singleton 0 catSet) Map.empty Map.empty Map.empty IntMap.empty
|
in GrammarEnv last_id (IntMap.singleton 0 catSet) Map.empty Map.empty Map.empty IntMap.empty
|
||||||
where
|
where
|
||||||
computeCatRange index cat ctype
|
computeCatRange index cat ctype
|
||||||
| cat == cString = (index,(fcatString,fcatString,PFCat 0 cat (CRec [(theLinLabel,Identity (CStr 0))])))
|
| cat == cString = (index,(fidString,fidString,PFCat 0 cat (CRec [(theLinLabel,Identity (CStr 0))])))
|
||||||
| cat == cInt = (index,(fcatInt, fcatInt, PFCat 0 cat (CRec [(theLinLabel,Identity (CStr 0))])))
|
| cat == cInt = (index,(fidInt, fidInt, PFCat 0 cat (CRec [(theLinLabel,Identity (CStr 0))])))
|
||||||
| cat == cFloat = (index,(fcatFloat, fcatFloat, PFCat 0 cat (CRec [(theLinLabel,Identity (CStr 0))])))
|
| cat == cFloat = (index,(fidFloat, fidFloat, PFCat 0 cat (CRec [(theLinLabel,Identity (CStr 0))])))
|
||||||
| otherwise = (index+size,(index,index+size-1,PFCat 0 cat schema))
|
| otherwise = (index+size,(index,index+size-1,PFCat 0 cat schema))
|
||||||
where
|
where
|
||||||
((_,size),schema) = compute (0,1) ctype
|
((_,size),schema) = compute (0,1) ctype
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pgfToCFG pgf lang = mkCFG (showCId (lookStartCat pgf)) extCats (startRules ++ co
|
|||||||
startRules :: [CFRule]
|
startRules :: [CFRule]
|
||||||
startRules = [CFRule (showCId c) [NonTerminal (fcatToCat fc r)] (CFRes 0)
|
startRules = [CFRule (showCId c) [NonTerminal (fcatToCat fc r)] (CFRes 0)
|
||||||
| (c,CncCat s e lbls) <- Map.toList (cnccats cnc),
|
| (c,CncCat s e lbls) <- Map.toList (cnccats cnc),
|
||||||
fc <- range (s,e), not (isLiteralFCat fc),
|
fc <- range (s,e), not (isPredefFId fc),
|
||||||
r <- [0..catLinArity fc-1]]
|
r <- [0..catLinArity fc-1]]
|
||||||
|
|
||||||
ruleToCFRule :: (FId,Production) -> [CFRule]
|
ruleToCFRule :: (FId,Production) -> [CFRule]
|
||||||
@@ -86,7 +86,7 @@ pgfToCFG pgf lang = mkCFG (showCId (lookStartCat pgf)) extCats (startRules ++ co
|
|||||||
mkRhs = concatMap symbolToCFSymbol . Array.elems
|
mkRhs = concatMap symbolToCFSymbol . Array.elems
|
||||||
|
|
||||||
containsLiterals :: Array DotPos Symbol -> Bool
|
containsLiterals :: Array DotPos Symbol -> Bool
|
||||||
containsLiterals row = any isLiteralFCat [args!!n | SymCat n _ <- Array.elems row] ||
|
containsLiterals row = any isPredefFId [args!!n | SymCat n _ <- Array.elems row] ||
|
||||||
not (null [n | SymLit n _ <- Array.elems row]) -- only this is needed for PMCFG.
|
not (null [n | SymLit n _ <- Array.elems row]) -- only this is needed for PMCFG.
|
||||||
-- The first line is for backward compat.
|
-- The first line is for backward compat.
|
||||||
|
|
||||||
|
|||||||
@@ -103,11 +103,11 @@ readLanguage = readCId
|
|||||||
showLanguage :: Language -> String
|
showLanguage :: Language -> String
|
||||||
showLanguage = showCId
|
showLanguage = showCId
|
||||||
|
|
||||||
fcatString, fcatInt, fcatFloat, fcatVar :: Int
|
fidString, fidInt, fidFloat, fidVar :: FId
|
||||||
fcatString = (-1)
|
fidString = (-1)
|
||||||
fcatInt = (-2)
|
fidInt = (-2)
|
||||||
fcatFloat = (-3)
|
fidFloat = (-3)
|
||||||
fcatVar = (-4)
|
fidVar = (-4)
|
||||||
|
|
||||||
isLiteralFCat :: FId -> Bool
|
isPredefFId :: FId -> Bool
|
||||||
isLiteralFCat = (`elem` [fcatString, fcatInt, fcatFloat, fcatVar])
|
isPredefFId = (`elem` [fidString, fidInt, fidFloat, fidVar])
|
||||||
|
|||||||
@@ -173,8 +173,8 @@ filterProductions prods0 prods
|
|||||||
where
|
where
|
||||||
set1 = Set.filter (filterRule prods0) set
|
set1 = Set.filter (filterRule prods0) set
|
||||||
|
|
||||||
filterRule prods0 (PApply funid args) = all (\fcat -> isLiteralFCat fcat || IntMap.member fcat prods0) args
|
filterRule prods0 (PApply funid args) = all (\fid -> isPredefFId fid || IntMap.member fid prods0) args
|
||||||
filterRule prods0 (PCoerce fcat) = isLiteralFCat fcat || IntMap.member fcat prods0
|
filterRule prods0 (PCoerce fid) = isPredefFId fid || IntMap.member fid prods0
|
||||||
filterRule prods0 _ = True
|
filterRule prods0 _ = True
|
||||||
|
|
||||||
updateConcrete abs cnc =
|
updateConcrete abs cnc =
|
||||||
@@ -191,8 +191,8 @@ updateConcrete abs cnc =
|
|||||||
then Nothing
|
then Nothing
|
||||||
else Just prods'
|
else Just prods'
|
||||||
|
|
||||||
is_ho_prod (PApply _ [fid]) | fid == fcatVar = True
|
is_ho_prod (PApply _ [fid]) | fid == fidVar = True
|
||||||
is_ho_prod _ = False
|
is_ho_prod _ = False
|
||||||
|
|
||||||
ho_fids :: IntSet.IntSet
|
ho_fids :: IntSet.IntSet
|
||||||
ho_fids = IntSet.fromList [fid | cat <- ho_cats
|
ho_fids = IntSet.fromList [fid | cat <- ho_cats
|
||||||
|
|||||||
@@ -138,10 +138,10 @@ feedLiteral (PState pgf cnc chart items) (ELit lit) =
|
|||||||
|
|
||||||
magic lit fid =
|
magic lit fid =
|
||||||
case lit of
|
case lit of
|
||||||
LStr s | fid == fcatString -> Just (cidString, ELit lit, words s)
|
LStr s | fid == fidString -> Just (cidString, ELit lit, words s)
|
||||||
LInt n | fid == fcatInt -> Just (cidInt, ELit lit, [show n])
|
LInt n | fid == fidInt -> Just (cidInt, ELit lit, [show n])
|
||||||
LFlt d | fid == fcatFloat -> Just (cidFloat, ELit lit, [show d])
|
LFlt d | fid == fidFloat -> Just (cidFloat, ELit lit, [show d])
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
-- | If the next token is not known but only its prefix (possible empty prefix)
|
-- | If the next token is not known but only its prefix (possible empty prefix)
|
||||||
-- then the 'getCompletions' function can be used to calculate the possible
|
-- then the 'getCompletions' function can be used to calculate the possible
|
||||||
@@ -344,14 +344,14 @@ process mbt fn !seqs !funs (item@(Active j ppos funid seqid args key0):items) ac
|
|||||||
updateAt :: Int -> a -> [a] -> [a]
|
updateAt :: Int -> a -> [a] -> [a]
|
||||||
updateAt nr x xs = [if i == nr then x else y | (i,y) <- zip [0..] xs]
|
updateAt nr x xs = [if i == nr then x else y | (i,y) <- zip [0..] xs]
|
||||||
|
|
||||||
litCatMatch (Just t) fcat
|
litCatMatch (Just t) fid
|
||||||
| fcat == fcatString = Just (cidString,ELit (LStr t),[t])
|
| fid == fidString = Just (cidString,ELit (LStr t),[t])
|
||||||
| fcat == fcatInt = case reads t of {[(n,"")] -> Just (cidInt,ELit (LInt n),[t]);
|
| fid == fidInt = case reads t of {[(n,"")] -> Just (cidInt,ELit (LInt n),[t]);
|
||||||
_ -> Nothing }
|
_ -> Nothing }
|
||||||
| fcat == fcatFloat = case reads t of {[(d,"")] -> Just (cidFloat,ELit (LFlt d),[t]);
|
| fid == fidFloat = case reads t of {[(d,"")] -> Just (cidFloat,ELit (LFlt d),[t]);
|
||||||
_ -> Nothing }
|
_ -> Nothing }
|
||||||
| fcat == fcatVar = Just (cidVar,EFun (mkCId t),[t])
|
| fid == fidVar = Just (cidVar,EFun (mkCId t),[t])
|
||||||
litCatMatch _ _ = Nothing
|
litCatMatch _ _ = Nothing
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ ppCnc name cnc =
|
|||||||
nest 2 (vcat (map ppPrintName (Map.toList (printnames cnc))))) $$
|
nest 2 (vcat (map ppPrintName (Map.toList (printnames cnc))))) $$
|
||||||
char '}'
|
char '}'
|
||||||
|
|
||||||
ppProduction (fcat,PApply funid args) =
|
ppProduction (fid,PApply funid args) =
|
||||||
ppFCat fcat <+> text "->" <+> ppFunId funid <> brackets (hcat (punctuate comma (map ppFCat args)))
|
ppFId fid <+> text "->" <+> ppFunId funid <> brackets (hcat (punctuate comma (map ppFId args)))
|
||||||
ppProduction (fcat,PCoerce arg) =
|
ppProduction (fid,PCoerce arg) =
|
||||||
ppFCat fcat <+> text "->" <+> char '_' <> brackets (ppFCat arg)
|
ppFId fid <+> text "->" <+> char '_' <> brackets (ppFId arg)
|
||||||
ppProduction (fcat,PConst _ _ ss) =
|
ppProduction (fid,PConst _ _ ss) =
|
||||||
ppFCat fcat <+> text "->" <+> ppStrs ss
|
ppFId fid <+> text "->" <+> ppStrs ss
|
||||||
|
|
||||||
ppCncFun (funid,CncFun fun arr) =
|
ppCncFun (funid,CncFun fun arr) =
|
||||||
ppFunId funid <+> text ":=" <+> parens (hcat (punctuate comma (map ppSeqId (elems arr)))) <+> brackets (ppCId fun)
|
ppFunId funid <+> text ":=" <+> parens (hcat (punctuate comma (map ppSeqId (elems arr)))) <+> brackets (ppCId fun)
|
||||||
@@ -70,7 +70,7 @@ ppSeq (seqid,seq) =
|
|||||||
ppSeqId seqid <+> text ":=" <+> hsep (map ppSymbol (elems seq))
|
ppSeqId seqid <+> text ":=" <+> hsep (map ppSymbol (elems seq))
|
||||||
|
|
||||||
ppCncCat (id,(CncCat start end labels)) =
|
ppCncCat (id,(CncCat start end labels)) =
|
||||||
ppCId id <+> text ":=" <+> (text "range " <+> brackets (ppFCat start <+> text ".." <+> ppFCat end) $$
|
ppCId id <+> text ":=" <+> (text "range " <+> brackets (ppFId start <+> text ".." <+> ppFId end) $$
|
||||||
text "labels" <+> brackets (vcat (map (text . show) (elems labels))))
|
text "labels" <+> brackets (vcat (map (text . show) (elems labels))))
|
||||||
|
|
||||||
ppPrintName (id,name) =
|
ppPrintName (id,name) =
|
||||||
@@ -85,12 +85,12 @@ ppAlt (Alt ts ps) = ppStrs ts <+> char '/' <+> hsep (map (doubleQuotes . text) p
|
|||||||
|
|
||||||
ppStrs ss = doubleQuotes (hsep (map text ss))
|
ppStrs ss = doubleQuotes (hsep (map text ss))
|
||||||
|
|
||||||
ppFCat fcat
|
ppFId fid
|
||||||
| fcat == fcatString = text "CString"
|
| fid == fidString = text "CString"
|
||||||
| fcat == fcatInt = text "CInt"
|
| fid == fidInt = text "CInt"
|
||||||
| fcat == fcatFloat = text "CFloat"
|
| fid == fidFloat = text "CFloat"
|
||||||
| fcat == fcatVar = text "CVar"
|
| fid == fidVar = text "CVar"
|
||||||
| otherwise = char 'C' <> int fcat
|
| otherwise = char 'C' <> int fid
|
||||||
|
|
||||||
ppFunId funid = char 'F' <> int funid
|
ppFunId funid = char 'F' <> int funid
|
||||||
ppSeqId seqid = char 'S' <> int seqid
|
ppSeqId seqid = char 'S' <> int seqid
|
||||||
|
|||||||
Reference in New Issue
Block a user