about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/lib.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-05-31 09:23:35 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-06-05 10:29:16 +1000
commitd1215da26e7848bd925a9fffecdaa7ea51b360c3 (patch)
treede75ac1b80a1b00c15edf2370d1b055d14a14439 /compiler/rustc_parse/src/lib.rs
parente1ae0fa055bf358cec14d41e7ddd96cd8964eb9d (diff)
downloadrust-d1215da26e7848bd925a9fffecdaa7ea51b360c3.tar.gz
rust-d1215da26e7848bd925a9fffecdaa7ea51b360c3.zip
Don't use the word "parse" for lexing operations.
Lexing converts source text into a token stream. Parsing converts a
token stream into AST fragments. This commit renames several lexing
operations that have "parse" in the name. I think these names have been
subtly confusing me for years.

This is just a `s/parse/lex/` on function names, with one exception:
`parse_stream_from_source_str` becomes `source_str_to_stream`, to make
it consistent with the existing `source_file_to_stream`. The commit also
moves that function's location in the file to be just above
`source_file_to_stream`.

The commit also cleans up a few comments along the way.
Diffstat (limited to 'compiler/rustc_parse/src/lib.rs')
-rw-r--r--compiler/rustc_parse/src/lib.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs
index 322739be3fb..b4610447be7 100644
--- a/compiler/rustc_parse/src/lib.rs
+++ b/compiler/rustc_parse/src/lib.rs
@@ -84,15 +84,6 @@ pub fn parse_crate_attrs_from_source_str(
     new_parser_from_source_str(psess, name, source).parse_inner_attributes()
 }
 
-pub fn parse_stream_from_source_str(
-    name: FileName,
-    source: String,
-    psess: &ParseSess,
-    override_span: Option<Span>,
-) -> TokenStream {
-    source_file_to_stream(psess, psess.source_map().new_source_file(name, source), override_span)
-}
-
 /// Creates a new parser from a source string.
 pub fn new_parser_from_source_str(psess: &ParseSess, name: FileName, source: String) -> Parser<'_> {
     panictry_buffer!(maybe_new_parser_from_source_str(psess, name, source))
@@ -142,6 +133,15 @@ fn maybe_source_file_to_parser(
 
 // Base abstractions
 
+pub fn source_str_to_stream(
+    name: FileName,
+    source: String,
+    psess: &ParseSess,
+    override_span: Option<Span>,
+) -> TokenStream {
+    source_file_to_stream(psess, psess.source_map().new_source_file(name, source), override_span)
+}
+
 /// Given a `source_file`, produces a sequence of token trees.
 pub fn source_file_to_stream(
     psess: &ParseSess,
@@ -165,7 +165,7 @@ fn maybe_file_to_stream<'psess>(
         ));
     });
 
-    lexer::parse_token_trees(psess, src.as_str(), source_file.start_pos, override_span)
+    lexer::lex_token_trees(psess, src.as_str(), source_file.start_pos, override_span)
 }
 
 /// Given a stream and the `ParseSess`, produces a parser.
@@ -195,13 +195,13 @@ pub fn parse_in<'a, T>(
 pub fn fake_token_stream_for_item(psess: &ParseSess, item: &ast::Item) -> TokenStream {
     let source = pprust::item_to_string(item);
     let filename = FileName::macro_expansion_source_code(&source);
-    parse_stream_from_source_str(filename, source, psess, Some(item.span))
+    source_str_to_stream(filename, source, psess, Some(item.span))
 }
 
 pub fn fake_token_stream_for_crate(psess: &ParseSess, krate: &ast::Crate) -> TokenStream {
     let source = pprust::crate_to_string_for_macros(krate);
     let filename = FileName::macro_expansion_source_code(&source);
-    parse_stream_from_source_str(filename, source, psess, Some(krate.spans.inner_span))
+    source_str_to_stream(filename, source, psess, Some(krate.spans.inner_span))
 }
 
 pub fn parse_cfg_attr(