@@ -6,6 +6,10 @@ use crate::{parsed::Signature, Time};
6
6
use bstr:: { BStr , ByteSlice } ;
7
7
use btoi:: btoi;
8
8
use hex:: FromHex ;
9
+ use nom:: { bytes:: complete:: tag, IResult , } ;
10
+ use nom:: sequence:: { tuple, preceded, terminated} ;
11
+ use nom:: bytes:: complete:: { take, take_while, take_while_m_n} ;
12
+ use nom:: combinator:: map;
9
13
10
14
#[ derive( PartialEq , Eq , Debug , Hash ) ]
11
15
pub struct Tag < ' data > {
@@ -71,6 +75,29 @@ fn parse_signature(d: &[u8]) -> Result<Signature, Error> {
71
75
} )
72
76
}
73
77
78
+ fn context ( msg : & ' static str ) -> impl Fn ( nom:: Err < Error > ) -> nom:: Err < Error > {
79
+ move |e : nom:: Err < Error > | e. map ( |e| e. parse_context ( msg) )
80
+ }
81
+
82
+ fn is_hex_digit_lc ( b : u8 ) -> bool {
83
+ match b {
84
+ b'0' ..=b'9' => true ,
85
+ b'a' ..=b'f' => true ,
86
+ _ => false ,
87
+ }
88
+ }
89
+
90
+ pub ( crate ) fn parse_tag_nom ( i : & [ u8 ] ) -> IResult < & [ u8 ] , Tag , Error > {
91
+ const NL : & [ u8 ] = b"\n " ;
92
+ let ( i, _) = terminated ( preceded ( tag ( b"object " ) , take_while_m_n ( 40usize , 40 , is_hex_digit_lc) ) , tag ( NL ) ) ( i) . map_err ( context ( "object <40 lowercase hex char>" ) ) ?;
93
+ unimplemented ! ( "parse message nom" )
94
+ }
95
+
96
+ pub ( crate ) fn parse_message_nom ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( Option < & BStr > , Option < & BStr > ) , Error > {
97
+ let ( i, _) = tag ( b"\n " ) ( i) ?;
98
+ unimplemented ! ( "parse message nom" )
99
+ }
100
+
74
101
fn parse_message < ' data > (
75
102
d : & ' data [ u8 ] ,
76
103
mut lines : impl Iterator < Item = & ' data [ u8 ] > ,
0 commit comments