on master help sign in
Merge pull request #1880 from ahmadsalim/feature/underscore-ident
b0e9e36David Christiansen
src/Idris/AbsSyntaxTree.hs+1−1
@@ -1655,7 +1655,7 @@ prettyName
1655 -> Doc OutputAnnotation
1655 -> Doc OutputAnnotation
1656prettyName infixParen showNS bnd n
1656prettyName infixParen showNS bnd n
1657 | (MN _ s) <- n, isPrefixOf "_" $ T.unpack s = text "_"
1657 | (MN _ s) <- n, isPrefixOf "_" $ T.unpack s = text "_"
1658− | (UN n') <- n, isPrefixOf "_" $ T.unpack n' = text "_"
1658+ | (UN n') <- n, T.unpack n' == "_" = text "_"
1659 | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
1659 | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
1660 | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
1660 | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
1661 where fullName = text nameSpace <> parenthesise (text (baseName n))
1661 where fullName = text nameSpace <> parenthesise (text (baseName n))
src/Idris/ParseHelpers.hs+4−2
@@ -224,7 +224,7 @@ float = Tok.double
224idrisStyle :: MonadicParsing m => IdentifierStyle m
224idrisStyle :: MonadicParsing m => IdentifierStyle m
225idrisStyle = IdentifierStyle _styleName _styleStart _styleLetter _styleReserved Hi.Identifier Hi.ReservedIdentifier
225idrisStyle = IdentifierStyle _styleName _styleStart _styleLetter _styleReserved Hi.Identifier Hi.ReservedIdentifier
226 where _styleName = "Idris"
226 where _styleName = "Idris"
227− _styleStart = satisfy isAlpha
227+ _styleStart = satisfy isAlpha <|> oneOf "_"
228 _styleLetter = satisfy isAlphaNum <|> oneOf "_'."
228 _styleLetter = satisfy isAlphaNum <|> oneOf "_'."
229 _styleReserved = HS.fromList ["let", "in", "data", "codata", "record", "Type",
229 _styleReserved = HS.fromList ["let", "in", "data", "codata", "record", "Type",
230 "do", "dsl", "import", "impossible",
230 "do", "dsl", "import", "impossible",
@@ -262,7 +262,9 @@ reservedOp name = token $ try $
262
262
263-- | Parses an identifier as a token
263-- | Parses an identifier as a token
264identifier :: MonadicParsing m => m String
264identifier :: MonadicParsing m => m String
265−identifier = token $ Tok.ident idrisStyle
265+identifier = try(do i <- token $ Tok.ident idrisStyle
266+ when (i == "_") $ unexpected "wildcard"
267+ return i)
266
268
267-- | Parses an identifier with possible namespace as a name
269-- | Parses an identifier with possible namespace as a name
268iName :: MonadicParsing m => [String] -> m Name
270iName :: MonadicParsing m => [String] -> m Name