Skip to content

Commit 660cf34

Browse files
committed
dead code
1 parent bfc263f commit 660cf34

File tree

8 files changed

+9
-70
lines changed

8 files changed

+9
-70
lines changed

crates/ide_assists/src/handlers/remove_dbg.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
3636
let input_expressions = input_expressions
3737
.into_iter()
3838
.filter_map(|(is_sep, group)| (!is_sep).then(|| group))
39-
.map(|mut tokens| ast::Expr::parse(&tokens.join("")))
40-
.collect::<Result<Vec<ast::Expr>, _>>()
41-
.ok()?;
39+
.map(|mut tokens| syntax::hacks::parse_expr_from_str(&tokens.join("")))
40+
.collect::<Option<Vec<ast::Expr>>>()?;
4241

4342
let parent = macro_call.syntax().parent()?;
4443
let (range, text) = match &*input_expressions {

crates/parser/src/grammar.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ pub(crate) mod entry {
117117
}
118118
}
119119

120-
pub(crate) mod entry_points {
121-
use super::*;
122-
123-
pub(crate) fn stmt_optional_semi(p: &mut Parser) {
124-
expressions::stmt(p, expressions::StmtWithSemi::Optional, false);
125-
}
126-
127-
pub(crate) fn attr(p: &mut Parser) {
128-
attributes::outer_attrs(p);
129-
}
130-
}
131-
132120
pub(crate) fn reparser(
133121
node: SyntaxKind,
134122
first_child: Option<SyntaxKind>,

crates/parser/src/lib.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -132,47 +132,6 @@ impl TopEntryPoint {
132132
}
133133
}
134134

135-
/// rust-analyzer parser allows you to choose one of the possible entry points.
136-
///
137-
/// The primary consumer of this API are declarative macros, `$x:expr` matchers
138-
/// are implemented by calling into the parser with non-standard entry point.
139-
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
140-
pub enum ParserEntryPoint {
141-
Path,
142-
Expr,
143-
StatementOptionalSemi,
144-
Pattern,
145-
Attr,
146-
}
147-
148-
/// Parse given tokens into the given sink as a rust file.
149-
pub fn parse_source_file(input: &Input) -> Output {
150-
TopEntryPoint::SourceFile.parse(input)
151-
}
152-
153-
/// Parses the given [`Input`] into [`Output`] assuming that the top-level
154-
/// syntactic construct is the given [`ParserEntryPoint`].
155-
///
156-
/// Both input and output here are fairly abstract. The overall flow is that the
157-
/// caller has some "real" tokens, converts them to [`Input`], parses them to
158-
/// [`Output`], and then converts that into a "real" tree. The "real" tree is
159-
/// made of "real" tokens, so this all hinges on rather tight coordination of
160-
/// indices between the four stages.
161-
pub fn parse(inp: &Input, entry_point: ParserEntryPoint) -> Output {
162-
let entry_point: fn(&'_ mut parser::Parser) = match entry_point {
163-
ParserEntryPoint::Path => grammar::entry::prefix::path,
164-
ParserEntryPoint::Expr => grammar::entry::prefix::expr,
165-
ParserEntryPoint::Pattern => grammar::entry::prefix::pat,
166-
ParserEntryPoint::StatementOptionalSemi => grammar::entry_points::stmt_optional_semi,
167-
ParserEntryPoint::Attr => grammar::entry_points::attr,
168-
};
169-
170-
let mut p = parser::Parser::new(inp);
171-
entry_point(&mut p);
172-
let events = p.finish();
173-
event::process(events)
174-
}
175-
176135
/// A parsing function for a specific braced-block.
177136
pub struct Reparser(fn(&mut parser::Parser));
178137

crates/parser/src/shortcuts.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ impl<'a> LexedStr<'a> {
5252
pub fn intersperse_trivia(
5353
&self,
5454
output: &crate::Output,
55-
synthetic_root: bool,
5655
sink: &mut dyn FnMut(StrStep),
5756
) -> bool {
5857
let mut builder = Builder { lexed: self, pos: 0, state: State::PendingEnter, sink };
5958

60-
if synthetic_root {
61-
builder.enter(SyntaxKind::SOURCE_FILE);
62-
}
6359
for event in output.iter() {
6460
match event {
6561
Step::Token { kind, n_input_tokens: n_raw_tokens } => {
@@ -73,9 +69,6 @@ impl<'a> LexedStr<'a> {
7369
}
7470
}
7571
}
76-
if synthetic_root {
77-
builder.exit();
78-
}
7972

8073
match mem::replace(&mut builder.state, State::Normal) {
8174
State::PendingExit => {

crates/parser/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ fn parse_inline_err() {
8080
fn parse(text: &str) -> (String, bool) {
8181
let lexed = LexedStr::new(text);
8282
let input = lexed.to_input();
83-
let output = crate::parse_source_file(&input);
83+
let output = crate::TopEntryPoint::SourceFile.parse(&input);
8484

8585
let mut buf = String::new();
8686
let mut errors = Vec::new();
8787
let mut indent = String::new();
88-
lexed.intersperse_trivia(&output, false, &mut |step| match step {
88+
lexed.intersperse_trivia(&output, &mut |step| match step {
8989
crate::StrStep::Token { kind, text } => {
9090
write!(buf, "{}", indent).unwrap();
9191
write!(buf, "{:?} {:?}\n", kind, text).unwrap();

crates/syntax/src/hacks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use crate::{ast, AstNode};
66

77
pub fn parse_expr_from_str(s: &str) -> Option<ast::Expr> {
8+
let s = s.trim();
89
let file = ast::SourceFile::parse(&format!("const _: () = {};", s));
910
let expr = file.syntax_node().descendants().find_map(ast::Expr::cast)?;
1011
if expr.syntax().text() != s {

crates/syntax/src/parsing.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@ pub(crate) use crate::parsing::reparsing::incremental_reparse;
1212
pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
1313
let lexed = parser::LexedStr::new(text);
1414
let parser_input = lexed.to_input();
15-
let parser_output = parser::parse_source_file(&parser_input);
16-
let (node, errors, _eof) = build_tree(lexed, parser_output, false);
15+
let parser_output = parser::TopEntryPoint::SourceFile.parse(&parser_input);
16+
let (node, errors, _eof) = build_tree(lexed, parser_output);
1717
(node, errors)
1818
}
1919

2020
pub(crate) fn build_tree(
2121
lexed: parser::LexedStr<'_>,
2222
parser_output: parser::Output,
23-
synthetic_root: bool,
2423
) -> (GreenNode, Vec<SyntaxError>, bool) {
2524
let mut builder = SyntaxTreeBuilder::default();
2625

27-
let is_eof = lexed.intersperse_trivia(&parser_output, synthetic_root, &mut |step| match step {
26+
let is_eof = lexed.intersperse_trivia(&parser_output, &mut |step| match step {
2827
parser::StrStep::Token { kind, text } => builder.token(kind, text),
2928
parser::StrStep::Enter { kind } => builder.start_node(kind),
3029
parser::StrStep::Exit => builder.finish_node(),

crates/syntax/src/parsing/reparsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn reparse_block(
9696

9797
let tree_traversal = reparser.parse(&parser_input);
9898

99-
let (green, new_parser_errors, _eof) = build_tree(lexed, tree_traversal, false);
99+
let (green, new_parser_errors, _eof) = build_tree(lexed, tree_traversal);
100100

101101
Some((node.replace_with(green), new_parser_errors, node.text_range()))
102102
}

0 commit comments

Comments
 (0)