Assignment operator and multi-line

97 views
Skip to first unread message

Vivek Shankar

unread,
Jul 10, 2020, 10:24:22 PM7/10/20
to CEL Go Discussion Forum
Hi,

I have been using CEL in my product as an engine to execute user-authored "code" and it works great. I am working on a multi-line capability, but I was wondering if there were any thoughts on adding two things to the parser -

  1. An end-of-line terminator: Like semi-colon in certain languages
  2. An assignment operator: I know this opens up scoping of variables etc. but it might be possible to define certain caveats. For example, you can't define the same var name in a sub-frame.

This would save me the need to write my own parser.

Tristan Swadell

unread,
Jul 13, 2020, 1:40:43 PM7/13/20
to Vivek Shankar, CEL Go Discussion Forum
Hi Vivek,

If you're looking for an example of assignments, I would recommend looking over https://github.com/google/cel-policy-templates-go for how we combined CEL + YAML for making assignments and more complex logical constructs. CEL will forever remain small so that it more easily be embedded into larger frameworks. The moment we introduce assignments, we'll increase the analytical complexity of the core language in ways that would be undesirable.

If you're looking for tips on how to embed CEL into a larger ANTLR grammar, I can provide some examples there as well.

-Tristan


--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/b3579d68-e1c0-49e4-9771-964dd1393cfao%40googlegroups.com.

Michael Leonard

unread,
Jul 14, 2020, 3:45:46 AM7/14/20
to Tristan Swadell, Vivek Shankar, CEL Go Discussion Forum
Just in case it's helpful... you might want to look into cue as well (in go, also by Google).


Vivek Shankar

unread,
Jul 14, 2020, 8:34:39 AM7/14/20
to CEL Go Discussion Forum
Hi Tristan,

Thanks for the reply. Makes sense.

I have managed to implement something similar. Here's an example -

stmts:
- init: userExists = has(user.name)
- init: givenNameExists = context.userExists && has(user.name.givenName) && user.name.givenName != ""
- init: familyNameExists = context.userExists && has(user.name.familyName) && user.name.familyName != ""
- init: formattedExists = context.userExists && has(user.name.formatted) && user.name.formatted != ""
- if:
match: context.formattedExists
block:
- ret: user.name.formatted
eifs:
- match: context.givenNameExists
block:
- if:
match: context.familyNameExists
block:
- ret: user.name.familyName + ", " + user.name.givenName
else:
- ret: user.name.givenName
- match: context.familyNameExists
block:
- ret: user.name.familyName

The "context" var implements traits.Indexer and contains a list of maps representing stacked state, so assigned variables can be inherited in nested blocks (like in nested if conditions etc.).


On Tuesday, 14 July 2020 01:40:43 UTC+8, Tristan Swadell wrote:
Hi Vivek,

If you're looking for an example of assignments, I would recommend looking over https://github.com/google/cel-policy-templates-go for how we combined CEL + YAML for making assignments and more complex logical constructs. CEL will forever remain small so that it more easily be embedded into larger frameworks. The moment we introduce assignments, we'll increase the analytical complexity of the core language in ways that would be undesirable.

If you're looking for tips on how to embed CEL into a larger ANTLR grammar, I can provide some examples there as well.

-Tristan


On Fri, Jul 10, 2020 at 7:24 PM Vivek Shankar <viv.s...@gmail.com> wrote:
Hi,

I have been using CEL in my product as an engine to execute user-authored "code" and it works great. I am working on a multi-line capability, but I was wondering if there were any thoughts on adding two things to the parser -

  1. An end-of-line terminator: Like semi-colon in certain languages
  2. An assignment operator: I know this opens up scoping of variables etc. but it might be possible to define certain caveats. For example, you can't define the same var name in a sub-frame.

This would save me the need to write my own parser.

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-...@googlegroups.com.

Vivek Shankar

unread,
Jul 14, 2020, 8:35:27 AM7/14/20
to CEL Go Discussion Forum
Thanks! I will check it out.


On Tuesday, 14 July 2020 15:45:46 UTC+8, Michael Leonard wrote:
Just in case it's helpful... you might want to look into cue as well (in go, also by Google).


On Mon, 13 Jul 2020, 18:40 'Tristan Swadell' via CEL Go Discussion Forum, <cel-go-...@googlegroups.com> wrote:
Hi Vivek,

If you're looking for an example of assignments, I would recommend looking over https://github.com/google/cel-policy-templates-go for how we combined CEL + YAML for making assignments and more complex logical constructs. CEL will forever remain small so that it more easily be embedded into larger frameworks. The moment we introduce assignments, we'll increase the analytical complexity of the core language in ways that would be undesirable.

If you're looking for tips on how to embed CEL into a larger ANTLR grammar, I can provide some examples there as well.

-Tristan


On Fri, Jul 10, 2020 at 7:24 PM Vivek Shankar <viv.s...@gmail.com> wrote:
Hi,

I have been using CEL in my product as an engine to execute user-authored "code" and it works great. I am working on a multi-line capability, but I was wondering if there were any thoughts on adding two things to the parser -

  1. An end-of-line terminator: Like semi-colon in certain languages
  2. An assignment operator: I know this opens up scoping of variables etc. but it might be possible to define certain caveats. For example, you can't define the same var name in a sub-frame.

This would save me the need to write my own parser.

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages