Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standard lib functions #416

Merged
merged 3 commits into from
Mar 28, 2023
Merged

Add standard lib functions #416

merged 3 commits into from
Mar 28, 2023

Conversation

isaiahvita
Copy link
Contributor

@isaiahvita isaiahvita commented Mar 17, 2023

This PR adds generic standard library functions for endpoints2.0.

An error/endpoints package was added in order to contain a utility ErrorCollector class that can provide detailed logging for errors encountered in rule evaluation. It was made public so that the additional SDK functions can depend on this as well.
The standard library functions were added in an internal package as required by the EP20 SEP.

EDIT: the core functions isSet not and getAttr will be implemented directly in codegen generation in a forthcoming PR. for example,

        @Override
        public GoWriter.Writable visitIsSet(Expr expr) {
            return (GoWriter w) -> {
                w.write("$W != nil", new ExprGenerator(scope).generate(expr));
            };
        }

        @Override
        public GoWriter.Writable visitNot(Expr expr) {
            return (GoWriter w) -> {
                w.write("!($W)", new ExprGenerator(scope).generate(expr));
            };
        }

        @Override
        public GoWriter.Writable visitBoolEquals(Expr left, Expr right) {
            return (GoWriter w) -> {
                var generator = new ExprGenerator(scope);
                w.write("$W == $W", generator.generate(left), generator.generate(right));
            };
        }

        @Override
        public GoWriter.Writable visitStringEquals(Expr left, Expr right) {
            return (GoWriter w) -> {
                var generator = new ExprGenerator(scope);
                w.write("$W == $W", generator.generate(left), generator.generate(right));
            };
        }

        @Override
        public GoWriter.Writable visitGetAttr(GetAttr getAttr) {
            var target = new ExprGenerator(scope).generate(getAttr.getTarget());
            var path = (GoWriter.Writable) (GoWriter w) -> {
                getAttr.getPath().stream().toList().forEach((part) -> {
                    if (part instanceof GetAttr.Part.Key) {
                        w.writeInline(".$L", getBuiltinMemberName(((GetAttr.Part.Key) part).key()));
                    } else if (part instanceof GetAttr.Part.Index) {
                        w.writeInline(".Get($L)", ((GetAttr.Part.Index) part).index());
                    }
                });
            };

            return (GoWriter w) -> w.writeInline("$W$W", target, path);
        }

        @Override
        public GoWriter.Writable visitLibraryFunction(FunctionDefinition fnDef, List<Expr> args) {
            return new FnGenerator(scope).generate(fnDef, args);
        }

@isaiahvita isaiahvita requested review from a team as code owners March 17, 2023 01:15
Copy link
Contributor

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks really good. I have some concerns/questions around ErrorCollector and internal as well as some minor feedback.

One other question: I'm assuming that the other functions isSet, not, and getAttr will be implemented directly in codegen generation (i.e. inlined in codegen)?

internal/endpoints/rulesfn/strings_test.go Outdated Show resolved Hide resolved
internal/endpoints/rulesfn/doc.go Outdated Show resolved Hide resolved
error/endpoints/error_collector.go Outdated Show resolved Hide resolved
internal/endpoints/rulesfn/uri.go Outdated Show resolved Hide resolved
Copy link
Contributor

@lucix-aws lucix-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved contigent on addressing the internal/ issue as pointed out by Aaron.

@isaiahvita
Copy link
Contributor Author

isaiahvita commented Mar 17, 2023

One other question: I'm assuming that the other functions isSet, not, and getAttr will be implemented directly in codegen generation (i.e. inlined in codegen)?

@aajtodd Good question, yah thats correct and i should have said this in the PR description. Will update in the PR description.

private/README.md Outdated Show resolved Hide resolved
private/README.md Outdated Show resolved Hide resolved
private/endpoints/rulesfn/error_collector.go Outdated Show resolved Hide resolved
@isaiahvita isaiahvita changed the title Add standard lib functions with utility error construct Add standard lib functions Mar 28, 2023
@isaiahvita isaiahvita merged commit 6bfc30d into aws:ep20 Mar 28, 2023
@isaiahvita isaiahvita deleted the ep20/stdlibfns branch March 28, 2023 21:44
isaiahvita added a commit that referenced this pull request May 5, 2023
@syall syall mentioned this pull request Jul 7, 2023
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants