Skip to content
Permalink
Browse files

Simplify code

  • Loading branch information...
estebank committed Mar 4, 2019
1 parent 3818f8b commit 6f0f2fc6d6ca0800c8b8b95932010d51af4e4663
@@ -6,6 +6,7 @@ use crate::source_map::{SourceMap, FilePathMapping};
use crate::feature_gate::UnstableFeatures;
use crate::parse::parser::Parser;
use crate::symbol::Symbol;
use crate::syntax::parse::parser::emit_unclosed_delims;
use crate::tokenstream::{TokenStream, TokenTree};
use crate::diagnostics::plugin::ErrorMap;
use crate::print::pprust::token_to_string;
@@ -141,8 +142,14 @@ pub fn parse_stream_from_source_str(
source: String,
sess: &ParseSess,
override_span: Option<Span>,
) -> (TokenStream, Vec<lexer::UnmatchedBrace>) {
source_file_to_stream(sess, sess.source_map().new_source_file(name, source), override_span)
) -> TokenStream {
let (stream, mut errors) = source_file_to_stream(
sess,
sess.source_map().new_source_file(name, source),
override_span,
);
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
stream
}

/// Creates a new parser from a source string.
@@ -261,10 +261,8 @@ pub struct Parser<'a> {

impl<'a> Drop for Parser<'a> {
fn drop(&mut self) {
if !self.unclosed_delims.is_empty() {
let diag = self.diagnostic();
emit_unclosed_delims(&mut self.unclosed_delims, diag);
}
let diag = self.diagnostic();
emit_unclosed_delims(&mut self.unclosed_delims, diag);
}
}

@@ -10,7 +10,6 @@ use crate::print::pprust;
use crate::ptr::P;
use crate::symbol::keywords;
use crate::syntax::parse::parse_stream_from_source_str;
use crate::syntax::parse::parser::emit_unclosed_delims;
use crate::tokenstream::{self, DelimSpan, TokenStream, TokenTree};

use syntax_pos::symbol::{self, Symbol};
@@ -675,9 +674,7 @@ impl Nonterminal {
// FIXME(#43081): Avoid this pretty-print + reparse hack
let source = pprust::nonterminal_to_string(self);
let filename = FileName::macro_expansion_source_code(&source);
let (tokens_for_real, mut errors) =
parse_stream_from_source_str(filename, source, sess, Some(span));
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
let tokens_for_real = parse_stream_from_source_str(filename, source, sess, Some(span));

// During early phases of the compiler the AST could get modified
// directly (e.g., attributes added or removed) and the internal cache
@@ -740,13 +737,7 @@ fn prepend_attrs(sess: &ParseSess,
let source = pprust::attr_to_string(attr);
let macro_filename = FileName::macro_expansion_source_code(&source);
if attr.is_sugared_doc {
let (stream, mut errors) = parse_stream_from_source_str(
macro_filename,
source,
sess,
Some(span),
);
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span));
builder.push(stream);
continue
}
@@ -763,13 +754,7 @@ fn prepend_attrs(sess: &ParseSess,
// ... and for more complicated paths, fall back to a reparse hack that
// should eventually be removed.
} else {
let (stream, mut errors) = parse_stream_from_source_str(
macro_filename,
source,
sess,
Some(span),
);
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
let stream = parse_stream_from_source_str(macro_filename, source, sess, Some(span));
brackets.push(stream);
}

@@ -12,7 +12,6 @@ use syntax::ast;
use syntax::ext::base::ExtCtxt;
use syntax::parse::lexer::comments;
use syntax::parse::{self, token, ParseSess};
use syntax::parse::parser::emit_unclosed_delims;
use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
use syntax_pos::hygiene::{SyntaxContext, Transparency};
use syntax_pos::symbol::{keywords, Symbol};
@@ -410,14 +409,12 @@ impl server::TokenStream for Rustc<'_> {
stream.is_empty()
}
fn from_str(&mut self, src: &str) -> Self::TokenStream {
let (tokens, mut errors) = parse::parse_stream_from_source_str(
parse::parse_stream_from_source_str(
FileName::proc_macro_source_code(src.clone()),
src.to_string(),
self.sess,
Some(self.call_site),
);
emit_unclosed_delims(&mut errors, &self.sess.span_diagnostic);
tokens
)
}
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
stream.to_string()

0 comments on commit 6f0f2fc

Please sign in to comment.
You can’t perform that action at this time.