start working on scoped IDs (doesn't build yet)
Haldean Brown
4 years ago
29 | 29 |
| Apply Expr [Expr]
|
30 | 30 |
| NativeCall T.Text [Expr]
|
31 | 31 |
| Id Name
|
|
32 |
| ScopedId Name Name
|
32 | 33 |
| Number DelNum
|
33 | 34 |
| Boolean Bool
|
34 | 35 |
| Let Name Expr Expr
|
|
90 | 91 |
show (Subscript e sub) = show e ++ "_" ++ T.unpack sub
|
91 | 92 |
show (Apply h xs) = showExprList (show h) xs
|
92 | 93 |
show (Id n) = T.unpack n
|
|
94 |
show (ScopedId p n) = T.unpack p ++ "." ++ T.unpack n
|
93 | 95 |
show (Number (DelInt i)) = show i
|
94 | 96 |
show (Number (DelFloat f)) = show f
|
95 | 97 |
show (Let n e b) = concat ["(let (", T.unpack n, " ", show e, ") ", show b]
|
|
100 | 102 |
instance Show SourceUrl where
|
101 | 103 |
show (HttpSource u) = show u
|
102 | 104 |
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
|
103 | 110 |
|
104 | 111 |
-- Converts a list of Del numbers to floats if any elements in the list are
|
105 | 112 |
-- floats; otherwise, keeps them as integers
|
54 | 54 |
mh <- mapexprM f hd
|
55 | 55 |
mb <- mapM (mapexprM f) xs
|
56 | 56 |
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
|
58 | 59 |
mapexprM f (Number num) = f $ Number num
|
59 | 60 |
mapexprM f (Let n e b) = do
|
60 | 61 |
me <- mapexprM f e
|
|
98 | 99 |
anyexpr f e@(Negate ex) = if f e then True else anyexpr f ex
|
99 | 100 |
anyexpr f e@(Apply hd xs) = if f e then True else anyexpr f hd || any id (map (anyexpr f) xs)
|
100 | 101 |
anyexpr f e@(Id _) = f e
|
|
102 |
anyexpr f e@(ScopedId _) = f e
|
101 | 103 |
anyexpr f e@(Number _) = f e
|
102 | 104 |
anyexpr f e@(Let _ v b) = if f e then True else anyexpr f v || anyexpr f b
|
103 | 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 | 54 |
genExpr (A.Number (A.DelInt i)) = return $ Atomic $ InInt i
|
54 | 55 |
genExpr (A.Number (A.DelFloat f)) = return $ Atomic $ InFloat f
|
55 | 56 |
|
79 | 79 |
rest <- many expr
|
80 | 80 |
return $ Apply hd rest
|
81 | 81 |
|
|
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 |
|
82 | 88 |
exprNoSub :: PT.Parser Expr
|
83 | |
exprNoSub = (Id <$> name)
|
|
89 |
exprNoSub = ident
|
84 | 90 |
<|> (Id <$> op)
|
85 | 91 |
<|> apply
|
86 | 92 |
<|> number
|
68 | 68 |
Id name -> case Map.lookup name types of
|
69 | 69 |
Just t -> return t
|
70 | 70 |
Nothing -> Failure $ BadId name
|
|
71 |
ScopedId _ _ -> exprType tc (canonicalId e)
|
71 | 72 |
Number (DelInt _) -> return IntType
|
72 | 73 |
Number (DelFloat _) -> return FloatType
|
73 | 74 |
Boolean _ -> return BoolType
|