mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Add edition to all parse
functions of the parser crate
This commit is contained in:
parent
392538c830
commit
454e481422
9 changed files with 16 additions and 20 deletions
|
@ -131,7 +131,7 @@ where
|
||||||
_ => TokenBuffer::from_subtree(tt),
|
_ => TokenBuffer::from_subtree(tt),
|
||||||
};
|
};
|
||||||
let parser_input = to_parser_input(&buffer);
|
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());
|
let mut tree_sink = TtTreeSink::new(buffer.begin());
|
||||||
for event in parser_output.iter() {
|
for event in parser_output.iter() {
|
||||||
match event {
|
match event {
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl<'a, S: Copy + fmt::Debug> TtIter<'a, S> {
|
||||||
) -> ExpandResult<Option<tt::TokenTree<S>>> {
|
) -> ExpandResult<Option<tt::TokenTree<S>>> {
|
||||||
let buffer = tt::buffer::TokenBuffer::from_tokens(self.inner.as_slice());
|
let buffer = tt::buffer::TokenBuffer::from_tokens(self.inner.as_slice());
|
||||||
let parser_input = to_parser_input(&buffer);
|
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 cursor = buffer.begin();
|
||||||
let mut error = false;
|
let mut error = false;
|
||||||
for step in tree_traversal.iter() {
|
for step in tree_traversal.iter() {
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub enum TopEntryPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 _p = tracing::span!(tracing::Level::INFO, "TopEntryPoint::parse", ?self).entered();
|
||||||
let entry_point: fn(&'_ mut parser::Parser<'_>) = match self {
|
let entry_point: fn(&'_ mut parser::Parser<'_>) = match self {
|
||||||
TopEntryPoint::SourceFile => grammar::entry::top::source_file,
|
TopEntryPoint::SourceFile => grammar::entry::top::source_file,
|
||||||
|
@ -99,7 +99,7 @@ impl TopEntryPoint {
|
||||||
TopEntryPoint::MetaItem => grammar::entry::top::meta_item,
|
TopEntryPoint::MetaItem => grammar::entry::top::meta_item,
|
||||||
TopEntryPoint::MacroEagerInput => grammar::entry::top::eager_macro_input,
|
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);
|
entry_point(&mut p);
|
||||||
let events = p.finish();
|
let events = p.finish();
|
||||||
let res = event::process(events);
|
let res = event::process(events);
|
||||||
|
@ -151,7 +151,7 @@ pub enum PrefixEntryPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
let entry_point: fn(&'_ mut parser::Parser<'_>) = match self {
|
||||||
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
||||||
PrefixEntryPoint::Block => grammar::entry::prefix::block,
|
PrefixEntryPoint::Block => grammar::entry::prefix::block,
|
||||||
|
@ -164,7 +164,7 @@ impl PrefixEntryPoint {
|
||||||
PrefixEntryPoint::Item => grammar::entry::prefix::item,
|
PrefixEntryPoint::Item => grammar::entry::prefix::item,
|
||||||
PrefixEntryPoint::MetaItem => grammar::entry::prefix::meta_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);
|
entry_point(&mut p);
|
||||||
let events = p.finish();
|
let events = p.finish();
|
||||||
event::process(events)
|
event::process(events)
|
||||||
|
@ -188,9 +188,9 @@ impl Reparser {
|
||||||
///
|
///
|
||||||
/// Tokens must start with `{`, end with `}` and form a valid brace
|
/// Tokens must start with `{`, end with `}` and form a valid brace
|
||||||
/// sequence.
|
/// sequence.
|
||||||
pub fn parse(self, tokens: &Input) -> Output {
|
pub fn parse(self, tokens: &Input, edition: Edition) -> Output {
|
||||||
let Reparser(r) = self;
|
let Reparser(r) = self;
|
||||||
let mut p = parser::Parser::new(tokens, Edition::Edition2021);
|
let mut p = parser::Parser::new(tokens, edition);
|
||||||
r(&mut p);
|
r(&mut p);
|
||||||
let events = p.finish();
|
let events = p.finish();
|
||||||
event::process(events)
|
event::process(events)
|
||||||
|
|
|
@ -40,13 +40,7 @@ static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
|
||||||
|
|
||||||
impl<'t> Parser<'t> {
|
impl<'t> Parser<'t> {
|
||||||
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
|
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
|
||||||
Parser {
|
Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0), edition }
|
||||||
inp,
|
|
||||||
pos: 0,
|
|
||||||
events: Vec::new(),
|
|
||||||
steps: Cell::new(0),
|
|
||||||
edition,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn finish(self) -> Vec<Event> {
|
pub(crate) fn finish(self) -> Vec<Event> {
|
||||||
|
|
|
@ -88,7 +88,7 @@ fn parse_inline_err() {
|
||||||
fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
|
fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
|
||||||
let lexed = LexedStr::new(text);
|
let lexed = LexedStr::new(text);
|
||||||
let input = lexed.to_input();
|
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 buf = String::new();
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
|
|
|
@ -86,7 +86,7 @@ fn check(entry: PrefixEntryPoint, input: &str, prefix: &str) {
|
||||||
let input = lexed.to_input();
|
let input = lexed.to_input();
|
||||||
|
|
||||||
let mut n_tokens = 0;
|
let mut n_tokens = 0;
|
||||||
for step in entry.parse(&input).iter() {
|
for step in entry.parse(&input, crate::Edition::Edition2021).iter() {
|
||||||
match step {
|
match step {
|
||||||
Step::Token { n_input_tokens, .. } => n_tokens += n_input_tokens as usize,
|
Step::Token { n_input_tokens, .. } => n_tokens += n_input_tokens as usize,
|
||||||
Step::FloatSplit { .. } => n_tokens += 1,
|
Step::FloatSplit { .. } => n_tokens += 1,
|
||||||
|
|
|
@ -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 =
|
let mut tokens =
|
||||||
self.syntax().descendants_with_tokens().filter_map(NodeOrToken::into_token);
|
self.syntax().descendants_with_tokens().filter_map(NodeOrToken::into_token);
|
||||||
|
|
|
@ -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 _p = tracing::span!(tracing::Level::INFO, "parse_text").entered();
|
||||||
let lexed = parser::LexedStr::new(text);
|
let lexed = parser::LexedStr::new(text);
|
||||||
let parser_input = lexed.to_input();
|
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);
|
let (node, errors, _eof) = build_tree(lexed, parser_output);
|
||||||
(node, errors)
|
(node, errors)
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ fn reparse_block(
|
||||||
return None;
|
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);
|
let (green, new_parser_errors, _eof) = build_tree(lexed, tree_traversal);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue