0

在我的整个开发过程中,我一直在手动运行 alex/happy 来生成我的解析器文件,然后运行 ​​ghci 来测试代码。这可以正常工作并将我加载到 GHCI 中,但是每当我运行程序时,我的文件cabal repl中都会抛出一个错误。Parser.hs

该错误是一个类型错误:Couldn't match type '[a]' with 'Expression'但是每当我手动测试此代码时ghci main,代码运行正常吗?

我不确定我是否没有完全理解 cabal 的工作原理,但我注意到从 happy 和 cabal 生成的 haskell 解析器是完全不同的。

我在下面附上了 cabal build 命令的错误消息的开头。

编辑

因此,正如 Alec 所指出的,每当运行 cabal 构建时,它都会对-agc标志感到满意,我不知道这一点,因此我的代码需要调整。

解决方案是使用标志构建 Happy 解析器-agc并确保它以这种方式编译。这可能会导致解析器中出现一些新错误,因为生成的解析器略有不同,但根据我的研究,如果没有cabal repl上述标志,就无法愉快地运行。

  PS D:\Documents\GitHub\solidiscan> cabal build
  Preprocessing executable 'solidiscan' for solidiscan-0.1.0.0..
  Building executable 'solidiscan' for solidiscan-0.1.0.0..
  [3 of 6] Compiling Solidiscan.Parser ( dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parser.hs, dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parse
  r.o )

  dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parser.hs:2429:42: error:
      * Couldn't match type `[a]' with `Expression'
        Expected type: HappyAbsSyn
                        [SourceUnit]
                        SourceUnit
                        [Char]
                        [Char]
                        Token
                        InheritanceSpec
                        InheritanceSpecifier
                        InheritanceSpecifier
                        [Expression]
                        Expression
                        [[Expression]]
                        [Expression]
                        [EnumValue]
                        EnumValue
                        [[EParameters]]
                        [EParameters]
                        EParameters
                        Token
                        [[Parameter]]
                        [Parameter]
                        Parameter
                        ReturnParam
                        [Expression]
                        Token
                        Token
                        PublicKeyword
                        [a]
                        [a]
                        [Expression]
                        Expression
                        TypeName
                        [Expression]
                        Expression
                        Expression
                        Expression
                        Expression
                        ElseState
                        Int
                        TypeName
                        ElemType
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                        [Token]
                        [PublicKeyword]
                        [ElseState]
                        [[[EParameters]]]
                        [[EParameters]]
                        [Expression]
                        [[Expression]]
                        [InheritanceSpec]
                        [Expression]
                        [[[Parameter]]]
                        [[Parameter]]
                        [ReturnParam]
                        [StorageLocation]
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                      -> HappyAbsSyn
                            [SourceUnit]
                            SourceUnit
                            [Char]
                            [Char]
                            Token
                            InheritanceSpec
                            InheritanceSpecifier
                            InheritanceSpecifier
                            [Expression]
                            Expression
                            [[Expression]]
                            [Expression]
                            [EnumValue]
                            EnumValue
                            [[EParameters]]
                            [EParameters]
                            EParameters
                            Token
                            [[Parameter]]
                            [Parameter]
                            Parameter
                            ReturnParam
                            [Expression]
                            Token
                            TypeName
                            PublicKeyword
                            [a]
                            Expression
                            [Expression]
                            Expression
                            TypeName
                            [Expression]
                            Expression
                            Expression
                            Expression
                            Expression
                            ElseState
                            Int
                            TypeName
                            ElemType
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
                            [Token]
                            [PublicKeyword]
                            [ElseState]
                            [[[EParameters]]]
                            [[EParameters]]
                            [Expression]
                            [[Expression]]
                            [InheritanceSpec]
                            [Expression]
                            [[[Parameter]]]
                            [[Parameter]]
                            [ReturnParam]
                            [StorageLocation]
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
          Actual type: HappyAbsSyn
                        [SourceUnit]
                        SourceUnit
                        [Char]
                        [Char]
                        Token
                        InheritanceSpec
                        InheritanceSpecifier
                        InheritanceSpecifier
                        [Expression]
                        Expression
                        [[Expression]]
                        [Expression]
                        [EnumValue]
                        EnumValue
                        [[EParameters]]
                        [EParameters]
                        EParameters
                        Token
                        [[Parameter]]
                        [Parameter]
                        Parameter
                        ReturnParam
                        [Expression]
                        Token
                        Token
                        PublicKeyword
                        [a]
                        [a]
                        [Expression]
                        Expression
                        TypeName
                        [Expression]
                        Expression
                        Expression
                        Expression
                        Expression
                        ElseState
                        Int
                        TypeName
                        ElemType
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                        [Token]
                        [PublicKeyword]
                        [ElseState]
                        [[[EParameters]]]
                        [[EParameters]]
                        [Expression]
                        [[Expression]]
                        [InheritanceSpec]
                        [Expression]
                        [[[Parameter]]]
                        [[Parameter]]
                        [ReturnParam]
                        [StorageLocation]
                        [Expression]
                        [ContractConts]
                        [EParameters]
                        [Expression]
                        [FuncMods]
                        [[Expression]]
                        [EnumValue]
                        [InheritanceSpecifier]
                        [Parameter]
                        [Expression]
                      -> HappyAbsSyn
                            [SourceUnit]
                            SourceUnit
                            [Char]
                            [Char]
                            Token
                            InheritanceSpec
                            InheritanceSpecifier
                            InheritanceSpecifier
                            [Expression]
                            Expression
                            [[Expression]]
                            [Expression]
                            [EnumValue]
                            EnumValue
                            [[EParameters]]
                            [EParameters]
                            EParameters
                            Token
                            [[Parameter]]
                            [Parameter]
                            Parameter
                            ReturnParam
                            [Expression]
                            Token
                            TypeName
                            PublicKeyword
                            [a]
                            Expression
                            [Expression]
                            Expression
                            TypeName
                            [Expression]
                            Expression
                            Expression
                            Expression
                            Expression
                            ElseState
                            Int
                            TypeName
                            ElemType
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
                            [Token]
                            [PublicKeyword]
                            [ElseState]
                            [[[EParameters]]]
                            [[EParameters]]
                            [Expression]
                            [[Expression]]
                            [InheritanceSpec]
                            [[a]]
                            [[[Parameter]]]
                            [[Parameter]]
                            [ReturnParam]
                            [StorageLocation]
                            [Expression]
                            [ContractConts]
                            [EParameters]
                            [Expression]
                            [FuncMods]
                            [[Expression]]
                            [EnumValue]
                            [InheritanceSpecifier]
                            [Parameter]
                            [Expression]
      * In the second argument of `happySpecReduce_1', namely
          `happyReduction_161'
        In the expression: happySpecReduce_1 81# happyReduction_161
        In an equation for `happyReduce_161':
            happyReduce_161 = happySpecReduce_1 81# happyReduction_161
      * Relevant bindings include
          happyReduce_161 :: Happy_GHC_Exts.Int#
                            -> Token
                            -> Happy_GHC_Exts.Int#
                            -> Happy_IntList
                            -> HappyStk
                                  (HappyAbsSyn
                                    [SourceUnit]
                                    SourceUnit
                                    [Char]
                                    [Char]
                                    Token
                                    InheritanceSpec
                                    InheritanceSpecifier
                                    InheritanceSpecifier
                                    [Expression]
                                    Expression
                                    [[Expression]]
                                    [Expression]
                                    [EnumValue]
                                    EnumValue
                                    [[EParameters]]
                                    [EParameters]
                                    EParameters
                                    Token
                                    [[Parameter]]
                                    [Parameter]
                                    Parameter
                                    ReturnParam
                                    [Expression]
                                    Token
                                    TypeName
                                    PublicKeyword
                                    [a]
                                    Expression
                                    [Expression]
                                    Expression
                                    TypeName
                                    [Expression]
                                    Expression
                                    Expression
                                    Expression
                                    Expression
                                    ElseState
                                    Int
                                    TypeName
                                    ElemType
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression]
                                    [Token]
                                    [PublicKeyword]
                                    [ElseState]
                                    [[[EParameters]]]
                                    [[EParameters]]
                                    [Expression]
                                    [[Expression]]
                                    [InheritanceSpec]
                                    [Expression]
                                    [[[Parameter]]]
                                    [[Parameter]]
                                    [ReturnParam]
                                    [StorageLocation]
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression])
                            -> [Token]
                            -> HappyIdentity
                                  (HappyAbsSyn
                                    [SourceUnit]
                                    SourceUnit
                                    [Char]
                                    [Char]
                                    Token
                                    InheritanceSpec
                                    InheritanceSpecifier
                                    InheritanceSpecifier
                                    [Expression]
                                    Expression
                                    [[Expression]]
                                    [Expression]
                                    [EnumValue]
                                    EnumValue
                                    [[EParameters]]
                                    [EParameters]
                                    EParameters
                                    Token
                                    [[Parameter]]
                                    [Parameter]
                                    Parameter
                                    ReturnParam
                                    [Expression]
                                    Token
                                    TypeName
                                    PublicKeyword
                                    [a]
                                    Expression
                                    [Expression]
                                    Expression
                                    TypeName
                                    [Expression]
                                    Expression
                                    Expression
                                    Expression
                                    Expression
                                    ElseState
                                    Int
                                    TypeName
                                    ElemType
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression]
                                    [Token]
                                    [PublicKeyword]
                                    [ElseState]
                                    [[[EParameters]]]
                                    [[EParameters]]
                                    [Expression]
                                    [[Expression]]
                                    [InheritanceSpec]
                                    [Expression]
                                    [[[Parameter]]]
                                    [[Parameter]]
                                    [ReturnParam]
                                    [StorageLocation]
                                    [Expression]
                                    [ContractConts]
                                    [EParameters]
                                    [Expression]
                                    [FuncMods]
                                    [[Expression]]
                                    [EnumValue]
                                    [InheritanceSpecifier]
                                    [Parameter]
                                    [Expression])
            (bound at dist\build\solidiscan\solidiscan-tmp\Solidiscan\Parser.hs:2429:1)
      |
  2429 | happyReduce_161 = happySpecReduce_1  81# happyReduction_161
      |                                          ^^^^^^^^^^^^^^^^^^
4

0 回答 0