git.haldean.org del / 610b1ae
start working on scoped IDs (doesn't build yet) Haldean Brown 4 years ago
5 changed file(s) with 19 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2929 | Apply Expr [Expr]
3030 | NativeCall T.Text [Expr]
3131 | Id Name
32 | ScopedId Name Name
3233 | Number DelNum
3334 | Boolean Bool
3435 | Let Name Expr Expr
9091 show (Subscript e sub) = show e ++ "_" ++ T.unpack sub
9192 show (Apply h xs) = showExprList (show h) xs
9293 show (Id n) = T.unpack n
94 show (ScopedId p n) = T.unpack p ++ "." ++ T.unpack n
9395 show (Number (DelInt i)) = show i
9496 show (Number (DelFloat f)) = show f
9597 show (Let n e b) = concat ["(let (", T.unpack n, " ", show e, ") ", show b]
100102 instance Show SourceUrl where
101103 show (HttpSource u) = show u
102104 show (HttpsSource u) = show u
105
106 canonicalId :: Expr -> Expr
107 canonicalId (ScopedId p n) = Id $ T.concat [p, ".", n]
108 canonicalId e@(Id _) = e
109 canonicalId _ = undefined
103110
104111 -- Converts a list of Del numbers to floats if any elements in the list are
105112 -- floats; otherwise, keeps them as integers
5454 mh <- mapexprM f hd
5555 mb <- mapM (mapexprM f) xs
5656 f $ Apply mh mb
57 mapexprM f (Id n) = f $ Id n
57 mapexprM f x@(Id _) = f x
58 mapexprM f x@(ScopedId _) = f x
5859 mapexprM f (Number num) = f $ Number num
5960 mapexprM f (Let n e b) = do
6061 me <- mapexprM f e
9899 anyexpr f e@(Negate ex) = if f e then True else anyexpr f ex
99100 anyexpr f e@(Apply hd xs) = if f e then True else anyexpr f hd || any id (map (anyexpr f) xs)
100101 anyexpr f e@(Id _) = f e
102 anyexpr f e@(ScopedId _) = f e
101103 anyexpr f e@(Number _) = f e
102104 anyexpr f e@(Let _ v b) = if f e then True else anyexpr f v || anyexpr f b
103105 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)
5354 genExpr (A.Number (A.DelInt i)) = return $ Atomic $ InInt i
5455 genExpr (A.Number (A.DelFloat f)) = return $ Atomic $ InFloat f
5556
7979 rest <- many expr
8080 return $ Apply hd rest
8181
82 ident :: PT.Parser Expr
83 ident = do
84 n <- name
85 x <- (char '.' >> name)
86 if empty x then return (Id n) else return (ScopedId n x)
87
8288 exprNoSub :: PT.Parser Expr
83 exprNoSub = (Id <$> name)
89 exprNoSub = ident
8490 <|> (Id <$> op)
8591 <|> apply
8692 <|> number
6868 Id name -> case Map.lookup name types of
6969 Just t -> return t
7070 Nothing -> Failure $ BadId name
71 ScopedId _ _ -> exprType tc (canonicalId e)
7172 Number (DelInt _) -> return IntType
7273 Number (DelFloat _) -> return FloatType
7374 Boolean _ -> return BoolType