-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add :root and :in selectors, fix variable bug
This commit adds support for the `:in` and `:root` functions. The `:in` function is a simpler way to check if a shape is in an expression, typically used to test if a variable contains a shape or if a root expression contains a shape. `:root` is used to create rooted common subexpressions that are evaluated once against every shape in the model. `:root` expressions are evaluate in an isolated context, so any variables used or stored by them are not accessible outside the root selector. `:root` selectors allows selection to be broken into multiple steps and evaluate globally. Let's say you want all number shapes that are used in operation inputs, but not used in operation outputs. This can be done today using the following expression: ``` service $outputs(~> operation -[output]-> ~> number) ~> operation -[input]-> ~> number :not([@: @{id} = @{var|outputs|id}]) ``` With the addition of the ``:in` selector, this gets easier because we can avoid using a scoped attribute selector: ``` service $outputs(~> operation -[output]-> ~> number) ~> operation -[input]-> ~> number :not(:in(${outputs})) ``` (Note: to make this work, I had to uncover and fix a bug in the implementation of how we store variables. We previously used `Collection#add` as a `Receiver`, but that method will return false if it's already seen a shape, which is wrong.) With the addition of `:root`, you can use a much simpler expression: ``` number :in(:root(service ~> operation -[input]-> ~> number)) :not(:in(:root(service ~> operation -[output]-> ~> number))) ``` (Note: the result of root expressions are run once and cached. No need to store them in a variable) These expressions _seem_ to be exactly the same, however, the `:root` expression gives a different result when working with models that contain multiple services. In the first two expressions, if any service uses shape X in input and not output, then X is a result. However, in the `:root` expression, X is only part of the result if no service uses it in their output shape closures.
- Loading branch information
Showing
20 changed files
with
660 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.