Skip to content
Open
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
19 changes: 19 additions & 0 deletions hoa/stateacc.hoa
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HOA: v1
States: 10
Start: 0
AP: 2 "p0" "p1"
acc-name: Buchi
Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc
--BODY--
State: 0
[!0&!1] 1
[ 0&!1] 1
[ !0&1] 1
[0 & 1] 0
State: 1 {0}
[!0&!1] 0
[ 0&!1] 0
[!0& 1] 1
[ 0 &1] 1
--END--
2 changes: 1 addition & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl AcceptanceSignature {
/// Tries to get the singleton element of the acceptance signature, if it exists.
/// Returns `None` if the acceptance signature is not a singleton.
pub fn get_singleton(&self) -> Option<Option<Id>> {
if self.len() == 0 {
if self.is_empty() {
Some(None)
} else if self.len() == 1 {
Some(Some(self[0]))
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ mod tests {
use crate::{
body::{Edge, State},
header::Header,
output::to_hoa,
AcceptanceAtom, AcceptanceCondition, AcceptanceName, AcceptanceSignature, Body, HeaderItem,
HoaAutomaton, Label, StateConjunction, ALPHABET, VARS,

@longfangsong longfangsong Jun 12, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to run the tests acturally, I can't find ALPHABET and VARS defined anywhere in this repo.

};
Expand Down Expand Up @@ -636,4 +637,12 @@ mod tests {
))
)
}

#[test]
fn real_test_state_acc() {
let contents = include_str!("../hoa/stateacc.hoa");
let hoa_aut = HoaAutomaton::try_from(contents);
let result = to_hoa(&hoa_aut.unwrap());
assert!(result.contains("State: 1 {0}"));
}
}
44 changes: 41 additions & 3 deletions src/output.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
use std::fmt::Display;

use itertools::Itertools;
use std::fmt::{Display, Write};

use crate::{
AcceptanceAtom, AcceptanceCondition, AcceptanceInfo, AcceptanceName, AcceptanceSignature,
AliasName, Edge, HeaderItem, HoaAutomaton, HoaBool, Label, Property, State, StateConjunction,
};

pub fn to_hoa(aut: &HoaAutomaton) -> String {
let state_acceptance = aut.header().iter().any(|it| {
if let HeaderItem::Properties(properties) = it {
properties.iter().contains(&Property::StateAcceptance)
} else {
false
}
});
aut.header()
.into_iter()
.map(|header_item| header_item.to_string())
.chain(std::iter::once("--BODY--".to_string()))
.chain(aut.body().into_iter().map(|state| state.to_string()))
.chain(
aut.body()
.into_iter()
.map(|state| state.fmt_with_config(state_acceptance)),
)
.chain(std::iter::once("--END--".to_string()))
.join("\n")
}
Expand Down Expand Up @@ -181,3 +191,31 @@ impl Display for State {
Ok(())
}
}

impl State {
fn fmt_with_config(&self, state_acceptance: bool) -> String {
let mut f = String::new();
if let Some(comment) = &self.1 {
write!(f, "State: {} \"{}\"", self.0, comment).unwrap();
} else {
write!(f, "State: {}", self.0).unwrap();
}
if state_acceptance {
let acceptance = self.2.iter().map(|it| &it.2).all_equal_value();
if let Ok(acceptance) = acceptance {
writeln!(f, " {acceptance}").unwrap();
} else {
writeln!(f).unwrap();
}
for edge in &self.2 {
writeln!(f, "{} {}", edge.0, edge.1).unwrap();
}
} else {
writeln!(f).unwrap();
for edge in &self.2 {
writeln!(f, "{edge}").unwrap();
}
}
f
}
}
2 changes: 1 addition & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn acceptance_info() -> impl Parser<Token, AcceptanceInfo, Error = Simple<To
pub fn label_expression() -> impl Parser<Token, AbstractLabelExpression, Error = Simple<Token>> {
recursive(|label_expression| {
let value = boolean()
.map(|b| AbstractLabelExpression::Boolean(b))
.map(AbstractLabelExpression::Boolean)
.or(integer().map(|i| AbstractLabelExpression::Integer(i as u16)));
// .or(alias_name().map(|aname| LabelExpression::Alias(AliasName(aname))));

Expand Down