Skip to content

Commit

Permalink
fix: Allow lalrpop parsers to be used with include!
Browse files Browse the repository at this point in the history
Due to rust-lang/rust#18810 (rust-lang/rfcs#752)
it is not possible to have an inner attribute in a file that gets
used with `include!`.

Specifying the attribute on each parser module is less precise and more
duplication but it will at least work for that case. If a user wants to
apply the rustfmt on the whole module they can still add an outer
attribute manually as well.
  • Loading branch information
Marwes committed Mar 17, 2018
1 parent df1b9c7 commit daec425
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/pascal/lalrpop/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern crate lalrpop;
fn main() {
lalrpop::Configuration::new()
.emit_comments(true)
.use_cargo_dir_conventions()
.process_current_dir()
.unwrap();
}
1 change: 1 addition & 0 deletions lalrpop/src/lexer/intern_token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn compile<W: Write>(
) -> io::Result<()> {
let prefix = &grammar.prefix;

rust!(out, "#[cfg_attr(rustfmt, rustfmt_skip)]");
rust!(out, "mod {}intern_token {{", prefix);
rust!(out, "#![allow(unused_imports)]");
try!(out.write_uses("", &grammar));
Expand Down
1 change: 1 addition & 0 deletions lalrpop/src/lr1/codegen/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl<'codegen, 'grammar, W: Write, C> CodeGenerator<'codegen, 'grammar, W, C> {
F: FnOnce(&mut Self) -> io::Result<()>,
{
rust!(self.out, "");
rust!(self.out, "#[cfg_attr(rustfmt, rustfmt_skip)]");
rust!(self.out, "mod {}parse{} {{", self.prefix, self.start_symbol);

// these stylistic lints are annoying for the generated code,
Expand Down
2 changes: 2 additions & 0 deletions lalrpop/src/lr1/codegen/test_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TestAll> {
self.write_parse_mod(|this| {
try!(this.write_parser_fn());

rust!(this.out, "#[cfg_attr(rustfmt, rustfmt_skip)]");
rust!(this.out, "mod {}ascent {{", this.prefix);
try!(super::ascent::compile(
this.grammar,
Expand All @@ -67,6 +68,7 @@ impl<'ascent, 'grammar, W: Write> CodeGenerator<'ascent, 'grammar, W, TestAll> {
rust!(this.out, "{}", pub_use);
rust!(this.out, "}}");

rust!(this.out, "#[cfg_attr(rustfmt, rustfmt_skip)]");
rust!(this.out, "mod {}parse_table {{", this.prefix);
try!(super::parse_table::compile(
this.grammar,
Expand Down
1 change: 0 additions & 1 deletion lalrpop/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ impl<W: Write> RustWrite<W> {
}

pub fn write_module_attributes(&mut self, grammar: &Grammar) -> io::Result<()> {
rust!(self, "#![cfg_attr(rustfmt, rustfmt_skip)]");
for attribute in grammar.module_attributes.iter() {
rust!(self, "{}", attribute);
}
Expand Down

0 comments on commit daec425

Please sign in to comment.