Remove proc_macro_span feature

This commit is contained in:
David Tolnay 2018-11-18 00:06:17 -08:00
parent dcda57c8af
commit 54f35aae28
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 44 additions and 16 deletions

View File

@ -22,3 +22,4 @@ quote = "0.6.10"
[build-dependencies] [build-dependencies]
lalrpop = "0.16.1" lalrpop = "0.16.1"
version_check = "0.1.5"

View File

@ -1,5 +1,11 @@
extern crate lalrpop; extern crate lalrpop;
extern crate version_check;
fn main() { fn main() {
lalrpop::process_root().unwrap(); lalrpop::process_root().unwrap();
if version_check::is_nightly().unwrap_or(false) {
println!("cargo:rustc-cfg=can_join_spans");
println!("cargo:rustc-cfg=can_show_location_of_runtime_parse_error");
}
} }

View File

@ -64,7 +64,16 @@ HtmlIdent: Ident = {
( (
match span { match span {
None => Some(token.span().unstable()), None => Some(token.span().unstable()),
Some(span) => span.join(token.span().unstable()), Some(span) => {
#[cfg(can_join_spans)]
{
span.join(token.span().unstable())
}
#[cfg(not(can_join_spans))]
{
Some(span)
}
}
}, },
if name.is_empty() { if name.is_empty() {
name + &token.to_string() name + &token.to_string()

View File

@ -156,22 +156,34 @@ impl Element {
let mut body = TokenStream::new(); let mut body = TokenStream::new();
for (attr_str, key, value) in attrs { for (attr_str, key, value) in attrs {
match value { match value {
TokenTree::Literal(l) if is_string_literal(l) => { TokenTree::Literal(lit) if is_string_literal(lit) => {
let value = value.clone(); let mut eprintln_msg = "ERROR: ".to_owned();
let tag_name: TokenTree = Literal::string(&name_str).into(); #[cfg(can_show_location_of_runtime_parse_error)]
let attr_str: TokenTree = Literal::string(&attr_str).into(); {
let span = value.span(); let span = lit.span();
let pos = format!( eprintln_msg += &format!(
"{}:{}:{}", "{}:{}:{}: ",
span.unstable().source_file().path().to_str().unwrap_or("unknown"), span.unstable()
span.unstable().start().line, .source_file()
span.unstable().start().column .path()
.to_str()
.unwrap_or("unknown"),
span.unstable().start().line,
span.unstable().start().column
);
}
eprintln_msg += &format!(
"<{} {}={}> failed to parse attribute value: {{}}",
name_str, attr_str, lit,
); );
let pos_str: TokenTree = Literal::string(&pos).into(); #[cfg(not(can_show_location_of_runtime_parse_error))]
{
eprintln_msg += "\nERROR: rebuild with nightly to print source location";
}
body.extend(quote!( body.extend(quote!(
element.attrs.#key = Some(#value.parse().unwrap_or_else(|err| { element.attrs.#key = Some(#lit.parse().unwrap_or_else(|err| {
eprintln!("ERROR: {}: <{} {}={:?}> failed to parse attribute value: {}", eprintln!(#eprintln_msg, err);
#pos_str, #tag_name, #attr_str, #value, err);
panic!("failed to parse string literal"); panic!("failed to parse string literal");
})); }));
)); ));

View File

@ -1,6 +1,6 @@
#![recursion_limit = "128"] #![recursion_limit = "128"]
#![feature(proc_macro_hygiene)] #![feature(proc_macro_hygiene)]
#![feature(proc_macro_span)] #![cfg_attr(can_show_location_of_runtime_parse_error, feature(proc_macro_span))]
extern crate ansi_term; extern crate ansi_term;
extern crate lalrpop_util; extern crate lalrpop_util;