所以我想用 Boomerang 解析一些 AIS 数据会很有趣,但我遇到了第一个障碍。编译错误令人费解。看到我在试图解决这个问题之前已经在 Boomerang 中解析了类似的东西。
图书馆很简单。我定义了一些基本类型及其解析器/语法:
import Control.Category (id, (.))
import Control.Monad (forever)
import Prelude hiding (id, (.))
import System.IO (hFlush, stdout)
import Text.Boomerang
import Text.Boomerang.String
import Text.Boomerang.TH
data MessageType = AIVDM | AIVDO deriving (Enum, Eq, Show)
data AIS = AIS {
msgType :: MessageType
} deriving (Eq, Show)
$(makeBoomerangs ''MessageType)
$(makeBoomerangs ''AIS)
messageTypeP :: StringBoomerang () (MessageType :- ())
messageTypeP = rAIVDM . "!AIVDM" <> rAIVDO . "!AIVDO"
aisP :: StringBoomerang () (AIS :- ())
aisP = rAIS . messageTypeP . lit ","
我现在希望支持句子计数值,它位于消息类型之后;我添加Int
到AIS
:
data AIS = AIS {
msgType :: MessageType, sCount :: Int
} deriving (Eq, Show)
并更改解析器/打印机:
aisP :: StringBoomerang () (AIS :- ())
aisP = rAIS . messageTypeP . lit "," . int
但它无法编译:
• Couldn't match type ‘()’ with ‘Int :- ()’
Expected type: Boomerang
StringError String () (MessageType :- (Int :- ()))
Actual type: Boomerang StringError String () (MessageType :- ())
• In the second argument of ‘(.)’, namely
‘messageTypeP . lit "," . int’
In the expression: rAIS . messageTypeP . lit "," . int
In an equation for ‘aisP’:
aisP = rAIS . messageTypeP . lit "," . int
哎哟。请帮忙?