forked from GitHub/gf-core
Fixed (final?) two bugs in the SISR generation.
This commit is contained in:
@@ -32,19 +32,19 @@ data SISRFormat =
|
|||||||
SISROld
|
SISROld
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
type SISRTag = [JS.Expr]
|
type SISRTag = [JS.DeclOrExpr]
|
||||||
|
|
||||||
|
|
||||||
prSISR :: SISRTag -> String
|
prSISR :: SISRTag -> String
|
||||||
prSISR = JS.printTree
|
prSISR = JS.printTree
|
||||||
|
|
||||||
topCatSISR :: String -> String -> SISRFormat -> SISRTag
|
topCatSISR :: String -> String -> SISRFormat -> SISRTag
|
||||||
topCatSISR i c fmt = [field (fmtOut fmt) i `ass` fmtRef fmt c]
|
topCatSISR i c fmt = map JS.DExpr [field (fmtOut fmt) i `ass` fmtRef fmt c]
|
||||||
|
|
||||||
profileInitSISR :: CFTerm -> SISRFormat -> SISRTag
|
profileInitSISR :: CFTerm -> SISRFormat -> SISRTag
|
||||||
profileInitSISR t fmt
|
profileInitSISR t fmt
|
||||||
| null (usedChildren t) = []
|
| null (usedChildren t) = []
|
||||||
| otherwise = [children `ass` JS.ENew (JS.Ident "Array") []]
|
| otherwise = [JS.Decl [JS.DInit children (JS.ENew (JS.Ident "Array") [])]]
|
||||||
|
|
||||||
usedChildren :: CFTerm -> [Int]
|
usedChildren :: CFTerm -> [Int]
|
||||||
usedChildren (CFObj _ ts) = foldr union [] (map usedChildren ts)
|
usedChildren (CFObj _ ts) = foldr union [] (map usedChildren ts)
|
||||||
@@ -55,12 +55,12 @@ usedChildren _ = []
|
|||||||
|
|
||||||
catSISR :: CFTerm -> SRGNT -> SISRFormat -> SISRTag
|
catSISR :: CFTerm -> SRGNT -> SISRFormat -> SISRTag
|
||||||
catSISR t (c,i) fmt
|
catSISR t (c,i) fmt
|
||||||
| i `elem` usedChildren t =
|
| i `elem` usedChildren t = map JS.DExpr
|
||||||
[JS.EIndex children (JS.EInt (fromIntegral i)) `ass` fmtRef fmt c]
|
[JS.EIndex (JS.EVar children) (JS.EInt (fromIntegral i)) `ass` fmtRef fmt c]
|
||||||
| otherwise = []
|
| otherwise = []
|
||||||
|
|
||||||
profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag
|
profileFinalSISR :: CFTerm -> SISRFormat -> SISRTag
|
||||||
profileFinalSISR term fmt = g term
|
profileFinalSISR term fmt = map JS.DExpr $ g term
|
||||||
where
|
where
|
||||||
-- optimization for tokens
|
-- optimization for tokens
|
||||||
g (CFObj n []) = [field (fmtOut fmt) "name" `ass` JS.EStr (prIdent n)]
|
g (CFObj n []) = [field (fmtOut fmt) "name" `ass` JS.EStr (prIdent n)]
|
||||||
@@ -74,7 +74,7 @@ profileFinalSISR term fmt = g term
|
|||||||
where ret = JS.EVar (JS.Ident "ret")
|
where ret = JS.EVar (JS.Ident "ret")
|
||||||
f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)]
|
f (CFAbs v x) = JS.EFun [var v] [JS.SReturn (f x)]
|
||||||
f (CFApp x y) = JS.ECall (f x) [f y]
|
f (CFApp x y) = JS.ECall (f x) [f y]
|
||||||
f (CFRes i) = JS.EIndex children (JS.EInt (fromIntegral i))
|
f (CFRes i) = JS.EIndex (JS.EVar children) (JS.EInt (fromIntegral i))
|
||||||
f (CFVar v) = JS.EVar (var v)
|
f (CFVar v) = JS.EVar (var v)
|
||||||
f (CFConst s) = JS.EStr s
|
f (CFConst s) = JS.EStr s
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ fmtOut SISROld = JS.EVar (JS.Ident "$")
|
|||||||
|
|
||||||
fmtRef SISROld c = JS.EVar (JS.Ident ("$" ++ c))
|
fmtRef SISROld c = JS.EVar (JS.Ident ("$" ++ c))
|
||||||
|
|
||||||
children = JS.EVar (JS.Ident "c")
|
children = JS.Ident "c"
|
||||||
|
|
||||||
var v = JS.Ident ("x" ++ show v)
|
var v = JS.Ident ("x" ++ show v)
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ cfgRulesToSRGRule names probs rs@(r:_) = SRGRule cat origCat rhs
|
|||||||
= SRGAlt (ruleProb probs r) n (mkSRGSymbols 0 ss)
|
= SRGAlt (ruleProb probs r) n (mkSRGSymbols 0 ss)
|
||||||
where
|
where
|
||||||
mkSRGSymbols _ [] = []
|
mkSRGSymbols _ [] = []
|
||||||
mkSRGSymbols i (Cat c:ss) = Cat (renameCat c,0) : mkSRGSymbols (i+1) ss
|
mkSRGSymbols i (Cat c:ss) = Cat (renameCat c,i) : mkSRGSymbols (i+1) ss
|
||||||
mkSRGSymbols i (Tok t:ss) = Tok t : mkSRGSymbols i ss
|
mkSRGSymbols i (Tok t:ss) = Tok t : mkSRGSymbols i ss
|
||||||
renameCat = lookupFM_ names
|
renameCat = lookupFM_ names
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user