git.haldean.org del / 30e5126
scoped id support in compiler, sorta Haldean Brown 4 years ago
3 changed file(s) with 7 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5555 mb <- mapM (mapexprM f) xs
5656 f $ Apply mh mb
5757 mapexprM f x@(Id _) = f x
58 mapexprM f x@(ScopedId _) = f x
58 mapexprM f x@(ScopedId _ _) = f x
5959 mapexprM f (Number num) = f $ Number num
6060 mapexprM f (Let n e b) = do
6161 me <- mapexprM f e
9999 anyexpr f e@(Negate ex) = if f e then True else anyexpr f ex
100100 anyexpr f e@(Apply hd xs) = if f e then True else anyexpr f hd || any id (map (anyexpr f) xs)
101101 anyexpr f e@(Id _) = f e
102 anyexpr f e@(ScopedId _) = f e
102 anyexpr f e@(ScopedId _ _) = f e
103103 anyexpr f e@(Number _) = f e
104104 anyexpr f e@(Let _ v b) = if f e then True else anyexpr f v || anyexpr f b
105105 anyexpr f e@(Boolean _) = f e
5050 genExpr (A.GtE x y) = binary GtE x y
5151 genExpr (A.Negate x) = genExpr x >>= return . Negate
5252 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)
5454 genExpr (A.Number (A.DelInt i)) = return $ Atomic $ InInt i
5555 genExpr (A.Number (A.DelFloat f)) = return $ Atomic $ InFloat f
5656
8282 ident :: PT.Parser Expr
8383 ident = do
8484 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)
8789
8890 exprNoSub :: PT.Parser Expr
8991 exprNoSub = ident