@@ -21,6 +21,12 @@ stringToken (c : cs) cur = case c of
2121 )
2222 _ -> stringToken cs (cur ++ [c])
2323
24+ compactLambda :: String -> String -> (String , String )
25+ compactLambda [] _ = error " Tokenize error in compactLambda"
26+ compactLambda (c : cs) cur = case c of
27+ ' }' -> ((' {' : cur) ++ [' }' ], cs)
28+ _ -> compactLambda cs (cur ++ [c])
29+
2430tokenize' :: String -> [String ] -> String -> [String ]
2531tokenize' cur tokens (c : cs) = case c of
2632 ' (' -> tokenize' " " (" (" : add' cur tokens) cs
@@ -32,6 +38,11 @@ tokenize' cur tokens (c : cs) = case c of
3238 new = stringToken cs " "
3339 newTokens = fst new : tokens
3440 newCs = snd new
41+ ' {' -> tokenize' " " newTokens newCs
42+ where
43+ new = compactLambda cs " "
44+ newTokens = fst new : tokens
45+ newCs = snd new
3546 _ ->
3647 if isSpace c
3748 then tokenize' " " (add' cur tokens) cs
@@ -67,6 +78,9 @@ endsWith = (==) . last
6778isString :: String -> Bool
6879isString t = (t `endsWith` ' "' ) && (t `startsWith` ' "' )
6980
81+ isCompactLambda :: String -> Bool
82+ isCompactLambda t = (t `endsWith` ' }' ) && (t `startsWith` ' {' )
83+
7084trim :: String -> String
7185trim = init . tail
7286
@@ -75,6 +89,7 @@ parseToken t
7589 | all (\ c -> isDigit c || c == ' -' ) t && t /= " -" = Number $ read t
7690 | all (\ c -> isDigit c || c == ' -' || c == ' .' ) t && t /= " -" && t /= " ." = Float $ read t
7791 | isString t = String $ trim t
92+ | isCompactLambda t = Pair (Name " compact" ) (head $ parse $ " (" <> trim t <> " )" )
7893 | otherwise = Name t
7994
8095parse' :: [Value ] -> [String ] -> Value
0 commit comments