Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CLAUDE.md

`hoars` parses (and, partially, writes) the HOA (Hanoi Omega Automata) format, <https://adl.github.io/hoaf/>. It is the parser behind the `hoa` feature of the `automata` crate (`leonbohn/automata`). Edition 2024, version 0.3.0, MIT.
`hoars` parses (and, partially, writes) the HOA (Hanoi Omega Automata) format, <https://adl.github.io/hoaf/>. It is the parser behind the `hoa` feature of the `automata` crate (`leonbohn/automata`). Edition 2024, version 0.4.0, MIT.

## History

Expand Down Expand Up @@ -29,8 +29,8 @@ RUSTDOCFLAGS="-D warnings" cargo doc --no-deps

- MSRV is 1.88 (`rust-version`; `biodivine-lib-bdd` needs it), checked in CI for the library only.
- Parsers use `chumsky` 0.9 (`Simple<Token>` errors), flagged with `allow(clippy::result_large_err)` in several places.
- 51 unit tests, including one that parses, round-trips and converts every fixture in `hoa/` (`hoa/spec/` holds the spec examples, `hoa/spot/` real Spot output); no fuzzing.
- Version `0.3.0` is the first release since crates.io `0.2.0` (breaking: `biodivine-lib-bdd` 0.6).
- 52 unit tests, including one that parses, round-trips and converts every fixture in `hoa/` (`hoa/spec/` holds the spec examples, `hoa/spot/` real Spot output); no fuzzing.
- Version `0.4.0` is the first release since crates.io `0.2.0` (0.3.0 was never published); breaking changes include `biodivine-lib-bdd` 0.6 and the reworked `Header`/`Body`/error API.

## Benchmarks

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hoars"
version = "0.3.0"
version = "0.4.0"
description = "A library for dealing with the HOA (Hanoi Omega Automata) file format."
repository = "https://github.com/leonbohn/hoars"
homepage = "https://github.com/leonbohn/hoars"
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 29 additions & 14 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,38 @@ pub fn tokenizer<'a>() -> impl Parser<'a, &'a str, Vec<(Token<'a>, Span)>, extra
op, paren, int, abort, end_, body, header, version, str_, alias, ident,
));

// comments nest: `/*a/*b*/c*/` is a single comment
let comment = recursive(|comment| {
just("/*")
.ignore_then(
comment
.or(any().and_is(just("*/").not()).ignored())
.repeated(),
)
.then_ignore(just("*/"))
.ignored()
})
.padded();
// Whitespace and nested comments (`/*a/*b*/c*/` is one comment). A depth counter instead
// of a recursive grammar: backtracking over unclosed `/*` was exponential (found by fuzzing).
let layout = custom(
|inp: &mut chumsky::input::InputRef<'a, '_, &'a str, extra::Err<Cheap<Span>>>| {
let start = inp.cursor();
let mut depth = 0usize;
loop {
let before = inp.save();
match inp.next() {
Some(c) if depth == 0 && c.is_whitespace() => {}
Some('/') if inp.peek() == Some('*') => {
inp.skip();
depth += 1;
}
Some('*') if depth > 0 && inp.peek() == Some('/') => {
inp.skip();
depth -= 1;
}
Some(_) if depth > 0 => {}
None if depth > 0 => return Err(Cheap::new(inp.span_since(&start))),
_ => {
inp.rewind(before);
return Ok(());
}
}
}
},
);

token
.map_with(|tok, e| (tok, e.span()))
.padded_by(comment.repeated())
.padded()
.padded_by(layout)
.repeated()
.collect()
}
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,16 @@ State: 0
assert!(HoaRepresentation::try_from(unterminated.as_str()).is_err());
}

#[test]
fn unclosed_nested_comments_are_linear_time() {
// found by fuzzing: backtracking over unclosed `/*` was exponential
let input = "/*/*\"\"/*#{//*/*/".repeat(200);
let start = std::time::Instant::now();
assert!(HoaRepresentation::try_from(input.as_str()).is_err());
assert!(super::parse_hoa_automata(&input).is_empty());
assert!(start.elapsed() < std::time::Duration::from_secs(1));
}

#[test]
fn abort_inside_string_is_not_an_abort() {
let hoa = MINIMAL.replace("v1", "v1\nname: \"--ABORT-- --END--\"");
Expand Down
Loading