Skip to content

Commit df0395f

Browse files
author
GBathie
committed
Fix grammar for sequences of unary ops
1 parent d997dae commit df0395f

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/ltl.pest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ not = { "!" }
1818
globally = { "G" }
1919
finally = { "F" }
2020
primary = _{ "(" ~ expr ~ ")" | prop }
21-
atom = _{ prefix? ~ primary }
22-
prop = @{ ASCII_ALPHA_LOWER ~ ASCII_ALPHANUMERIC* }
21+
atom = _{ prefix* ~ primary }
22+
prop = @{ ASCII_ALPHA_LOWER ~ (ASCII_ALPHANUMERIC | "_")* }
2323

2424
WHITESPACE = _{ " " | "\t" }

src/tests/formula_parser.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
tests::{G, Not},
44
};
55

6-
use super::{AND, F, IMP, U, build_atom};
6+
use super::{AND, EQ, F, IMP, SX, U, X, build_atom};
77

88
#[test]
99
fn test_parsing_fixed() {
@@ -37,3 +37,22 @@ fn test_parsing_gfand() {
3737
assert_eq!(f, expected)
3838
}
3939
}
40+
41+
#[test]
42+
fn test_double_unary() {
43+
let atomic_props: Vec<_> = ["a", "b", "c"].into_iter().map(|s| s.to_owned()).collect();
44+
45+
let a = || build_atom("a", 0);
46+
let b = || build_atom("b", 1);
47+
let c = || build_atom("c", 2);
48+
for (expr, expected) in [
49+
("X G a && F X[!] b", AND(X(G(a())), F(SX(b())))),
50+
(
51+
"X X a <=> G G b -> F F c",
52+
EQ(X(X(a())), IMP(G(G(b())), F(F(c())))),
53+
),
54+
] {
55+
let f = parse_ltl_formula(expr, &atomic_props).unwrap();
56+
assert_eq!(f, expected)
57+
}
58+
}

0 commit comments

Comments
 (0)