Add edition to all parse functions of the parser crate

This commit is contained in:
Johann Hemmann 2024-01-30 16:45:10 +01:00 committed by Lukas Wirth
parent 392538c830
commit 454e481422
9 changed files with 16 additions and 20 deletions

View file

@ -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 {

View file

@ -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() {

View file

@ -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)

View file

@ -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> {

View file

@ -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();

View file

@ -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,

View file

@ -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);

View file

@ -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)
}

View file

@ -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);