単純なParsec利用例
標準入力から"abc"と入力されたかをチェックするParsecの例
- プログラム
module Main where import System.IO import Text.ParserCombinators.Parsec main = getContents >>= return . parseSimple >>= print parseSimple input = parse simple "(unknown)" input simple = string "abc"
- 実行結果
> runghc .\SimpleParser.hs abc // 入力 Right "abc" > runghc .\SimpleParser.hs cba // 入力 Left "(unknown)" (line 1, column 1): unexpected "c" expecting "abc"