3
我寫了一個parsec代碼,它完美地適合我想要的東西。它分析預期以下文件:Parsec:跳過第一行
4,5
6,7
相應的代碼是這樣的:
import Text.ParserCombinators.Parsec
import Control.Applicative hiding ((<|>))
import Control.Monad
data Test = Test Integer Integer deriving Show
integer :: Parser Integer
integer = rd <$> many1 digit
where rd = read :: String -> Integer
testParser :: Parser Test
testParser = do
a <- integer
char ','
b <- integer
return $ Test a b
testParserFile = endBy testParser eol
eol :: Parser Char
eol = char '\n'
main = do
a <- parseFromFile testParserFile "./jack.txt"
print a
但我的實際文件是這樣的:
col 1,col 2
4,5
6,7
有沒有一種方法,使上面的解析器,只是跳過第一行?
是的,消耗'許多'不是''\ n's,然後是'\ n',然後繼續前進 – luqui