Intermittent commit - need to replace keys with literals in the productions, but getting there. Parses work fine. peg-mime
authorKrista Grothoff <krista@pep-project.org>
Thu, 15 Sep 2016 14:57:43 +0200
branchpeg-mime
changeset 11772d35f26558c2
parent 1176 020a639a2508
child 1178 335ac741184f
Intermittent commit - need to replace keys with literals in the productions, but getting there. Parses work fine.
mime-parser/mailmime.peg
     1.1 --- a/mime-parser/mailmime.peg	Thu Sep 15 11:21:28 2016 +0200
     1.2 +++ b/mime-parser/mailmime.peg	Thu Sep 15 14:57:43 2016 +0200
     1.3 @@ -1,20 +1,85 @@
     1.4 -Mail            <-      ( Header )+ CRLF ( Body )? EOF
     1.5 -Header          <-      HeaderKey COLON HeaderValue
     1.6 -HeaderKey       <-      ( Alpha / Digit / OrdinarySymbol )+
     1.7 -HeaderValue     <-      HeaderLine ( HeaderCont )*
     1.8 -HeaderLine      <-      Text* CRLF
     1.9 -HeaderCont      <-      Whitespace HeaderLine
    1.10 -Body            <-      PlainBody
    1.11 -PlainBody       <-      .* EOF
    1.12 -Text            <-      ( Alpha / Digit / Symbol / Space )+
    1.13 -Alpha           <-      [a-zA-Z]
    1.14 -Digit           <-      [0-9]
    1.15 -Symbol          <-      OrdinarySymbol / COLON
    1.16 -Whitespace      <-      Space+
    1.17 -Space           <-      [' ' '\t']
    1.18 -OrdinarySymbol  <-      ["!" "#" "$" "%" "&" "'" "*" "+" "\-" "/" "\" "=" "?" "^" "_" "`" "{" "|" "}" "~" "\[" "\]" "@" ";" "." "<" ">" "\"" "(" ")" "," "\\"]
    1.19 -COLON           <-      ':'
    1.20 -NEWLINE         <-      '\n'
    1.21 -CR              <-      '\r'
    1.22 -CRLF            <-      CR CR? NEWLINE 
    1.23 -EOF             <-      !.
    1.24 \ No newline at end of file
    1.25 +Mail                    <-      ( Header )+ CRLF ( Body )? EOF
    1.26 +
    1.27 +# As pretty as it would be to make the header parse elegant, 
    1.28 +# the parse semantics work better this way
    1.29 +Header                  <-      MIMEHeader / MessageHeader / GenericHeader
    1.30 +
    1.31 +MIMEHeader              <-      MIMEVersionHeader /
    1.32 +                                MIMEContentTypeHeader /
    1.33 +                                MIMEContentDispoHeader /
    1.34 +                                MIMETransfEncodeHeader
    1.35 +MIMEVersionHeader       <-      MIMEVersionKey COLON VersionString
    1.36 +MIMEContentTypeHeader   <-      MIMEContentTypeKey COLON ContentTypeString
    1.37 +MIMEContentDispoHeader  <-      MIMEContentDispoKey COLON ContentDispoString
    1.38 +MIMETransfEncodeHeader  <-      MIMETransfEncodeKey COLON TransfEncodeString
    1.39 +
    1.40 +VersionString           <-      HeaderText
    1.41 +ContentTypeString       <-      HeaderText
    1.42 +ContentDispoString      <-      HeaderText
    1.43 +TransfEncodeString      <-      HeaderText
    1.44 +
    1.45 +MessageHeader           <-      MessageIDHeader /
    1.46 +                                MessageToHeader /
    1.47 +                                MessageFromHeader /
    1.48 +                                MessageCCHeader /
    1.49 +                                MessageBCCHeader /
    1.50 +                                MessageSubjHeader /
    1.51 +                                MessageReplyToHeader /
    1.52 +                                MessageInReplyToHeader /
    1.53 +                                MessageRefsHeader                            
    1.54 +
    1.55 +MessageIDHeader         <-      MessageIDKey COLON IDString
    1.56 +MessageToHeader         <-      MessageToKey COLON ToString
    1.57 +MessageFromHeader       <-      MessageFromKey COLON FromString
    1.58 +MessageCCHeader         <-      MessageCCKey COLON CCString
    1.59 +MessageBCCHeader        <-      MessageBCCKey COLON BCCString
    1.60 +MessageSubjHeader       <-      MessageSubjKey COLON SubjString
    1.61 +MessageReplyToHeader    <-      MessageReplyToKey COLON ReplyToString
    1.62 +MessageInReplyToHeader  <-      MessageInReplyToKey COLON InReplyToString
    1.63 +MessageRefsHeader       <-      MessageRefsKey COLON RefsString
    1.64 +
    1.65 +IDString                <-      HeaderText
    1.66 +ToString                <-      HeaderText
    1.67 +FromString              <-      HeaderText
    1.68 +CCString                <-      HeaderText
    1.69 +BCCString               <-      HeaderText
    1.70 +SubjString              <-      HeaderText
    1.71 +ReplyToString           <-      HeaderText
    1.72 +InReplyToString         <-      HeaderText
    1.73 +RefsString              <-      HeaderText
    1.74 +
    1.75 +
    1.76 +MIMEVersionKey          <-      'MIME-Version'
    1.77 +MIMEContentTypeKey      <-      'Content-Type'
    1.78 +MIMEContentDispoKey     <-      'Content-Disposition'
    1.79 +MIMETransfEncodeKey     <-      'Content-Transfer-Encoding'
    1.80 +MessageIDKey            <-      'Message-ID'
    1.81 +MessageToKey            <-      'To'
    1.82 +MessageFromKey          <-      'From'
    1.83 +MessageCCKey            <-      'Cc'
    1.84 +MessageBCCKey           <-      'Bcc'
    1.85 +MessageSubjKey          <-      'Subject'
    1.86 +MessageReplyToKey       <-      'Reply-To'
    1.87 +MessageInReplyToKey     <-      'In-Reply-To'
    1.88 +MessageRefsKey          <-      'References'  
    1.89 +                            
    1.90 +GenericHeader       <-      HeaderKey COLON HeaderText
    1.91 +HeaderKey           <-      ( Alpha / Digit / OrdinarySymbol )+
    1.92 +HeaderText          <-      HeaderLine ( HeaderCont )*
    1.93 +HeaderCont          <-      Whitespace HeaderLine
    1.94 +HeaderLine          <-      Text* CRLF
    1.95 +
    1.96 +Body                <-      PlainBody
    1.97 +PlainBody           <-      .* EOF
    1.98 +Text                <-      ( Alpha / Digit / Symbol / Space )+
    1.99 +Alpha               <-      [a-zA-Z]
   1.100 +Digit               <-      [0-9]
   1.101 +Symbol              <-      OrdinarySymbol / COLON
   1.102 +Whitespace          <-      Space+
   1.103 +Space               <-      [' ' '\t']
   1.104 +OrdinarySymbol      <-      ["!" "#" "$" "%" "&" "'" "*" "+" "\-" "/" "\" "=" "?" "^" "_" "`" "{" "|" "}" "~" "\[" "\]" "@" ";" "." "<" ">" "\"" "(" ")" "," "\\"]
   1.105 +COLON               <-      ':'
   1.106 +NEWLINE             <-      '\n'
   1.107 +CR                  <-      '\r'
   1.108 +CRLF                <-      CR CR? NEWLINE 
   1.109 +EOF                 <-      !.
   1.110 \ No newline at end of file