Skip to content

Commit d3aea46

Browse files
authored
Merge branch 'expr-lang:master' into master
2 parents ef455a9 + d63c3b5 commit d3aea46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2471
-382
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*\[generated\].go linguist-language=txt

.github/scripts/coverage.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
const expected = 90
44
const exclude = [
5-
'expr/test',
6-
'checker/mock',
7-
'vm/func_types',
8-
'vm/runtime/helpers',
9-
'internal/difflib',
10-
'internal/spew',
11-
'internal/testify',
5+
'expr/test', // We do not need to test the test package.
6+
'checker/mock', // Mocks only used for testing.
7+
'vm/func_types', // Generated files.
8+
'vm/runtime/helpers', // Generated files.
9+
'internal/difflib', // Test dependency. This is vendored dependency, and ideally we also have good tests for it.
10+
'internal/spew', // Test dependency.
11+
'internal/testify', // Test dependency.
12+
'patcher/value', // Contains a lot of repeating code. Ideally we should have a test for it.
13+
'pro', // Expr Pro is not a part of the main codebase.
1214
]
1315

1416
cd(path.resolve(__dirname, '..', '..'))

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
go-versions: [ '1.18', '1.22' ]
14+
go-versions: [ '1.18', '1.22', '1.24' ]
1515
go-arch: [ '386' ]
1616
steps:
1717
- uses: actions/checkout@v3

.github/workflows/diff.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ jobs:
1313
with:
1414
go-version: 1.18
1515
- name: Install benchstat
16-
run: go install golang.org/x/perf/cmd/benchstat@latest
16+
# NOTE: benchstat@latest requires go 1.23 since 2025-02-14 - this is the last go 1.18 ref
17+
# https://cs.opensource.google/go/x/perf/+/c95ad7d5b636f67d322a7e4832e83103d0fdd292
18+
run: go install golang.org/x/perf/cmd/benchstat@884df5810d2850d775c2cb4885a7ea339128a17d
1719

1820
- uses: actions/checkout@v3
1921
- name: Benchmark new code

.github/workflows/fuzz.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ jobs:
2121
fuzz-seconds: 600
2222
output-sarif: true
2323
- name: Upload Crash
24-
uses: actions/upload-artifact@v3
24+
uses: actions/upload-artifact@v4
2525
if: failure() && steps.build.outcome == 'success'
2626
with:
2727
name: artifacts
2828
path: ./out/artifacts
2929
- name: Upload Sarif
3030
if: always() && steps.build.outcome == 'success'
31-
uses: github/codeql-action/upload-sarif@v2
31+
uses: github/codeql-action/upload-sarif@v3
3232
with:
3333
# Path to SARIF file relative to the root of the repository
3434
sarif_file: cifuzz-sarif/results.sarif

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
go-versions: [ '1.18', '1.19', '1.20', '1.21', '1.22' ]
14+
go-versions: [ '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24' ]
1515
steps:
1616
- uses: actions/checkout@v3
1717
- name: Setup Go ${{ matrix.go-version }}

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,14 @@ func main() {
162162
* [Visually.io](https://visually.io) employs Expr as a business rule engine for its personalization targeting algorithm.
163163
* [Akvorado](https://github.com/akvorado/akvorado) utilizes Expr to classify exporters and interfaces in network flows.
164164
* [keda.sh](https://keda.sh) uses Expr to allow customization of its Kubernetes-based event-driven autoscaling.
165-
* [Span Digital](https://spandigital.com/) uses Expr in it's Knowledge Management products.
165+
* [Span Digital](https://spandigital.com/) uses Expr in its Knowledge Management products.
166166
* [Xiaohongshu](https://www.xiaohongshu.com/) combining yaml with Expr for dynamically policies delivery.
167167
* [Melrōse](https://melrōse.org) uses Expr to implement its music programming language.
168+
* [Tork](https://www.tork.run/) integrates Expr into its workflow execution.
169+
* [Critical Moments](https://criticalmoments.io) uses Expr for its mobile realtime conditional targeting system.
170+
* [WoodpeckerCI](https://woodpecker-ci.org) uses Expr for [filtering workflows/steps](https://woodpecker-ci.org/docs/usage/workflow-syntax#evaluate).
171+
* [FastSchema](https://github.com/fastschema/fastschema) - A BaaS leveraging Expr for its customizable and dynamic Access Control system.
172+
* [WunderGraph Cosmo](https://github.com/wundergraph/cosmo) - GraphQL Federeration Router uses Expr to customize Middleware behaviour
168173

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

ast/find.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ast
2+
3+
func Find(node Node, fn func(node Node) bool) Node {
4+
v := &finder{fn: fn}
5+
Walk(&node, v)
6+
return v.node
7+
}
8+
9+
type finder struct {
10+
node Node
11+
fn func(node Node) bool
12+
}
13+
14+
func (f *finder) Visit(node *Node) {
15+
if f.fn(*node) {
16+
f.node = *node
17+
}
18+
}

ast/find_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ast_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/expr-lang/expr/internal/testify/require"
7+
8+
"github.com/expr-lang/expr/ast"
9+
)
10+
11+
func TestFind(t *testing.T) {
12+
left := &ast.IdentifierNode{
13+
Value: "a",
14+
}
15+
var root ast.Node = &ast.BinaryNode{
16+
Operator: "+",
17+
Left: left,
18+
Right: &ast.IdentifierNode{
19+
Value: "b",
20+
},
21+
}
22+
23+
x := ast.Find(root, func(node ast.Node) bool {
24+
if n, ok := node.(*ast.IdentifierNode); ok {
25+
return n.Value == "a"
26+
}
27+
return false
28+
})
29+
30+
require.Equal(t, left, x)
31+
}

ast/node.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ type VariableDeclaratorNode struct {
216216
Expr Node // Expression of the variable. Like "foo + 1" in "let foo = 1; foo + 1".
217217
}
218218

219+
// SequenceNode represents a sequence of nodes separated by semicolons.
220+
// All nodes are executed, only the last node will be returned.
221+
type SequenceNode struct {
222+
base
223+
Nodes []Node
224+
}
225+
219226
// ArrayNode represents an array.
220227
type ArrayNode struct {
221228
base

0 commit comments

Comments
 (0)