Skip to content

Commit 454e481

Browse files
UrhengulasVeykril
authored andcommitted
Add edition to all parse functions of the parser crate
1 parent 392538c commit 454e481

9 files changed

Lines changed: 16 additions & 20 deletions

File tree

‎crates/mbe/src/syntax_bridge.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ where
131131
_ => TokenBuffer::from_subtree(tt),
132132
};
133133
let parser_input = to_parser_input(&buffer);
134-
let parser_output = entry_point.parse(&parser_input);
134+
let parser_output = entry_point.parse(&parser_input, parser::Edition::Edition2021);
135135
letmut tree_sink = TtTreeSink::new(buffer.begin());
136136
for event in parser_output.iter(){
137137
match event {

‎crates/mbe/src/tt_iter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a, S: Copy + fmt::Debug> TtIter<'a, S> {
143143
) -> ExpandResult<Option<tt::TokenTree<S>>>{
144144
let buffer = tt::buffer::TokenBuffer::from_tokens(self.inner.as_slice());
145145
let parser_input = to_parser_input(&buffer);
146-
let tree_traversal = entry_point.parse(&parser_input);
146+
let tree_traversal = entry_point.parse(&parser_input, parser::Edition::Edition2021);
147147
letmut cursor = buffer.begin();
148148
letmut error = false;
149149
for step in tree_traversal.iter(){

‎crates/parser/src/lib.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub enum TopEntryPoint {
8787
}
8888

8989
implTopEntryPoint{
90-
pubfnparse(&self,input:&Input) -> Output{
90+
pubfnparse(&self,input:&Input,edition:Edition) -> Output{
9191
let _p = tracing::span!(tracing::Level::INFO,"TopEntryPoint::parse", ?self).entered();
9292
let entry_point:fn(&'_mut parser::Parser<'_>) = matchself{
9393
TopEntryPoint::SourceFile => grammar::entry::top::source_file,
@@ -99,7 +99,7 @@ impl TopEntryPoint {
9999
TopEntryPoint::MetaItem => grammar::entry::top::meta_item,
100100
TopEntryPoint::MacroEagerInput => grammar::entry::top::eager_macro_input,
101101
};
102-
letmut p = parser::Parser::new(input,Edition::Edition2021);
102+
letmut p = parser::Parser::new(input,edition);
103103
entry_point(&mut p);
104104
let events = p.finish();
105105
let res = event::process(events);
@@ -151,7 +151,7 @@ pub enum PrefixEntryPoint {
151151
}
152152

153153
implPrefixEntryPoint{
154-
pubfnparse(&self,input:&Input) -> Output{
154+
pubfnparse(&self,input:&Input,edition:Edition) -> Output{
155155
let entry_point:fn(&'_mut parser::Parser<'_>) = matchself{
156156
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
157157
PrefixEntryPoint::Block => grammar::entry::prefix::block,
@@ -164,7 +164,7 @@ impl PrefixEntryPoint {
164164
PrefixEntryPoint::Item => grammar::entry::prefix::item,
165165
PrefixEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
166166
};
167-
letmut p = parser::Parser::new(input,Edition::Edition2021);
167+
letmut p = parser::Parser::new(input,edition);
168168
entry_point(&mut p);
169169
let events = p.finish();
170170
event::process(events)
@@ -188,9 +188,9 @@ impl Reparser {
188188
///
189189
/// Tokens must start with `{`, end with `}` and form a valid brace
190190
/// sequence.
191-
pubfnparse(self,tokens:&Input) -> Output{
191+
pubfnparse(self,tokens:&Input,edition:Edition) -> Output{
192192
letReparser(r) = self;
193-
letmut p = parser::Parser::new(tokens,Edition::Edition2021);
193+
letmut p = parser::Parser::new(tokens,edition);
194194
r(&mut p);
195195
let events = p.finish();
196196
event::process(events)

‎crates/parser/src/parser.rs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
4040

4141
impl<'t>Parser<'t>{
4242
pub(super)fnnew(inp:&'tInput,edition:Edition) -> Parser<'t>{
43-
Parser{
44-
inp,
45-
pos:0,
46-
events:Vec::new(),
47-
steps:Cell::new(0),
48-
edition,
49-
}
43+
Parser{ inp,pos:0,events:Vec::new(),steps:Cell::new(0), edition }
5044
}
5145

5246
pub(crate)fnfinish(self) -> Vec<Event>{

‎crates/parser/src/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn parse_inline_err() {
8888
fnparse(entry:TopEntryPoint,text:&str) -> (String,bool){
8989
let lexed = LexedStr::new(text);
9090
let input = lexed.to_input();
91-
let output = entry.parse(&input);
91+
let output = entry.parse(&input,crate::Edition::Edition2021);
9292

9393
letmut buf = String::new();
9494
letmut errors = Vec::new();

‎crates/parser/src/tests/prefix_entries.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn check(entry: PrefixEntryPoint, input: &str, prefix: &str) {
8686
let input = lexed.to_input();
8787

8888
letmut n_tokens = 0;
89-
for step in entry.parse(&input).iter(){
89+
for step in entry.parse(&input,crate::Edition::Edition2021).iter(){
9090
match step {
9191
Step::Token{ n_input_tokens, .. } => n_tokens += n_input_tokens asusize,
9292
Step::FloatSplit{ .. } => n_tokens += 1,

‎crates/syntax/src/lib.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ impl ast::TokenTree {
219219
}
220220
}
221221

222-
let parser_output = parser::TopEntryPoint::MacroEagerInput.parse(&parser_input);
222+
let parser_output = parser::TopEntryPoint::MacroEagerInput
223+
.parse(&parser_input, parser::Edition::Edition2021);
223224

224225
letmut tokens =
225226
self.syntax().descendants_with_tokens().filter_map(NodeOrToken::into_token);

‎crates/syntax/src/parsing.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
1313
let _p = tracing::span!(tracing::Level::INFO,"parse_text").entered();
1414
let lexed = parser::LexedStr::new(text);
1515
let parser_input = lexed.to_input();
16-
let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input);
16+
let parser_output =
17+
parser::TopEntryPoint::SourceFile.parse(&parser_input, parser::Edition::Edition2021);
1718
let(node, errors, _eof) = build_tree(lexed, parser_output);
1819
(node, errors)
1920
}

‎crates/syntax/src/parsing/reparsing.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn reparse_block(
9494
returnNone;
9595
}
9696

97-
let tree_traversal = reparser.parse(&parser_input);
97+
let tree_traversal = reparser.parse(&parser_input, parser::Edition::Edition2021);
9898

9999
let(green, new_parser_errors, _eof) = build_tree(lexed, tree_traversal);
100100

0 commit comments

Comments
 (0)