Skip to content

Commit

Permalink
Merge branch 'flatten2' of https://github.com/OlgaNovg/expr into flat…
Browse files Browse the repository at this point in the history
…ten2
  • Loading branch information
OlgaNovg committed Jul 10, 2024
2 parents 674c94f + b83d632 commit 4f0a28b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func main() {
* [Span Digital](https://spandigital.com/) uses Expr in it's Knowledge Management products.
* [Xiaohongshu](https://www.xiaohongshu.com/) combining yaml with Expr for dynamically policies delivery.
* [Melrōse](https://melrōse.org) uses Expr to implement its music programming language.
* [Tork](https://www.tork.run/) integrates Expr into its workflow execution.

[Add your company too](https://github.com/expr-lang/expr/edit/master/README.md)

Expand Down
11 changes: 7 additions & 4 deletions ast/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ func (n *ConstantNode) String() string {
}

func (n *UnaryNode) String() string {
op := ""
op := n.Operator
if n.Operator == "not" {
op = fmt.Sprintf("%s ", n.Operator)
} else {
op = fmt.Sprintf("%s", n.Operator)
}
if _, ok := n.Node.(*BinaryNode); ok {
wrap := false
switch n.Node.(type) {
case *BinaryNode, *ConditionalNode:
wrap = true
}
if wrap {
return fmt.Sprintf("%s(%s)", op, n.Node.String())
}
return fmt.Sprintf("%s%s", op, n.Node.String())
Expand Down
1 change: 1 addition & 0 deletions ast/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestPrint(t *testing.T) {
{`(nil ?? 1) > 0`, `(nil ?? 1) > 0`},
{`{("a" + "b"): 42}`, `{("a" + "b"): 42}`},
{`(One == 1 ? true : false) && Two == 2`, `(One == 1 ? true : false) && Two == 2`},
{`not (a == 1 ? b > 1 : b < 2)`, `not (a == 1 ? b > 1 : b < 2)`},
}

for _, tt := range tests {
Expand Down

0 comments on commit 4f0a28b

Please sign in to comment.