hsc2hs を使用して、C ヘッダーから多数の列挙値をインポートしています。私のコード(簡略化)は次のようになります。
-- | newtype wrapper around Windows SDK SE_OBJECT_TYPE enumeration
newtype SecurityObjectType = SecurityObjectType BYTE
#{enum SecurityObjectType, SecurityObjectType
, securityObjectUnknown = SE_UNKNOWN_OBJECT_TYPE
, securityObjectFile = SE_FILE_OBJECT
}
プロジェクトで実行すると、宣言とtype のcabal haddock
空のドキュメント ブロックが作成されます。今、私はこれらのドキュメントを持っていたいと思っています。次のようなハドックスタイルのコメントを使用するだけですsecurityObjectUnknown
securityObjectFile
SecurityObjectType
-- | newtype wrapper around Windows SDK SE_OBJECT_TYPE enumeration
newtype SecurityObjectType = SecurityObjectType BYTE
#{enum SecurityObjectType, SecurityObjectType
-- | Unknown object type
, securityObjectUnknown = SE_UNKNOWN_OBJECT_TYPE
-- | Indicates a file or directory. The name string that identifies a file
-- or directory object can be in one of the following formats:
-- * A relative path, such as FileName.dat or ..\FileName
-- * An absolute path, such as FileName.dat, C:\DirectoryName\FileName.dat,
-- or G:\RemoteDirectoryName\FileName.dat.
-- * A UNC name, such as \\ComputerName\ShareName\FileName.dat.
, securityObjectFile = SE_FILE_OBJECT
}
hsc2hs に干渉し、ビルドが失敗します。しかし、私はこれらの宣言を文書化したいと考えています。どうすればそれができますか?
UPD: コメントがある場合、ビルド中に生成されるエラー メッセージは次のとおりです。
Preprocessing library Win32-security-0.1...
SecurityInfo.hsc: In function 'main':
SecurityInfo.hsc:47:5: error: lvalue required as decrement operand
SecurityInfo.hsc:47:5: error: 'Indicates' undeclared (first use in this function)
SecurityInfo.hsc:47:5: note: each undeclared identifier is reported only once for each function it appears in
SecurityInfo.hsc:47:5: error: expected ')' before 'a'
SecurityInfo.hsc:47:5: error: lvalue required as decrement operand
SecurityInfo.hsc:47:5: error: expected ')' before 'a'
SecurityInfo.hsc:47:5: error: lvalue required as decrement operand
SecurityInfo.hsc:47:5: error: expected ')' before 'a'
SecurityInfo.hsc:55:20: warning: missing terminating " character
SecurityInfo.hsc:56:24: warning: missing terminating " character
SecurityInfo.hsc:66:20: warning: missing terminating " character
SecurityInfo.hsc:67:18: warning: missing terminating " character
SecurityInfo.hsc:71:20: warning: missing terminating " character
SecurityInfo.hsc:72:2: warning: missing terminating " character
SecurityInfo.hsc:237:0: error: unterminated argument list invoking macro "hsc_enum"
SecurityInfo.hsc:53:5: error: 'hsc_enum' undeclared (first use in this function)
SecurityInfo.hsc:53:5: error: expected ';' at end of input
SecurityInfo.hsc:53:5: error: expected declaration or statement at end of input
compiling dist\build\System\Win32\Security\SecurityInfo_hsc_make.c failed (exit code 1)
単純化した例のため、実際には行番号は一致しませんが、エラー出力の 47 行目は-- | Unknown object type
行に対応しています。
生成されSecurityInfo_hsc_make.c
たファイルを掘り下げると、明らかに問題が示されます (ここにフラグメントがあります)。
#line 47 "SecurityInfo.hsc"
hsc_enum (SecurityObjectType, SecurityObjectType
-- | Unknown object type
, hsc_printf ("%s", "securityObjectUnknown "), SE_UNKNOWN_OBJECT_TYPE
-- | Indicates a file or directory. The name string that identifies a file
-- or directory object can be in one of the following formats:
-- * A relative path);
hsc_enum (SecurityObjectType, SecurityObjectType
-- | Unknown object type
, hsc_haskellize ("such as FileName.dat or ..\FileName
-- * An absolute path"), such as FileName.dat or ..\FileName
-- * An absolute path);
hsc_enum (SecurityObjectType, SecurityObjectType
-- | Unknown object type
, hsc_haskellize ("such as FileName.dat"), such as FileName.dat);
hsc_enum (SecurityObjectType, SecurityObjectType
-- | Unknown object type
Haskell コメントは、生成された C ファイルに単純に挿入されますが、これは明らかに C 構文規則に違反しています。私が望んでいたのは、これらのコメントが自動生成された.hs
ファイルに反映されるようにすることです。