Commit 660971ac authored by Antoine Martin's avatar Antoine Martin Committed by Etienne Renault

desugar: only export/document required function

parent fff280da
......@@ -5,6 +5,9 @@ import (
"strings"
)
// Desugar an LTL formula by expanding the expression inside "any" or "all"
// keywords by a combination of expression representing all aliases of the
// concerned variables.
func Desugar(formula string, aliases map[string][]string) (string, error) {
if !strings.Contains(formula, "any") && !strings.Contains(formula, "all") {
return formula, nil
......@@ -60,7 +63,7 @@ func findExpr(formula string) (string, int, error) {
return formula[:idx], idx, nil
}
func parseExpr(expr string) (Expression, error) {
func parseExpr(expr string) (expression, error) {
if expr[0] != '"' || expr[len(expr)-1] != '"' {
return nil, fmt.Errorf("expression must be enclosed in `\"`: '%s'", expr)
}
......@@ -68,12 +71,12 @@ func parseExpr(expr string) (Expression, error) {
res := strings.Split(expr, " ")
if len(res) == 1 {
return &SimpleVar{
return &simpleVar{
name: expr,
}, nil
}
if len(res) == 3 {
return &BoolExpression{
return &boolExpression{
lhs: res[0],
operator: res[1],
rhs: res[2],
......@@ -83,23 +86,23 @@ func parseExpr(expr string) (Expression, error) {
return nil, fmt.Errorf("couldn't parse expr '%s': got %v when splitting", expr, res)
}
// SimpleVar represents a single variable expression
type SimpleVar struct {
// simpleVar represents a single variable expression
type simpleVar struct {
name string
}
// BoolExpression represents a boolean expression, such as 'a == 2'
type BoolExpression struct {
// boolExpression represents a boolean expression, such as 'a == 2'
type boolExpression struct {
lhs string
operator string
rhs string
}
type Expression interface {
type expression interface {
Expand(aliases map[string][]string, op string) (string, error)
}
func (sv *SimpleVar) Expand(aliases map[string][]string, op string) (string, error) {
func (sv *simpleVar) Expand(aliases map[string][]string, op string) (string, error) {
al, ok := aliases[sv.name]
if !ok {
return "", fmt.Errorf("couldn't find aliases for %s", sv.name)
......@@ -122,7 +125,7 @@ func (sv *SimpleVar) Expand(aliases map[string][]string, op string) (string, err
return b.String(), nil
}
func (bx *BoolExpression) Expand(aliases map[string][]string, op string) (string, error) {
func (bx *boolExpression) Expand(aliases map[string][]string, op string) (string, error) {
al, ok := aliases[bx.lhs]
if !ok {
return "", fmt.Errorf("couldn't find aliases for %s", bx.lhs)
......
......@@ -23,14 +23,14 @@ func TestUnchanged(t *testing.T) {
func TestSimpleVarExpand(t *testing.T) {
tests := []struct {
variable SimpleVar
variable simpleVar
aliases map[string][]string
expected string
shouldFail bool
}{
// 0
{
variable: SimpleVar{
variable: simpleVar{
name: "a",
},
aliases: map[string][]string{
......@@ -46,7 +46,7 @@ func TestSimpleVarExpand(t *testing.T) {
},
// 1
{
variable: SimpleVar{
variable: simpleVar{
name: "a",
},
aliases: map[string][]string{},
......@@ -55,7 +55,7 @@ func TestSimpleVarExpand(t *testing.T) {
},
// 2
{
variable: SimpleVar{
variable: simpleVar{
name: "a",
},
aliases: map[string][]string{
......@@ -86,14 +86,14 @@ func TestSimpleVarExpand(t *testing.T) {
func TestBoolExpressionExpand(t *testing.T) {
tests := []struct {
expr BoolExpression
expr boolExpression
aliases map[string][]string
expected string
shouldFail bool
}{
// 0
{
expr: BoolExpression{
expr: boolExpression{
lhs: "a",
operator: "==",
rhs: "2",
......@@ -109,7 +109,7 @@ func TestBoolExpressionExpand(t *testing.T) {
},
// 1
{
expr: BoolExpression{
expr: boolExpression{
lhs: "a",
operator: "==",
rhs: "2",
......@@ -122,7 +122,7 @@ func TestBoolExpressionExpand(t *testing.T) {
},
// 2
{
expr: BoolExpression{
expr: boolExpression{
lhs: "a",
operator: "==",
rhs: "2",
......
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