Improvements to grammar

This commit is contained in:
2024-11-09 21:39:45 -08:00
parent bb749a917a
commit 6abd97ee85
9 changed files with 80 additions and 80 deletions

View File

@@ -233,20 +233,23 @@ ebind = do
ibind : Parser (List (FC, String, Icit, Raw))
ibind = do
-- I've gone back and forth on this, but I think {m a b} is more useful than {Nat}
sym "{"
-- REVIEW - I have name required and type optional, which I think is the opposite of what I expect
names <- try (some (withPos varname) <* sym ":")
ty <- typeExpr
names <- (some (withPos varname))
ty <- optional (sym ":" *> typeExpr)
sym "}"
pure $ map (\(pos,name) => (pos, name, Implicit, ty)) names
pure $ map (\(pos,name) => (pos, name, Implicit, fromMaybe (RImplicit pos) ty)) names
abind : Parser (List (FC, String, Icit, Raw))
abind = do
-- for this, however, it would be nice to allow {{Monad A}}
sym "{{"
names <- try (some (withPos varname) <* sym ":")
name <- optional $ try (withPos varname <* sym ":")
ty <- typeExpr
sym "}}"
pure $ map (\(pos,name) => (pos, name, Auto, ty)) names
case name of
Just (pos,name) => pure [(pos, name, Auto, ty)]
Nothing => pure [(getFC ty, "_", Auto, ty)]
arrow : Parser Unit
arrow = sym "->" <|> sym ""
@@ -371,8 +374,8 @@ parseDecl = parseMixfix <|> parsePType <|> parsePFunc <|> parseNorm <|> parseDat
export
parseModHeader : Parser String
parseModHeader = sameLevel (keyword "module") >> uident
parseModHeader : Parser (FC, String)
parseModHeader = sameLevel (keyword "module") >> withPos uident
export
parseImports : Parser (List Import)

View File

@@ -63,13 +63,13 @@ processModule base stk name = do
let Right toks = tokenise src
| Left err => fail (showError src err)
let Right (modName, ops, toks) := partialParse parseModHeader top.ops toks
let Right ((nameFC, modName), ops, toks) := partialParse parseModHeader top.ops toks
| Left err => fail (showError src err)
putStrLn "module \{modName}"
let True = name == modName
| _ => fail "ERROR at (0, 0): module name \{show modName} doesn't match file name \{show fn}"
| _ => fail "ERROR at \{show nameFC}: module name \{show modName} doesn't match file name \{show fn}"
let Right (imports, ops, toks) := partialParse parseImports ops toks
| Left err => fail (showError src err)