scoped id support in compiler, sorta
Haldean Brown
4 years ago
55 | 55 |
mb <- mapM (mapexprM f) xs
|
56 | 56 |
f $ Apply mh mb
|
57 | 57 |
mapexprM f x@(Id _) = f x
|
58 | |
mapexprM f x@(ScopedId _) = f x
|
|
58 |
mapexprM f x@(ScopedId _ _) = f x
|
59 | 59 |
mapexprM f (Number num) = f $ Number num
|
60 | 60 |
mapexprM f (Let n e b) = do
|
61 | 61 |
me <- mapexprM f e
|
|
99 | 99 |
anyexpr f e@(Negate ex) = if f e then True else anyexpr f ex
|
100 | 100 |
anyexpr f e@(Apply hd xs) = if f e then True else anyexpr f hd || any id (map (anyexpr f) xs)
|
101 | 101 |
anyexpr f e@(Id _) = f e
|
102 | |
anyexpr f e@(ScopedId _) = f e
|
|
102 |
anyexpr f e@(ScopedId _ _) = f e
|
103 | 103 |
anyexpr f e@(Number _) = f e
|
104 | 104 |
anyexpr f e@(Let _ v b) = if f e then True else anyexpr f v || anyexpr f b
|
105 | 105 |
anyexpr f e@(Boolean _) = f e
|
50 | 50 |
genExpr (A.GtE x y) = binary GtE x y
|
51 | 51 |
genExpr (A.Negate x) = genExpr x >>= return . Negate
|
52 | 52 |
genExpr (A.Id n) = return $ Atomic $ Name n
|
53 | |
genExpr e@(A.ScopedId _ _) = genExpr (canonicalId e)
|
|
53 |
genExpr e@(A.ScopedId _ _) = genExpr (A.canonicalId e)
|
54 | 54 |
genExpr (A.Number (A.DelInt i)) = return $ Atomic $ InInt i
|
55 | 55 |
genExpr (A.Number (A.DelFloat f)) = return $ Atomic $ InFloat f
|
56 | 56 |
|
82 | 82 |
ident :: PT.Parser Expr
|
83 | 83 |
ident = do
|
84 | 84 |
n <- name
|
85 | |
x <- (char '.' >> name)
|
86 | |
if empty x then return (Id n) else return (ScopedId n x)
|
|
85 |
x <- optionMaybe (char '.' >> name)
|
|
86 |
case x of
|
|
87 |
Nothing -> return (Id n)
|
|
88 |
Just v -> return (ScopedId n v)
|
87 | 89 |
|
88 | 90 |
exprNoSub :: PT.Parser Expr
|
89 | 91 |
exprNoSub = ident
|