我最后写了parseLexeme,来代替中的lexeme
this tutorial
data Lexeme a = Lexeme a String -- String contains the spaces after the lexeme
whites :: Parser String
whites = many spaceChar
parseLexeme :: Parser a -> Parser (Lexeme a)
parseLexeme p = do
value <- p
w <- whites
return $ Lexeme value w
instance PPrint a => PPrint (Lexeme a) where
pprint (Lexeme value w) = (pprint value) ++ w
data Identifier = Identifier (Lexeme String)
parseIdentifier :: Parser Identifier
parseIdentifier = do
v <- parseLexeme $ (:) <$> letterChar <*> many (alphaNumChar <|> char '_')
return $ Identifier v
instance PPrint Identifier where
pprint (Identifier l) = pprint l