Skip to content

Commit c72908a

Browse files
committed
more intuitive order
1 parent d846afd commit c72908a

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

crates/parser/src/lib.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,48 +41,6 @@ pub use crate::{
4141
syntax_kind::SyntaxKind,
4242
};
4343

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-
8644
/// Parse the whole of the input as a given syntactic construct.
8745
///
8846
/// This covers two main use-cases:
@@ -152,6 +110,48 @@ impl TopEntryPoint {
152110
}
153111
}
154112

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+
155155
/// A parsing function for a specific braced-block.
156156
pub struct Reparser(fn(&mut parser::Parser));
157157

crates/parser/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod sourcegen_inline_tests;
2-
mod prefix_entries;
32
mod top_entries;
3+
mod prefix_entries;
44

55
use std::{
66
fmt::Write,

0 commit comments

Comments
 (0)