Move sess
function and use it more.
This commit is contained in:
parent
3996447b37
commit
0d4ebe1c1b
2 changed files with 8 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
use crate::tests::{
|
use crate::tests::{
|
||||||
matches_codepattern, string_to_stream, with_error_checking_parse, with_expected_parse_error,
|
matches_codepattern, sess, string_to_stream, with_error_checking_parse,
|
||||||
|
with_expected_parse_error,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ast::token::IdentIsRaw;
|
use ast::token::IdentIsRaw;
|
||||||
|
@ -16,13 +17,8 @@ use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::create_default_session_globals_then;
|
use rustc_span::create_default_session_globals_then;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_span::{BytePos, FileName, Pos, Span};
|
use rustc_span::{BytePos, FileName, Pos, Span};
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn sess() -> ParseSess {
|
|
||||||
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE])
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses an item.
|
/// Parses an item.
|
||||||
///
|
///
|
||||||
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err`
|
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err`
|
||||||
|
|
|
@ -18,6 +18,10 @@ use std::path::{Path, PathBuf};
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
pub(crate) fn sess() -> ParseSess {
|
||||||
|
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE])
|
||||||
|
}
|
||||||
|
|
||||||
/// Map string to parser (via tts).
|
/// Map string to parser (via tts).
|
||||||
fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
|
fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
|
||||||
new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
|
new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
|
||||||
|
@ -72,8 +76,7 @@ where
|
||||||
|
|
||||||
/// Maps a string to tts, using a made-up filename.
|
/// Maps a string to tts, using a made-up filename.
|
||||||
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
|
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
|
||||||
let ps =
|
let ps = sess();
|
||||||
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE]);
|
|
||||||
source_file_to_stream(
|
source_file_to_stream(
|
||||||
&ps,
|
&ps,
|
||||||
ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
|
ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
|
||||||
|
@ -83,8 +86,7 @@ pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
|
||||||
|
|
||||||
/// Parses a string, returns a crate.
|
/// Parses a string, returns a crate.
|
||||||
pub(crate) fn string_to_crate(source_str: String) -> ast::Crate {
|
pub(crate) fn string_to_crate(source_str: String) -> ast::Crate {
|
||||||
let ps =
|
let ps = sess();
|
||||||
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE]);
|
|
||||||
with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
|
with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue