@@ -28,6 +28,22 @@ pub(crate) fn try_byte_string(it: &mut token_stream::IntoIter) -> Option<String>
28
28
} )
29
29
}
30
30
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
+
31
47
pub ( crate ) fn expect_ident ( it : & mut token_stream:: IntoIter ) -> String {
32
48
try_ident ( it) . expect ( "Expected Ident" )
33
49
}
@@ -52,8 +68,14 @@ pub(crate) fn expect_group(it: &mut token_stream::IntoIter) -> Group {
52
68
}
53
69
}
54
70
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
57
79
}
58
80
59
81
pub ( 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)
70
92
literal
71
93
}
72
94
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 {
74
96
assert_eq ! ( expect_ident( it) , expected_name) ;
75
97
assert_eq ! ( expect_punct( it) , ':' ) ;
76
- let byte_string = expect_byte_string ( it) ;
98
+ let string = expect_string ( it) ;
77
99
assert_eq ! ( expect_punct( it) , ',' ) ;
78
- byte_string
100
+ string
79
101
}
0 commit comments