Parsec.Combinator:sepEndBy1
module Main where import Text.ParserCombinators.Parsec test1 :: Parser String test1 = sepEndBy1 letter (char ',') run :: Show a => Parser a -> String -> IO () run p input = case (parse p "" input) of Left err -> do{ putStr "parse error at " ; print err } Right x -> print x
で、
*Main> run test1 "" parse error at (line 1, column 1): unexpected end of input expecting letter *Main> run test1 "," parse error at (line 1, column 1): unexpected "," expecting letter *Main> run test1 "a," "a" *Main> run test1 "ab," "a" *Main> run test1 "a,b" "ab" *Main> run test1 "a,b," "ab"