0

我正在使用 Megaparsec 编写解析器。基本上,主文件将打开并读取文件的内容,然后解析该内容。在 ghci 中运行主文件时,一切都正确生成 img-1

但是当我尝试使用堆栈 runghc -- app/Main.hs 运行主文件时,发生了奇怪的解析错误: img-2

这是 GitHub 上的项目:https ://github.com/phuongduyphan/dbml-parser-haskell

某人可以看看并告诉我我做错了什么吗?为什么运行相同的 main 函数会导致堆栈 ghci 和堆栈 runghc 的输出不同?

4

1 回答 1

2

我克隆了您的存储库并尝试了:

stack runghc -- app/Main.hs holistics.dbml

并得到:

Right 
( DBMLState 
    { tableS = fromList 
        [ 
            ( 0
            , NTable 
                { ntId = 0
                , ntGroupId = Nothing
                , ntName = "users" 
                , ntTableSettings = Nothing
                , ntFieldIds = [ 0 ]
                , ntIndexIds = []
                } 
            ) 
        ]
    , enumS = fromList []
    , refS = fromList []
    , tableGroupS = fromList []
    , fieldS = fromList 
        [ 
            ( 0
            , NField 
                { nfId = 0
                , nfTableId = 0
                , nfEnumId = Nothing
                , nfName = "id" 
                , nfType = "int" 
                , nfFieldSettings = Just [ FieldNote "abc" ]
                } 
            ) 
        ]
    , indexS = fromList []
    , endpointS = fromList []
    , tableIdCounter = 1
    , enumIdCounter = 0
    , refIdCounter = 0
    , tableGroupIdCounter = 0
    , fieldIdCounter = 1
    , indexIdCounter = 0
    , endpointIdCounter = 0
    } 
)

问题很可能是堆栈或本地开发环境的设置问题。供参考,运行

stack --version

给我

Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2

更新或重新安装堆栈可能是一种可能的解决方案。

于 2020-01-16T05:21:43.560 回答