This looks like a bug in Alex 3.0.1. It works fine in version 2.3.3 after dealing with some other unrelated issues in your code1. The problem is this line in the generated code:
ignorePendingBytes (p,c,ps,s) = (p,c,s)
通过跟踪生成代码中的类型,该函数似乎应该具有以下类型AlexInput -> AlexInput
, but AlexInput
显然不能同时是 3 元组和 4 元组。
这可能发生是因为定义AlexInput
两个版本之间发生了变化。
type AlexInput = (AlexPosn, Char, String) -- v2.3.3
type AlexInput = (AlexPosn, Char, [Byte], String) -- v3.0.1
据我所知,正确的代码应该是
ignorePendingBytes (p,c,ps,s) = (p,c,[],s)
并在生成的代码中手动进行此更改,使其在处理其他问题后进行编译。
但是,除非您需要 3.0.1 中的某些内容,否则我建议降级直到该问题得到解决,因为必须针对生成的代码维护补丁通常会带来麻烦而不值得。
1 Your code is missing a Show
instance for Lexeme
and you're also calling return
on alexMonadScan
, which is already in the Alex
monad.