in class, wrote parsers defining our own parser type , gave lot of flexibility. example, if wanted make code , parse out "[at]" '@', write
atparser = parser $ \s -> case s of w:x:y:z:zs -> | (w:x:y:z:[]) == "[at]" = ['@',zs] | otherwise = [] zs -> []
however, cannot figure out how implement sort of parser using text.parsercombinators. possible?
thanks
i believe you're looking string
combinator.
λ> :set -package parsec package flags have changed, resetting , loading new packages... λ> import text.parsec λ> :t string string :: stream s m char => string -> parsect s u m string λ> parse (string "[at]") "" "[at]" right "[at]" λ> parse (string "[at]") "" "[at" left (line 1, column 1): unexpected end of input expecting "[at]" λ> parse ('@' <$ string "[at]") "" "[at]" right '@'
Comments
Post a Comment