This repository was archived by the owner on Aug 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed
Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -29,23 +29,32 @@ impl<'a> StatementParser for ParserBase<'a> {
2929 self . consume ( ) ; // 消费 ns
3030 // 解析命名空间路径
3131 let mut path = Vec :: new ( ) ;
32- let mut expect_id = true ;
33- while let Some ( tok) = self . peek ( ) {
34- if expect_id {
35- // 期望标识符
36- if tok. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' ) {
32+
33+ // 解析第一个标识符
34+ if let Some ( first_id) = self . peek ( ) {
35+ if first_id. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' ) {
36+ path. push ( self . consume ( ) . unwrap ( ) ) ;
37+ } else {
38+ return Err ( "期望命名空间标识符" . to_string ( ) ) ;
39+ }
40+ } else {
41+ return Err ( "期望命名空间标识符" . to_string ( ) ) ;
42+ }
43+
44+ // 解析后续的 :: 和标识符
45+ while self . peek ( ) == Some ( & "::" . to_string ( ) ) {
46+ self . consume ( ) ; // 消费 "::"
47+ if let Some ( next_id) = self . peek ( ) {
48+ if next_id. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' ) {
3749 path. push ( self . consume ( ) . unwrap ( ) ) ;
38- expect_id = false ;
3950 } else {
40- break ;
51+ return Err ( "期望命名空间标识符" . to_string ( ) ) ;
4152 }
42- } else if tok == "::" {
43- self . consume ( ) ;
44- expect_id = true ;
4553 } else {
46- break ;
54+ return Err ( "期望命名空间标识符" . to_string ( ) ) ;
4755 }
4856 }
57+
4958 self . expect ( ";" ) ?;
5059 return Ok ( Statement :: ImportNamespace ( crate :: ast:: NamespaceType :: Code , path) ) ;
5160 } else {
You can’t perform that action at this time.
0 commit comments