-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This eliminates the global registry object in favor of a (possibly user-created) registry instance. Users need this ability in order to add custom functions without changing the behavior of JSONPath expressions globally. Replace `spec.Function` with an interface that registry.Function (added in 701cf60) adheres to. Refactor `NewFunctionExpr` to simply create a `FunctionExpr` with that interface and performs no validation. Instead, teach the parser use a registry.Registry to look up functions and validate arguments. This requires that the parser have a registry instance, so add a `parser` struct that stores both a registry and a lexer, and cease passing the lexer to every parsing function. While at it, add the `Validator` and `Evaluator` interfaces to the registry package and teach the `Register` method (now an instance method) to return errors rather than panic. Also pass `Function` fields to it rather than a `Function` instance, as it's a cleaner API. Then make the `Function` fields private and add accessor methods to comply with the `spec.Function` interface. Other bits and bobs: * Rename `execute` to `evaluate` to be more consistent. * Remove the default function definitions from the spec package, as they now live in the registry package. * Add a mock function to properly test function expressions. * Add overlooked test case for a nil slice step.
- Loading branch information
Showing
12 changed files
with
452 additions
and
1,253 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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.