@@ -7,83 +7,98 @@ use chumsky::text::{Char, Padded};
7
7
8
8
#[ derive( Eq , PartialEq , Debug , Clone ) ]
9
9
pub enum Expr < ' src > {
10
- Use ( UseExpr < ' src > ) ,
10
+ Use ( ExprUse < ' src > ) ,
11
11
Other ( & ' src str ) ,
12
12
}
13
13
14
14
#[ derive( Eq , PartialEq , Debug , Clone ) ]
15
- pub enum UseExpr < ' src > {
15
+ pub enum ExprUse < ' src > {
16
16
Item {
17
17
module : & ' src str ,
18
18
rename : Option < & ' src str > ,
19
- nested : Option < Box < UseExpr < ' src > > > ,
19
+ nested : Option < Box < ExprUse < ' src > > > ,
20
20
} ,
21
- Many ( Vec < UseExpr < ' src > > ) ,
21
+ Many ( Vec < ExprUse < ' src > > ) ,
22
22
Glob ,
23
23
}
24
24
25
- pub fn parser < ' src > ( ) -> impl Parser <
25
+ pub fn expr < ' src > ( ) -> impl Parser <
26
26
' src ,
27
27
& ' src str ,
28
28
Vec < Expr < ' src > > ,
29
29
extra:: Err < Rich < ' src , char > > ,
30
30
> {
31
- let use_expr = || {
32
- lexeme ( "use" )
33
- . ignore_then ( use_parser ( ) )
34
- . then_ignore ( lexeme ( ";" ) . or_not ( ) )
35
- . map ( Expr :: Use )
36
- } ;
37
-
38
- let other = use_expr ( )
39
- . not ( )
40
- . ignore_then ( any ( ) )
31
+ expr_use ( )
32
+ . or ( expr_other ( ) )
41
33
. repeated ( )
42
- . at_least ( 1 )
43
- . to_slice ( )
44
- . map ( Expr :: Other ) ;
34
+ . collect :: < Vec < _ > > ( )
35
+ }
45
36
46
- use_expr ( ) . or ( other) . repeated ( ) . collect :: < Vec < _ > > ( )
37
+ fn expr_use < ' src > ( ) -> impl Parser <
38
+ ' src ,
39
+ & ' src str ,
40
+ Expr < ' src > ,
41
+ extra:: Err < Rich < ' src , char > > ,
42
+ > {
43
+ lexeme ( "use" )
44
+ . ignore_then ( expr_use_rec ( ) )
45
+ . then_ignore ( lexeme ( ";" ) . or_not ( ) )
46
+ . map ( Expr :: Use )
47
47
}
48
48
49
- fn use_parser < ' src > ( ) -> impl Parser <
49
+ fn expr_use_rec < ' src > ( ) -> impl Parser <
50
50
' src ,
51
51
& ' src str ,
52
- UseExpr < ' src > ,
52
+ ExprUse < ' src > ,
53
53
extra:: Err < Rich < ' src , char > > ,
54
54
> {
55
- recursive ( |use_parser | {
55
+ recursive ( |expr_use | {
56
56
let ident = || text:: ascii:: ident ( ) . padded ( ) ;
57
57
let item = ident ( )
58
58
. then (
59
59
lexeme ( "as" ) . ignore_then ( ident ( ) ) . or_not ( ) ,
60
60
)
61
61
. then (
62
62
lexeme ( "::" )
63
- . ignore_then ( use_parser . clone ( ) )
63
+ . ignore_then ( expr_use . clone ( ) )
64
64
. or_not ( ) ,
65
65
)
66
66
. map ( |( ( module, rename) , nested) | {
67
- UseExpr :: Item {
67
+ ExprUse :: Item {
68
68
module,
69
69
rename,
70
70
nested : nested. map ( Box :: new) ,
71
71
}
72
72
} ) ;
73
73
74
- let many = use_parser
74
+ let many = expr_use
75
75
. separated_by ( lexeme ( ',' ) )
76
76
. allow_trailing ( )
77
77
. collect :: < Vec < _ > > ( )
78
78
. delimited_by ( lexeme ( '{' ) , lexeme ( '}' ) )
79
- . map ( UseExpr :: Many ) ;
79
+ . map ( ExprUse :: Many ) ;
80
80
81
- let glob = lexeme ( "*" ) . map ( |_| UseExpr :: Glob ) ;
81
+ let glob = lexeme ( "*" ) . map ( |_| ExprUse :: Glob ) ;
82
82
83
83
item. or ( many) . or ( glob)
84
84
} )
85
85
}
86
86
87
+ fn expr_other < ' src > ( ) -> impl Parser <
88
+ ' src ,
89
+ & ' src str ,
90
+ Expr < ' src > ,
91
+ extra:: Err < Rich < ' src , char > > ,
92
+ > {
93
+ expr_use ( )
94
+ . not ( )
95
+ . ignore_then ( any ( ) )
96
+ . repeated ( )
97
+ . at_least ( 1 )
98
+ . to_slice ( )
99
+ . map ( Expr :: Other )
100
+ }
101
+
87
102
fn lexeme < ' src , T , I , E > ( seq : T ) -> Padded < Just < T , I , E > >
88
103
where
89
104
I : Input < ' src > ,
0 commit comments