@@ -27,24 +27,20 @@ use crate::lazy::text::matched::{
2727use crate :: lazy:: text:: parse_result:: { fatal_parse_error, InvalidInputError , IonParseError } ;
2828use crate :: lazy:: text:: parse_result:: { IonMatchResult , IonParseResult } ;
2929use crate :: lazy:: text:: raw:: v1_1:: arg_group:: { EExpArg , EExpArgExpr , TextEExpArgGroup } ;
30- use crate :: lazy:: text:: raw:: v1_1:: reader:: {
31- MacroIdRef ,
32- SystemMacroAddress , TextEExpression_1_1
33- } ;
30+ use crate :: lazy:: text:: raw:: v1_1:: reader:: { MacroIdRef , SystemMacroAddress , TextEExpression_1_1 } ;
3431use crate :: lazy:: text:: value:: {
3532 LazyRawTextValue , LazyRawTextValue_1_0 , LazyRawTextValue_1_1 , LazyRawTextVersionMarker ,
3633} ;
3734use crate :: result:: DecodingError ;
38- use crate :: {
39- Encoding , HasRange , IonError , IonResult , IonType , RawSymbolRef , TimestampPrecision ,
40- } ;
35+ use crate :: { Encoding , HasRange , IonError , IonResult , IonType , RawSymbolRef , TimestampPrecision } ;
4136
4237use crate :: lazy:: expanded:: macro_table:: { Macro , ION_1_1_SYSTEM_MACROS } ;
4338use crate :: lazy:: expanded:: template:: { Parameter , RestSyntaxPolicy } ;
4439use crate :: lazy:: text:: as_utf8:: AsUtf8 ;
40+ use crate :: lazy:: text:: raw:: sequence:: RawTextSExpIterator ;
41+ use crate :: lazy:: text:: token_kind:: { ValueTokenKind , TEXT_ION_TOKEN_KINDS } ;
4542use bumpalo:: collections:: Vec as BumpVec ;
4643use winnow:: ascii:: { digit0, digit1} ;
47- use crate :: lazy:: text:: raw:: sequence:: RawTextSExpIterator ;
4844
4945/// Generates parser functions that map from an Ion type representation (`Decimal`, `Int`, etc)
5046/// to an `EncodedTextValue`.
@@ -402,7 +398,10 @@ impl<'top> TextBuffer<'top> {
402398 // int `3` while recognizing the input `-3` as the int `-3`. If `match_operator` runs before
403399 // `match_value`, it will consume the sign (`-`) of negative number values, treating
404400 // `-3` as an operator (`-`) and an int (`3`). Thus, we run `match_value` first.
405- whitespace_and_then ( alt ( ( Self :: match_value :: < TextEncoding_1_1 > , Self :: match_operator) ) ) ,
401+ whitespace_and_then ( alt ( (
402+ Self :: match_value :: < TextEncoding_1_1 > ,
403+ Self :: match_operator,
404+ ) ) ) ,
406405 )
407406 . map ( |( maybe_annotations, value) | input. apply_annotations ( maybe_annotations, value) )
408407 . map ( RawValueExpr :: ValueLiteral )
@@ -446,7 +445,9 @@ impl<'top> TextBuffer<'top> {
446445 }
447446
448447 /// Matches an optional annotation sequence and a trailing value.
449- pub fn match_annotated_value < E : TextEncoding < ' top > > ( & mut self ) -> IonParseResult < ' top , E :: Value < ' top > > {
448+ pub fn match_annotated_value < E : TextEncoding < ' top > > (
449+ & mut self ,
450+ ) -> IonParseResult < ' top , E :: Value < ' top > > {
450451 let input = * self ;
451452 (
452453 opt ( Self :: match_annotations) ,
@@ -524,49 +525,34 @@ impl<'top> TextBuffer<'top> {
524525
525526 /// Matches a single Ion 1.0 value.
526527 pub fn match_value < E : TextEncoding < ' top > > ( & mut self ) -> IonParseResult < ' top , E :: Value < ' top > > {
528+ use ValueTokenKind :: * ;
527529 dispatch ! {
528- |input: & mut TextBuffer <' top>| input. peek_byte( ) ;
529- byte if byte. is_ascii_digit( ) || byte == b'-' => {
530- alt( (
531- Self :: match_int_value,
532- Self :: match_float_value,
533- Self :: match_decimal_value,
534- Self :: match_timestamp_value,
535- ) )
536- } ,
537- byte if byte. is_ascii_alphabetic( ) => {
538- alt( (
539- Self :: match_null_value,
540- Self :: match_bool_value,
541- Self :: match_identifier_value,
542- Self :: match_float_special_value, // nan
543- ) )
544- } ,
545- b'$' | b'_' => {
546- Self :: match_symbol_value // identifiers and symbol IDs
547- } ,
548- b'"' | b'\'' => {
549- alt( (
550- Self :: match_string_value,
551- Self :: match_symbol_value,
552- ) )
553- } ,
554- b'[' => E :: list_matcher( ) ,
555- b'(' => E :: sexp_matcher( ) ,
556- b'{' => {
557- alt( (
558- Self :: match_blob_value,
559- Self :: match_clob_value,
560- E :: struct_matcher( ) ,
561- ) )
562- } ,
563- b'+' => Self :: match_float_special_value, // +inf
564- _other => {
565- // `other` is not a legal start-of-value byte.
566- |input: & mut TextBuffer <' top>| {
567- let error = InvalidInputError :: new( * input) ;
568- Err ( ErrMode :: Backtrack ( IonParseError :: Invalid ( error) ) )
569- }
530+ |input: & mut TextBuffer <' top>| Ok ( TEXT_ION_TOKEN_KINDS [ input. peek_byte( ) ? as usize ] ) ;
531+ NumberOrTimestamp => alt( (
532+ Self :: match_int_value,
533+ Self :: match_float_value,
534+ Self :: match_decimal_value,
535+ Self :: match_timestamp_value,
536+ ) ) ,
537+ Letter => alt( (
538+ Self :: match_null_value,
539+ Self :: match_bool_value,
540+ Self :: match_identifier_value,
541+ Self :: match_float_special_value, // nan
542+ ) ) ,
543+ Symbol => Self :: match_symbol_value,
544+ QuotedText => alt( ( Self :: match_string_value, Self :: match_symbol_value) ) ,
545+ List => E :: list_matcher( ) ,
546+ SExp => E :: sexp_matcher( ) ,
547+ LobOrStruct => alt( (
548+ Self :: match_blob_value,
549+ Self :: match_clob_value,
550+ E :: struct_matcher( ) ,
551+ ) ) ,
552+ Invalid ( byte) => |input: & mut TextBuffer <' top>| {
553+ let error = InvalidInputError :: new( * input)
554+ . with_label( format!( "a value cannot begin with '{}'" , char :: from( byte) ) ) ;
555+ Err ( ErrMode :: Backtrack ( IonParseError :: Invalid ( error) ) )
570556 } ,
571557 }
572558 . with_taken ( )
@@ -598,16 +584,15 @@ impl<'top> TextBuffer<'top> {
598584 & mut self ,
599585 parameter : & ' top Parameter ,
600586 ) -> IonParseResult < ' top , TextEExpArgGroup < ' top > > {
601-
602587 TextEncoding_1_1 :: container_matcher (
603588 "an explicit argument group" ,
604589 "(::" ,
605590 RawTextSExpIterator :: < TextEncoding_1_1 > :: new,
606- whitespace_and_then ( ")" )
591+ whitespace_and_then ( ")" ) ,
607592 )
608- . with_taken ( )
609- . map ( |( expr_cache, input) | TextEExpArgGroup :: new ( parameter, input, expr_cache) )
610- . parse_next ( self )
593+ . with_taken ( )
594+ . map ( |( expr_cache, input) | TextEExpArgGroup :: new ( parameter, input, expr_cache) )
595+ . parse_next ( self )
611596 }
612597
613598 pub fn match_e_expression_name ( & mut self ) -> IonParseResult < ' top , MacroIdRef < ' top > > {
@@ -819,8 +804,6 @@ impl<'top> TextBuffer<'top> {
819804 }
820805 }
821806
822-
823-
824807 pub fn match_empty_arg_group (
825808 & mut self ,
826809 parameter : & ' top Parameter ,
@@ -1127,10 +1110,7 @@ impl<'top> TextBuffer<'top> {
11271110 /// Matches an Ion float of any syntax
11281111 fn match_float ( & mut self ) -> IonParseResult < ' top , MatchedFloat > {
11291112 terminated (
1130- alt ( (
1131- Self :: match_float_special,
1132- Self :: match_float_numeric_value,
1133- ) ) ,
1113+ alt ( ( Self :: match_float_special, Self :: match_float_numeric_value) ) ,
11341114 Self :: peek_stop_character,
11351115 )
11361116 . parse_next ( self )
0 commit comments