@@ -28,6 +28,22 @@ pub(crate) fn try_byte_string(it: &mut token_stream::IntoIter) -> Option<String>
2828 } )
2929}
3030
31+ pub ( crate ) fn try_string ( it : & mut token_stream:: IntoIter ) -> Option < String > {
32+ try_literal ( it) . and_then ( |string| {
33+ if string. starts_with ( '\"' ) && string. ends_with ( '\"' ) {
34+ let content = & string[ 1 ..string. len ( ) - 1 ] ;
35+ if content. contains ( '\\' ) {
36+ panic ! ( "Escape sequences in string literals not yet handled" ) ;
37+ }
38+ Some ( content. to_string ( ) )
39+ } else if string. starts_with ( "r\" " ) {
40+ panic ! ( "Raw string literals are not yet handled" ) ;
41+ } else {
42+ None
43+ }
44+ } )
45+ }
46+
3147pub ( crate ) fn expect_ident ( it : & mut token_stream:: IntoIter ) -> String {
3248 try_ident ( it) . expect ( "Expected Ident" )
3349}
@@ -52,8 +68,14 @@ pub(crate) fn expect_group(it: &mut token_stream::IntoIter) -> Group {
5268 }
5369}
5470
55- pub ( crate ) fn expect_byte_string ( it : & mut token_stream:: IntoIter ) -> String {
56- try_byte_string ( it) . expect ( "Expected byte string" )
71+ pub ( crate ) fn expect_string ( it : & mut token_stream:: IntoIter ) -> String {
72+ try_string ( it) . expect ( "Expected string" )
73+ }
74+
75+ pub ( crate ) fn expect_string_ascii ( it : & mut token_stream:: IntoIter ) -> String {
76+ let string = try_string ( it) . expect ( "Expected string" ) ;
77+ assert ! ( string. is_ascii( ) , "Expected ASCII string" ) ;
78+ string
5779}
5880
5981pub ( crate ) fn expect_end ( it : & mut token_stream:: IntoIter ) {
@@ -70,10 +92,10 @@ pub(crate) fn get_literal(it: &mut token_stream::IntoIter, expected_name: &str)
7092 literal
7193}
7294
73- pub ( crate ) fn get_byte_string ( it : & mut token_stream:: IntoIter , expected_name : & str ) -> String {
95+ pub ( crate ) fn get_string ( it : & mut token_stream:: IntoIter , expected_name : & str ) -> String {
7496 assert_eq ! ( expect_ident( it) , expected_name) ;
7597 assert_eq ! ( expect_punct( it) , ':' ) ;
76- let byte_string = expect_byte_string ( it) ;
98+ let string = expect_string ( it) ;
7799 assert_eq ! ( expect_punct( it) , ',' ) ;
78- byte_string
100+ string
79101}
0 commit comments