Commit Graph

64 Commits

Author SHA1 Message Date
Anand Krishnamoorthi
951bb6b14c Handle chained _ (#27)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-10-17 19:32:42 -07:00
Anand Krishnamoorthi
2436467fbd Minimize PR 22 (#26)
* specific functions added to eval different rego components

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* allow multiple inputs and results

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* prepare_for_eval is necessary to be called

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* test with the suggested code examples and clean scopes

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* try to refactor first steps of evaluations

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* improve coverage and fix clean state internal evaluation

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* add getters and setters and fix clean function

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>

* Tests are single input by default. Multi input specified via "many!" marker.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>

---------

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
Co-authored-by: eric-therond <eric.therond.fr@gmail.com>
2023-10-09 14:27:31 -07:00
eric-therond
2ba718ba72 improve errors location (#23)
Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
2023-09-27 09:41:30 -07:00
Anand Krishnamoorthi
b7420aceba Fix clippy warning (#25)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-09-27 08:40:36 -07:00
eric-therond
8a9652b8d2 negation of an undefined value should return true (#21)
Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
2023-06-29 09:44:19 -07:00
Anand Krishnamoorthi
796da46ae8 Ensure that scopes are cleaned up correctly upon error. (#20)
When evaluating rules, upon error the last pushed scope wasn't being
popped from the stack of scopes. This causes incorrect behavior
when there are multiple definitions for the same rule name.

The fix is to make sure that the scopes are popped manually upon encountering errors.

Once the interpreter logic is locked down, then we need to clean up scope management
using Drop functions so that the cleanup happens even during short circuited return.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-06-23 08:57:47 -07:00
eric-therond
e08d13df53 fix bitwise.and and add tests (#19)
Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
2023-06-22 11:27:58 -07:00
eric-therond
910ef32ffb support of or-functions (#18)
* support of multiple definitions of the same function
* handle functions producing an error

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
2023-06-16 09:30:17 -07:00
Anand Krishnamoorthi
7789de41b6 Statement Scheduler Implementation
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-04-09 20:28:59 -07:00
Anand Krishnamoorthi
6738eeed3c Remove unnecessary lifetime
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-07 21:27:27 +05:30
Anand Krishnamoorthi
cba0af0d3f json.filter, object.filter, object.get, object.keys, object.remove
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-07 21:27:27 +05:30
Anand Krishnamoorthi
6b637e9151 conversion::to_number builtin
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-05 16:39:42 +05:30
Anand Krishnamoorthi
112623c762 tracing::trace builtin
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-05 16:39:42 +05:30
Anand Krishnamoorthi
81f6199642 bitwise builtins
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-05 16:39:42 +05:30
Anand Krishnamoorthi
ec695bd22e debugging::print builtin
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-05 16:39:42 +05:30
Anand Krishnamoorthi
c5ea737200 Partial sprintf implementation.
This needs to be flushed out to be compatible with https://pkg.go.dev/fmt.
All the features of the go format string don't need to be implemented,
only those that are relevant for Rego.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-04 17:12:18 +05:30
Anand Krishnamoorthi
ea47de919c All string functions except sprintf. TODO: Add tests
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 22:13:09 +05:30
Anand Krishnamoorthi
f9897085cf More string functions without tests
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 22:13:09 +05:30
Anand Krishnamoorthi
3c3cd312fc More string functions
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 22:13:09 +05:30
Anand Krishnamoorthi
27c5afd8ee strings: concat and contains
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 22:13:09 +05:30
Anand Krishnamoorthi
89e26e37a2 string concat (WIP)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 22:13:09 +05:30
Anand Krishnamoorthi
e93b33ea05 Support build on non Linux platforms
cargo config
1. MUSL is no longer the default target. This allows building on Mac and Windows.
2. On Linux, code coverage compiler options are supplied by default.

pre-commit, pre-push
- Coverage is turned on only on Linux
- clippy is run on all platforms

github
- MUSL build is tested to ensure that stand alone executables can be created

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-03-01 15:45:44 +05:30
Anand Krishnamoorthi
608f1592e8 Prepare for upstreaming
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
32028a311e Test for multi-assign
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
8e0ddbcff2 Support dependencies between vars defined in same statement
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
34eee1f17f Statement scheduler (WIP)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
0ae24110cb Print small-form table of files without 100% coverage.
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
379d4631a5 Code tweaks to improve coverage
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
31e1c63281 Tests for aggregates builtins
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
6b87e99fb9 Tests for numbers builtins
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
17257f9f1d Tests for arrays builtins
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
c4ae2d4cc2 Tests for types functions
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
ae3866b1ab Destructuring of arrays and objects in some-in expressions
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
cf4fbdbb90 some .. in implementation
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
eded43bdc6 Fix key, value in membership and some-in
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
3549931342 refactor
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
d84096024d Arrays and Aggregates
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
351483d100 Implement every statement (#4)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
2a1924efa5 Set loop index variable if not "_" (#3)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
267b76e4d3 Allow comprehensions in default value. (#2)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
12c3d26476 Lock down numbers
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
a8a1d4b820 mod function
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Anand Krishnamoorthi
b30fc2599c Builtin functions for numbers (WIP)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-28 09:38:40 +05:30
Ming-Wei Shih
24911e6807 Merge pull request #7 from anakrish/main
Implement comparison operators. Formalize semantics.
2023-02-13 13:23:00 -08:00
Anand Krishnamoorthi
53030c4ada Implement comparison operators. Formalize semantics.
Rename compare.rs to comparison.rs to match OPA documentation of builtins.

Also update loop handling to ensure that the current scope is restored after
each iteration of the loop so as to undo side effects of the iteration.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-12 22:19:16 -08:00
Ming-Wei Shih
fd5140a5a8 Rework assign operations (#6)
Support "var = value", "value = var", and "var = var"
Fall back the '=' to comparsion when both operators are defined
Correctly support variable shadowing with "var := value"

Also, remove the unused Variable struct

Signed-off-by: Ming-Wei Shih <mishih@microsoft.com>
2023-02-11 06:37:04 +05:30
Ming-Wei Shih
1001afbb28 Merge pull request #5 from anakrish/main
Locked down supported values in default rule.
2023-02-10 08:32:18 -08:00
Anand Krishnamoorthi
3a3bbcdb7d Locked down supported values in default rule.
Only scalars, composites and comprehensions containing scalars are supported.
This will be changed as OPA fixes bug with default values

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-10 06:13:42 -08:00
Anand Krishnamoorthi
c92707433e Improvements to github workflow (#4)
- format check
- clippy checks
- build tests separately before running

Also fix clippy warnings

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2023-02-10 11:16:09 +05:30
Anand Krishnamoorthi
dc0720b32a Merge pull request #3 from anakrish/main
Update name to regorus
2023-02-10 10:08:33 +05:30