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 +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,36 @@ pub trait StatementParser {
2020impl < ' a > StatementParser for ParserBase < ' a > {
2121 fn parse_statement ( & mut self ) -> Result < Statement , String > {
2222 if let Some ( token) = self . peek ( ) {
23+ // 支持 using ns xxx; 语句
24+ if token == "using" {
25+ self . consume ( ) ; // 消费 using
26+ if self . peek ( ) == Some ( & "ns" . to_string ( ) ) {
27+ self . consume ( ) ; // 消费 ns
28+ // 解析命名空间路径
29+ let mut path = Vec :: new ( ) ;
30+ let mut expect_id = true ;
31+ while let Some ( tok) = self . peek ( ) {
32+ if expect_id {
33+ // 期望标识符
34+ if tok. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' ) {
35+ path. push ( self . consume ( ) . unwrap ( ) ) ;
36+ expect_id = false ;
37+ } else {
38+ break ;
39+ }
40+ } else if tok == "::" {
41+ self . consume ( ) ;
42+ expect_id = true ;
43+ } else {
44+ break ;
45+ }
46+ }
47+ self . expect ( ";" ) ?;
48+ return Ok ( Statement :: ImportNamespace ( crate :: ast:: NamespaceType :: Code , path) ) ;
49+ } else {
50+ return Err ( "不支持的using语句,仅支持using ns" . to_string ( ) ) ;
51+ }
52+ }
2353 match token. as_str ( ) {
2454 "return" => {
2555 self . consume ( ) ; // 消费 "return" 关键字
You can’t perform that action at this time.
0 commit comments