diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-08 17:26:43 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-08 17:27:57 +0200 |
| commit | 29f1d1b22b240ee9ef3cf4b867bc7a663d8d3a6a (patch) | |
| tree | 9bbf6c53a3782c48f679a02e93fbe46908f44d34 /src/Parser.hs | |
| parent | 22a9ade3409b40f644a5b79fc6f1e5b06419c507 (diff) | |
Improve error reporting
Diffstat (limited to 'src/Parser.hs')
| -rw-r--r-- | src/Parser.hs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index e7c0701..be75ab3 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -13,11 +13,11 @@ import Utils validateBalance :: [String] -> [AST] -> LContext [AST] validateBalance allowed asts = do when (MB.isJust parenM && "(" `notElem` allowed) - $ throwL (astPos $ MB.fromJust parenM) "unbalanced function call" + $ throwL (astPos $ MB.fromJust parenM, "unbalanced function call") when (MB.isJust bracketM && "[" `notElem` allowed) - $ throwL (astPos $ MB.fromJust bracketM) "unbalanced vector" + $ throwL (astPos $ MB.fromJust bracketM, "unbalanced vector") when (MB.isJust curlyM && "{" `notElem` allowed) - $ throwL (astPos $ MB.fromJust curlyM) "unbalanced hash map" + $ throwL (astPos $ MB.fromJust curlyM, "unbalanced hash map") return asts where parenM = L.find ((== ASTSymbol "(") . an) asts @@ -69,8 +69,7 @@ _parse acc (Token { tokenContent = "}" }:rest) = do let children' = takeWhile (an .> (/= ASTSymbol "{")) acc children <- validateBalance ["{"] children' let openCurly = MB.fromJust $ L.find (an .> (== ASTSymbol "{")) acc - pairs <- asPairsM (reverse children) `catchError` - \(LException _ e) -> throwL (astPos openCurly) e + pairs <- asPairsM (reverse children) `catchError` appendError (astPos openCurly, "when parsing a hash map") let hmap = openCurly { an = ASTHashMap (M.fromList pairs) } let newAcc = hmap : drop (length children + 1) acc _parse newAcc rest |
