我正在解析一种语言,我想$include
在解析时对其他文件有语法。
我的代码:
import Text.ParserCombinators.Parsec
import Text.Parsec.Prim (parserZero)
import Text.ParserCombinators.Parsec.Char
import Control.Monad.Trans
import Data.Functor.Identity
notaInclude :: Parser [SourcesItem]
notaInclude = do
try $ string "$Include" >> blanks1
char '"'
fileName <- quotedStringParser
char '"'
i <- getInput
included <- liftIO $ readFile fileName
setInput included
si <- sources
setInput i
return si
来自 GHC 的错误消息:
Lazi/Lazi'nh/Language/Sources/Parser.hs:65:17:
No instance for (MonadIO Identity) arising from a use of `liftIO'
Possible fix: add an instance declaration for (MonadIO Identity)
In the expression: liftIO
In a stmt of a 'do' block: included <- liftIO $ readFile fileName
In the expression:
do { try
(do { string "$Include";
blanks1 });
char '"';
fileName <- quotedStringParser;
char '"';
.... }
我怎样才能让它工作?