on master help sign in
Merge pull request #1880 from ahmadsalim/feature/underscore-ident

Allow identifiers to start with underscore (_).

commitb0e9e36ca6668b9e260c61c96cc1649af772fb61 authorDavid Christiansen <david@davidchristiansen.dk> dateMon 9 Feb 2015, 11:56 (12 years ago) parent7409ce04d8ab37
2 files changed+5−3
src/Idris/AbsSyntaxTree.hs+1−1 src/Idris/ParseHelpers.hs+4−2
src/Idris/AbsSyntaxTree.hs+1−1
@@ -1655,7 +1655,7 @@ prettyName
16551655 -> Doc OutputAnnotation
16561656prettyName infixParen showNS bnd n
16571657 | (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 "_"
16591659 | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
16601660 | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
16611661 where fullName = text nameSpace <> parenthesise (text (baseName n))
src/Idris/ParseHelpers.hs+4−2
@@ -224,7 +224,7 @@ float = Tok.double
224224idrisStyle :: MonadicParsing m => IdentifierStyle m
225225idrisStyle = IdentifierStyle _styleName _styleStart _styleLetter _styleReserved Hi.Identifier Hi.ReservedIdentifier
226226 where _styleName = "Idris"
227− _styleStart = satisfy isAlpha
227+ _styleStart = satisfy isAlpha <|> oneOf "_"
228228 _styleLetter = satisfy isAlphaNum <|> oneOf "_'."
229229 _styleReserved = HS.fromList ["let", "in", "data", "codata", "record", "Type",
230230 "do", "dsl", "import", "impossible",
@@ -262,7 +262,9 @@ reservedOp name = token $ try $
262262
263263-- | Parses an identifier as a token
264264identifier :: 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)
266268
267269-- | Parses an identifier with possible namespace as a name
268270iName :: MonadicParsing m => [String] -> m Name