@@ -235,6 +235,10 @@ fn is_format_size_char(
235235 * byte_size = 8 ;
236236 true
237237 }
238+ ( FormatTypeCategory :: Float , Some ( 'H' | 'B' ) ) => {
239+ * byte_size = 2 ;
240+ true
241+ }
238242 // FormatTypeCategory::Float, 'L' => *byte_size = 16, // TODO support f128
239243 _ => false ,
240244 }
@@ -290,7 +294,45 @@ fn parse_type_string(params: &str) -> Result<Vec<ParsedFormatterItemInfo>, Strin
290294
291295 let mut byte_size = 0u8 ;
292296 let mut show_ascii_dump = false ;
293- if is_format_size_char ( ch, type_cat, & mut byte_size) {
297+ let mut float_variant = None ;
298+ if type_cat == FormatTypeCategory :: Float {
299+ match ch {
300+ Some ( var @ ( 'B' | 'H' ) ) => {
301+ byte_size = 2 ;
302+ float_variant = Some ( var) ;
303+ ch = chars. next ( ) ;
304+ }
305+ Some ( 'F' ) => {
306+ byte_size = 4 ;
307+ ch = chars. next ( ) ;
308+ }
309+ Some ( 'D' ) => {
310+ byte_size = 8 ;
311+ ch = chars. next ( ) ;
312+ }
313+ _ => {
314+ if is_format_size_char ( ch, type_cat, & mut byte_size) {
315+ ch = chars. next ( ) ;
316+ } else {
317+ let mut decimal_size = String :: new ( ) ;
318+ while is_format_size_decimal ( ch, type_cat, & mut decimal_size) {
319+ ch = chars. next ( ) ;
320+ }
321+ if !decimal_size. is_empty ( ) {
322+ byte_size = decimal_size. parse ( ) . map_err ( |_| {
323+ get_message_with_args (
324+ "od-error-invalid-number" ,
325+ HashMap :: from ( [
326+ ( "number" . to_string ( ) , decimal_size. quote ( ) . to_string ( ) ) ,
327+ ( "spec" . to_string ( ) , params. quote ( ) . to_string ( ) ) ,
328+ ] ) ,
329+ )
330+ } ) ?;
331+ }
332+ }
333+ }
334+ }
335+ } else if is_format_size_char ( ch, type_cat, & mut byte_size) {
294336 ch = chars. next ( ) ;
295337 } else {
296338 let mut decimal_size = String :: new ( ) ;
@@ -313,15 +355,23 @@ fn parse_type_string(params: &str) -> Result<Vec<ParsedFormatterItemInfo>, Strin
313355 ch = chars. next ( ) ;
314356 }
315357
316- let ft = od_format_type ( type_char, byte_size) . ok_or_else ( || {
317- get_message_with_args (
318- "od-error-invalid-size" ,
319- HashMap :: from ( [
320- ( "size" . to_string ( ) , byte_size. to_string ( ) ) ,
321- ( "spec" . to_string ( ) , params. quote ( ) . to_string ( ) ) ,
322- ] ) ,
323- )
324- } ) ?;
358+ let ft = if let Some ( v) = float_variant {
359+ match v {
360+ 'B' => FORMAT_ITEM_BF16 ,
361+ 'H' => FORMAT_ITEM_F16 ,
362+ _ => unreachable ! ( ) ,
363+ }
364+ } else {
365+ od_format_type ( type_char, byte_size) . ok_or_else ( || {
366+ get_message_with_args (
367+ "od-error-invalid-size" ,
368+ HashMap :: from ( [
369+ ( "size" . to_string ( ) , byte_size. to_string ( ) ) ,
370+ ( "spec" . to_string ( ) , params. quote ( ) . to_string ( ) ) ,
371+ ] ) ,
372+ )
373+ } ) ?
374+ } ;
325375 formats. push ( ParsedFormatterItemInfo :: new ( ft, show_ascii_dump) ) ;
326376 }
327377
0 commit comments