Skip to content

Commit

Permalink
Remove lazy_static and htmlescape dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslueg committed Jul 14, 2024
1 parent 861844c commit 9e6e21b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
Expand All @@ -15,7 +15,7 @@ jobs:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
Expand All @@ -24,11 +24,19 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
cargo test --no-default-features
cargo test --all-features
sudo apt-get update && sudo apt-get install -y libxml2-utils
cargo test -- --ignored
cargo test --features visual-debug -- --ignored
examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo run --example src_to_svg
- run: cargo run --example various
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ readme = "README.md"
exclude = ["examples/*.jpeg", "examples/*.jpg", "examples/*.svg", "examples/*.html"]

[dependencies]
syn = { version = "2.0", features = ["full", "parsing", "extra-traits"], default_features=false }
railroad = "0.2"
syn = { version = "2.0", features = ["full", "parsing", "extra-traits"], default-features=false }
railroad = { version = "0.3.1" }
proc-macro2 = { version = "1.0", default-features=false }

[dev-dependencies]
lazy_static = "1.1"
quote = { version = "1.0", default_features = false }
quote = { version = "1.0", default-features = false }
railroad_verification = "0.1"
htmlescape = "0.3"

[features]
visual-debug = ["railroad/visual-debug"]
6 changes: 2 additions & 4 deletions examples/nom4_method.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions examples/various.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use htmlescape;
use macro_railroad;
use railroad;
use std::fs;
Expand Down Expand Up @@ -86,7 +85,7 @@ pub fn to_example_page(
outp.write_all(b"</style>")?;
outp.write_all(b"</head><body>")?;

write!(outp, "<h1>{}</h1>", htmlescape::encode_minimal(title))?;
write!(outp, "<h1>{}</h1>", railroad::svg::encode_minimal(title))?;
outp.write_all(b"<div>")?;
let mut names = Vec::with_capacity(examples.len());
outp.write_all(b"<div class=\"examples\">")?;
Expand All @@ -96,23 +95,23 @@ pub fn to_example_page(
write!(
outp,
"<div class=\"example\" id=\"{}\">",
htmlescape::encode_attribute(&name)
railroad::svg::encode_attribute(&name)
)?;
write!(
outp,
"<a href=\"#{}\">",
htmlescape::encode_attribute(&name)
railroad::svg::encode_attribute(&name)
)?;
write!(
outp,
"<h3>Macro <i>`{}`</i></h3></a>",
htmlescape::encode_minimal(&name)
railroad::svg::encode_minimal(&name)
)?;
names.push(name);
write!(
outp,
"<pre class=\"rust\">{}</pre><br>",
htmlescape::encode_minimal(src)
railroad::svg::encode_minimal(src)
)?;
let dia_svg = dia.to_string();
let dia_opt_svg = dia_opt.to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn into_primitive(m: lowering::Matcher) -> Box<dyn railroad::Node> {
let mut nonterm = railroad::NonTerminal::new(name);
nonterm
.attr("class".to_owned())
.or_insert_with(Default::default)
.or_default()
.push_str(fragment_to_class(&fragment));
Box::new(nonterm)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl InspectVisitor for NonTerminalCollector {
Matcher::NonTerminal { name, fragment } => {
self.bag
.entry(fragment.clone())
.or_insert_with(Default::default)
.or_default()
.insert(name.clone());
}
other => self.visit_children(other),
Expand Down
12 changes: 5 additions & 7 deletions tests/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
///
/// This calls out to the `xmllint` tool from libxml2, which may not be available.
/// The test is therefor ignored by default; use `cargo test -- --ignored`
use std::sync::OnceLock;

#[macro_use]
extern crate lazy_static;

lazy_static! {
static ref VERIFIER: railroad_verification::Verifier =
railroad_verification::Verifier::new().unwrap();
fn init_verifier() -> &'static railroad_verification::Verifier {
static VERIFIER: OnceLock<railroad_verification::Verifier> = OnceLock::new();
VERIFIER.get_or_init(|| railroad_verification::Verifier::new().unwrap())
}

fn to_diagram(src: &str) -> (String, Vec<(&'static str, String)>) {
Expand Down Expand Up @@ -51,7 +49,7 @@ macro_rules! verify {
eprintln!("Parsed `{}` as macro '{}'", stringify!($testname), name);
for (variant, dia) in dias.into_iter() {
eprintln!("Verifying variant `{}`", variant);
if let Err(e) = VERIFIER.verify(dia) {
if let Err(e) = init_verifier().verify(dia) {
eprintln!("{:?}", e);
panic!("Failed to verifiy `{}`", name);
}
Expand Down

0 comments on commit 9e6e21b

Please sign in to comment.