about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohann Hemmann <johann.hemmann@code.berlin>2024-01-30 16:45:10 +0100
committerLukas Wirth <lukastw97@gmail.com>2024-04-14 15:07:43 +0200
commit454e48142237b421db514330e8c26fb90c90affc (patch)
treed65c1e8056be88f4a0f101df5593b4c66793a8a5
parent392538c8303a9d82afa6bdb02219a3506c7b942b (diff)
downloadrust-454e48142237b421db514330e8c26fb90c90affc.tar.gz
rust-454e48142237b421db514330e8c26fb90c90affc.zip
Add edition to all `parse` functions of the parser crate
-rw-r--r--crates/mbe/src/syntax_bridge.rs2
-rw-r--r--crates/mbe/src/tt_iter.rs2
-rw-r--r--crates/parser/src/lib.rs12
-rw-r--r--crates/parser/src/parser.rs8
-rw-r--r--crates/parser/src/tests.rs2
-rw-r--r--crates/parser/src/tests/prefix_entries.rs2
-rw-r--r--crates/syntax/src/lib.rs3
-rw-r--r--crates/syntax/src/parsing.rs3
-rw-r--r--crates/syntax/src/parsing/reparsing.rs2
9 files changed, 16 insertions, 20 deletions
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index c934db6b715..a22bbf833aa 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -131,7 +131,7 @@ where
         _ => TokenBuffer::from_subtree(tt),
     };
     let parser_input = to_parser_input(&buffer);
