Commit 80cabdab authored by Antoine Martin's avatar Antoine Martin Committed by Etienne Renault

ltl-desugar: support bool expressions

parent 1e857f1a
......@@ -61,9 +61,26 @@ func findExpr(formula string) (string, int, error) {
}
func parseExpr(expr string) (Expression, error) {
return &SimpleVar{
name: expr[1 : len(expr)-1],
}, nil
if expr[0] != '"' || expr[len(expr)-1] != '"' {
return nil, fmt.Errorf("expression must be enclosed in `\"`: '%s'", expr)
}
expr = expr[1 : len(expr)-1]
res := strings.Split(expr, " ")
if len(res) == 1 {
return &SimpleVar{
name: expr,
}, nil
}
if len(res) == 3 {
return &BoolExpression{
lhs: res[0],
operator: res[1],
rhs: res[2],
}, nil
}
return nil, fmt.Errorf("couldn't parse expr '%s': got %v when splitting", expr, res)
}
// SimpleVar represents a single variable expression
......
......@@ -117,6 +117,15 @@ func TestDesugar(t *testing.T) {
expected: `F ("a1" || "a2")`,
shouldFail: false,
},
// 1
{
formula: `F any("a == 2")`,
aliases: map[string][]string{
"a": []string{"a1", "a2"},
},
expected: `F (("a1 == 2") || ("a2 == 2"))`,
shouldFail: false,
},
}
for i, test := range tests {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment