1
我想解析RFC 2822使用fparsec,但我無法處理與多行的標題:(它與下一個標題混淆): 這裏是我最好的嘗試:做你有任何提示?fparsec rfc2822解析多個標題行
let str (s:string) = pstring s
let stringLiteral =
manySatisfy (fun c -> c <> ':' && c <> '\r' && c <> '\n')
let ws = many (pchar ' ')
let keyValueSimple = stringLiteral .>>. (ws >>. str ":" >>. ws >>. stringLiteral) .>>. pchar '\n' |>> (fun (a,b) -> a)
let lineValue = ws >>. stringLiteral .>>. (pchar '\n' .>>. (pchar '\t')) |>> (fun (a,b) -> a)
let lastValue = ws >>. stringLiteral .>>. (pchar '\n' .>> notFollowedBy (pchar '\t')) |>> (fun (a,b) -> a)
let keyValueComplex = stringLiteral .>>. (ws >>. pchar ':') .>>. (many lineValue) .>>. lastValue |>> (fun (((f),d),b) -> (f,f))
let headers = many1 (keyValueComplex)
let parse (fileName:string) =
test headers "Return-Path: <[email protected]>\n\twerwe\nDelivered-To: [email protected]\n "
我得到期待\ t在3,1:投遞至:[email protected]