-    let parser_output = entry_point.parse(&parser_input);
+    let parser_output = entry_point.parse(&parser_input, parser::Edition::Edition2021);
     let mut tree_sink = TtTreeSink::new(buffer.begin());
     for event in parser_output.iter() {
         match event {
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index e3d12d87078..12f7deafd6b 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
@@ -143,7 +143,7 @@ impl<'a, S: Copy + fmt::Debug> TtIter<'a, S> {
     ) -> ExpandResult<Option<tt::TokenTree<S>>> {
         let buffer = tt::buffer::TokenBuffer::from_tokens(self.inner.as_slice());
         let parser_input = to_parser_input(&buffer);
-        let tree_traversal = entry_point.parse(&parser_input);
+        let tree_traversal = entry_point.parse(&parser_input, parser::Edition::Edition2021);
         let mut cursor = buffer.begin();
         let mut error = false;
         for step in tree_traversal.iter() {
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs
index abce8e2f482..f29fba08dd3 100644
--- a/crates/parser/src/lib.rs
+++ b/crates/parser/src/lib.rs
@@ -87,7 +87,7 @@ pub enum TopEntryPoint {
 }
 
 impl TopEntryPoint {
-    pub fn parse(&self, input: &Input) -> Output {
+    pub fn parse(&self, input: &Input, edition: Edition) -> Output {
         let _p = tracing::span!(tracing::Level::INFO, "TopEntryPoint::parse", ?self).entered();
         let entry_point: fn(&'_ mut parser::Parser<'_>) = match self {
             TopEntryPoint::SourceFile => grammar::entry::top::source_file,
@@ -99,7 +99,7 @@ impl TopEntryPoint {
             TopEntryPoint::MetaItem => grammar::entry::top::meta_item,
             TopEntryPoint::MacroEagerInput => grammar::entry::top::eager_macro_input,
         };
-        let mut p = parser::Parser::new(input, Edition::Edition2021);
+        let mut p = parser::Parser::new(input, edition);
         entry_point(&mut p);
         let events = p.finish();
         let res = event::process(events);
@@ -151,7 +151,7 @@ pub enum PrefixEntryPoint {
 }
 
 impl PrefixEntryPoint {
-    pub fn parse(&self, input: &Input) -> Output {
+    pub fn parse(&self, input: &Input, edition: Edition) -> Output {
         let entry_point: fn(&'_ mut parser::Parser<'_>) = match self {
             PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
             PrefixEntryPoint::Block => grammar::entry::prefix::block,
@@ -164,7 +164,7 @@ impl PrefixEntryPoint {
             PrefixEntryPoint::Item => grammar::entry::prefix::item,
             PrefixEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
         };
-        let mut p = parser::Parser::new(input, Edition::Edition2021);
+        let mut p = parser::Parser::new(input, edition);
         entry_point(&mut p);
         let events = p.finish();
         event::process(events)
@@ -188,9 +188,9 @@ impl Reparser {
     ///
     /// Tokens must start with `{`, end with `}` and form a valid brace
     /// sequence.
-    pub fn parse(self, tokens: &Input) -> Output {
+    pub fn parse(self, tokens: &Input, edition: Edition) -> Output {
         let Reparser(r) = self;
-        let mut p = parser::Parser::new(tokens, Edition::Edition2021);
+        let mut p = parser::Parser::new(tokens, edition);
         r(&mut p);
         let events = p.finish();
         event::process(events)
diff --git a/crates/parser/src/parser.rs b/crates/parser/src/parser.rs
index df53e13f6ef..eb8f761a916 100644
--- a/crates/parser/src/parser.rs
+++ b/crates/parser/src/parser.rs
@@ -40,13 +40,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
 
 impl<'t> Parser<'t> {
     pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
-        Parser {
-            inp,
-            pos: 0,
-            events: Vec::new(),
-            steps: Cell::new(0),
-            edition,
-        }
+        Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition }
     }
 
     pub(crate) fn finish(self) -> Vec<Event> {
diff --git a/crates/parser/src/tests.rs b/crates/parser/src/tests.rs
index c65219b28dc..6b5bde7a753 100644
--- a/crates/parser/src/tests.rs
+++ b/crates/parser/src/tests.rs
@@ -88,7 +88,7 @@ fn parse_inline_err() {
 fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
     let lexed = LexedStr::new(text);
     let input = lexed.to_input();
-    let output = entry.parse(&input);
+    let output = entry.parse(&input, crate::Edition::Edition2021);
 
     let mut buf = String::new();
     let mut errors = Vec::new();
diff --git a/crates/parser/src/tests/prefix_entries.rs b/crates/parser/src/tests/prefix_entries.rs
index 2f3c7febc04..ee8b2d1f43d 100644
--- a/crates/parser/src/tests/prefix_entries.rs
+++ b/crates/parser/src/tests/prefix_entries.rs
@@ -86,7 +86,7 @@ fn check(entry: PrefixEntryPoint, input: &str, prefix: &str) {
     let input = lexed.to_input();
 
     let mut n_tokens = 0;
-    for step in entry.parse(&input).iter() {
+    for step in entry.parse(&input, crate::Edition::Edition2021).iter() {
         match step {
             Step::Token { n_input_tokens, .. } => n_tokens += n_input_tokens as usize,
             Step::FloatSplit { .. } => n_tokens += 1,
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs
index 1bb82cc191f..41f560fce2f 100644
--- a/crates/syntax/src/lib.rs
+++ b/crates/syntax/src/lib.rs
@@ -219,7 +219,8 @@ impl ast::TokenTree {
             }
         }
 
-        let parser_output = parser::TopEntryPoint::MacroEagerInput.parse(&parser_input);
+        let parser_output = parser::TopEntryPoint::MacroEagerInput
+            .parse(&parser_input, parser::Edition::Edition2021);
 
         let mut tokens =
             self.syntax().descendants_with_tokens().filter_map(NodeOrToken::into_token);
diff --git a/crates/syntax/src/parsing.rs b/crates/syntax/src/parsing.rs
index d750476f63c..35683c9eed9 100644
--- a/crates/syntax/src/parsing.rs
+++ b/crates/syntax/src/parsing.rs
@@ -13,7 +13,8 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
     let _p = tracing::span!(tracing::Level::INFO, "parse_text").entered();
     let lexed = parser::LexedStr::new(text);
     let parser_input = lexed.to_input();
-    let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input);
+    let parser_output =
+        parser::TopEntryPoint::SourceFile.parse(&parser_input, parser::Edition::Edition2021);
     let (node, errors, _eof) = build_tree(lexed, parser_output);
     (node, errors)
 }
diff --git a/crates/syntax/src/parsing/reparsing.rs b/crates/syntax/src/parsing/reparsing.rs
index 14715b57253..3f48bdddfaf 100644
--- a/crates/syntax/src/parsing/reparsing.rs
+++ b/crates/syntax/src/parsing/reparsing.rs
@@ -94,7 +94,7 @@ fn reparse_block(
         return None;
     }
 
-    let tree_traversal = reparser.parse(&parser_input);
+    let tree_traversal = reparser.parse(&parser_input, parser::Edition::Edition2021);
 
     let (green, new_parser_errors, _eof) = build_tree(lexed, tree_traversal);