@@ -41,48 +41,6 @@ pub use crate::{
41
41
syntax_kind:: SyntaxKind ,
42
42
} ;
43
43
44
- /// Parse a prefix of the input as a given syntactic construct.
45
- ///
46
- /// This is used by macro-by-example parser to implement things like `$i:item`
47
- /// and the naming of variants follows the naming of macro fragments.
48
- ///
49
- /// Note that this is generally non-optional -- the result is intentionally not
50
- /// `Option<Output>`. The way MBE work, by the time we *try* to parse `$e:expr`
51
- /// we already commit to expression. In other words, this API by design can't be
52
- /// used to implement "rollback and try another alternative" logic.
53
- #[ derive( Debug ) ]
54
- pub enum PrefixEntryPoint {
55
- Vis ,
56
- Block ,
57
- Stmt ,
58
- Pat ,
59
- Ty ,
60
- Expr ,
61
- Path ,
62
- Item ,
63
- MetaItem ,
64
- }
65
-
66
- impl PrefixEntryPoint {
67
- pub fn parse ( & self , input : & Input ) -> Output {
68
- let entry_point: fn ( & ' _ mut parser:: Parser ) = match self {
69
- PrefixEntryPoint :: Vis => grammar:: entry:: prefix:: vis,
70
- PrefixEntryPoint :: Block => grammar:: entry:: prefix:: block,
71
- PrefixEntryPoint :: Stmt => grammar:: entry:: prefix:: stmt,
72
- PrefixEntryPoint :: Pat => grammar:: entry:: prefix:: pat,
73
- PrefixEntryPoint :: Ty => grammar:: entry:: prefix:: ty,
74
- PrefixEntryPoint :: Expr => grammar:: entry:: prefix:: expr,
75
- PrefixEntryPoint :: Path => grammar:: entry:: prefix:: path,
76
- PrefixEntryPoint :: Item => grammar:: entry:: prefix:: item,
77
- PrefixEntryPoint :: MetaItem => grammar:: entry:: prefix:: meta_item,
78
- } ;
79
- let mut p = parser:: Parser :: new ( input) ;
80
- entry_point ( & mut p) ;
81
- let events = p. finish ( ) ;
82
- event:: process ( events)
83
- }
84
- }
85
-
86
44
/// Parse the whole of the input as a given syntactic construct.
87
45
///
88
46
/// This covers two main use-cases:
@@ -152,6 +110,48 @@ impl TopEntryPoint {
152
110
}
153
111
}
154
112
113
+ /// Parse a prefix of the input as a given syntactic construct.
114
+ ///
115
+ /// This is used by macro-by-example parser to implement things like `$i:item`
116
+ /// and the naming of variants follows the naming of macro fragments.
117
+ ///
118
+ /// Note that this is generally non-optional -- the result is intentionally not
119
+ /// `Option<Output>`. The way MBE work, by the time we *try* to parse `$e:expr`
120
+ /// we already commit to expression. In other words, this API by design can't be
121
+ /// used to implement "rollback and try another alternative" logic.
122
+ #[ derive( Debug ) ]
123
+ pub enum PrefixEntryPoint {
124
+ Vis ,
125
+ Block ,
126
+ Stmt ,
127
+ Pat ,
128
+ Ty ,
129
+ Expr ,
130
+ Path ,
131
+ Item ,
132
+ MetaItem ,
133
+ }
134
+
135
+ impl PrefixEntryPoint {
136
+ pub fn parse ( & self , input : & Input ) -> Output {
137
+ let entry_point: fn ( & ' _ mut parser:: Parser ) = match self {
138
+ PrefixEntryPoint :: Vis => grammar:: entry:: prefix:: vis,
139
+ PrefixEntryPoint :: Block => grammar:: entry:: prefix:: block,
140
+ PrefixEntryPoint :: Stmt => grammar:: entry:: prefix:: stmt,
141
+ PrefixEntryPoint :: Pat => grammar:: entry:: prefix:: pat,
142
+ PrefixEntryPoint :: Ty => grammar:: entry:: prefix:: ty,
143
+ PrefixEntryPoint :: Expr => grammar:: entry:: prefix:: expr,
144
+ PrefixEntryPoint :: Path => grammar:: entry:: prefix:: path,
145
+ PrefixEntryPoint :: Item => grammar:: entry:: prefix:: item,
146
+ PrefixEntryPoint :: MetaItem => grammar:: entry:: prefix:: meta_item,
147
+ } ;
148
+ let mut p = parser:: Parser :: new ( input) ;
149
+ entry_point ( & mut p) ;
150
+ let events = p. finish ( ) ;
151
+ event:: process ( events)
152
+ }
153
+ }
154
+
155
155
/// A parsing function for a specific braced-block.
156
156
pub struct Reparser ( fn ( & mut parser:: Parser ) ) ;
157
157
0 commit comments