diff --git a/bowtie/src/Bowtie/Surface/Parse.hs b/bowtie/src/Bowtie/Surface/Parse.hs index 9398776..db9cbf3 100644 --- a/bowtie/src/Bowtie/Surface/Parse.hs +++ b/bowtie/src/Bowtie/Surface/Parse.hs @@ -14,8 +14,8 @@ import Bowtie.Lib.OrderedMap (OrderedMap) import Bowtie.Lib.Prelude hiding (many, some) import Bowtie.Surface.AST import Bowtie.Type.Parse - (Parser, ParserErrorBundle, lexeme, lowerIbindingParser, parseTest, - spacesOrNewlines, symbol, upperIbindingParser) + (Parser, ParserErrorBundle, lexeme, lowerIdParser, parseTest, + spacesOrNewlines, symbol, upperIdParser) import Control.Applicative.Combinators.NonEmpty import Text.Megaparsec hiding (parse, parseTest, some) @@ -99,7 +99,7 @@ bindingParser = do bindingBodyParser :: Parser (Id, Expr) bindingBodyParser = do pos <- Lexer.indentLevel - i <- lexeme lowerIbindingParser + i <- lexeme lowerIdParser symbol "=" _ <- Lexer.indentGuard spacesOrNewlines GT pos e <- exprParser @@ -121,7 +121,7 @@ lamParser :: Parser Expr lamParser = do pos <- Lexer.indentLevel symbol "\\" - id <- lexeme lowerIbindingParser + id <- lexeme lowerIdParser mType <- optional annotationParser symbol "." _ <- Lexer.indentGuard spacesOrNewlines GT pos @@ -186,8 +186,8 @@ caseParser = altParser :: Parser Alt altParser = do pos <- Lexer.indentLevel - i <- lexeme upperIbindingParser - ids <- many (lexeme lowerIbindingParser) + i <- lexeme upperIdParser + ids <- many (lexeme lowerIdParser) symbol "->" _ <- Lexer.indentGuard spacesOrNewlines GT pos e <- exprParser @@ -220,11 +220,11 @@ itemParser = varParser :: Parser Expr varParser = - fmap Var (lexeme lowerIbindingParser) + fmap Var (lexeme lowerIdParser) conParser :: Parser Expr conParser = - fmap Construct (lexeme upperIbindingParser) + fmap Construct (lexeme upperIdParser) -- | -- >>> parseTest intParser "1" diff --git a/bowtie/src/Bowtie/Type/Parse.hs b/bowtie/src/Bowtie/Type/Parse.hs index 41fcd74..bdb526e 100644 --- a/bowtie/src/Bowtie/Type/Parse.hs +++ b/bowtie/src/Bowtie/Type/Parse.hs @@ -4,8 +4,8 @@ module Bowtie.Type.Parse , typeDeclarationParser , typeSignatureParser , typeParser - , lowerIbindingParser - , upperIbindingParser + , lowerIdParser + , upperIdParser -- | Helpers , lexeme @@ -63,8 +63,8 @@ typeDeclarationParser = do -- parser started with Break it would actually have to be -- @try (toss Break)@ so they wouldn't step on each other's toes. symbol "type" - typeId <- lexeme upperIbindingParser - typeArgs <- many (lexeme lowerIbindingParser) + typeId <- lexeme upperIdParser + typeArgs <- many (lexeme lowerIdParser) symbol "=" constructors <- constructorParser `sepBy` symbol "|" case OrderedMap.fromList constructors of @@ -79,7 +79,7 @@ typeDeclarationParser = do -- (Id "Bar",[TConstructor (Id "Bool"),TVariable (Id "a")]) constructorParser :: Parser (Id, [Type]) constructorParser = do - id <- lexeme upperIbindingParser + id <- lexeme upperIdParser args <- many constructorArgParser pure (id, args) @@ -107,7 +107,7 @@ constructorArgParser = -- (Id "foo",TArrow (TConstructor (Id "Int")) (TVariable (Id "a"))) typeSignatureParser :: Parser (Id, Type) typeSignatureParser = do - i <- lexeme lowerIbindingParser + i <- lexeme lowerIdParser symbol ":" t <- typeParser pure (i, t) @@ -160,18 +160,18 @@ singleTypeParser = do singleTypeParser' :: Parser Type singleTypeParser' = -- TODO: a good label - fmap TVariable (lexeme lowerIbindingParser) - <|> fmap TConstructor (lexeme upperIbindingParser) + fmap TVariable (lexeme lowerIdParser) + <|> fmap TConstructor (lexeme upperIdParser) -- | --- >>> parseTest lowerIbindingParser "a" +-- >>> parseTest lowerIdParser "a" -- Id "a" -- -- When we had a separate lexer this could just be tried after trying -- to lex keyword tokens like "let" and "in". Now that we don't -- it needs logic so that it doesn't eat those keywords. -lowerIbindingParser :: Parser Id -lowerIbindingParser = do +lowerIdParser :: Parser Id +lowerIdParser = do notFollowedBy (keyword *> satisfy (not . validIdChar)) c <- satisfy Char.isLower rest <- takeWhileP (Just "followup identifier char") validIdChar @@ -192,10 +192,10 @@ keywordList = ] -- | --- >>> parseTest upperIbindingParser "Unit" +-- >>> parseTest upperIdParser "Unit" -- Id "Unit" -upperIbindingParser :: Parser Id -upperIbindingParser = do +upperIdParser :: Parser Id +upperIdParser = do c <- satisfy Char.isUpper rest <- takeWhileP (Just "followup identifier char") validIdChar pure (Id (Text.cons c rest))