on 17618de help sign in
elk/src/AST/Helpers.hs
32 lines 623 B history raw
1{-# OPTIONS_GHC -Wall #-}
2module AST.Helpers where
4import qualified Data.Char as Char
8splitDots :: String -> [String]
9splitDots variable =
10 go [] variable
11 where
12 go vars str =
13 case break (=='.') str of
14 (x,_:rest) | isOp x -> vars ++ [x ++ '.' : rest]
15 | otherwise -> go (vars ++ [x]) rest
16 (x,[]) -> vars ++ [x]
19isTuple :: String -> Bool
20isTuple name =
21 take 6 name == "_Tuple"
22 && all Char.isDigit (drop 6 name)
25isOp :: String -> Bool
26isOp name =
27 all isSymbol name
30isSymbol :: Char -> Bool
31isSymbol c =
32 Char.isSymbol c || elem c "+-/*=.$<>:&|^?%#@~!"