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

adds support for provider functions #162

Merged

Conversation

lkwg82
Copy link
Contributor

@lkwg82 lkwg82 commented Jun 6, 2024

adds support for parsing provider defined functions

@lkwg82 lkwg82 requested a review from a team June 6, 2024 18:30
Copy link
Collaborator

@kkozik-amplify kkozik-amplify left a comment

Choose a reason for hiding this comment

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

Hey @lkwg82, thanks a lot for contributing.
I left a comment about one minor thing. Overall the PR looks good

@@ -55,6 +56,8 @@ heredoc_template_trim : /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*

function_call : identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")"
arguments : (expression (new_line_or_comment* "," new_line_or_comment* expression)* ("," | "...")? new_line_or_comment*)
colons: "::"
Copy link
Collaborator

@kkozik-amplify kkozik-amplify Jun 7, 2024

Choose a reason for hiding this comment

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

Please remove this definition and use :: directly in provider_function_call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont get it done, everytime I inline "::" I get this error:

FAIL: test_load_terraform_from_cache:10
'provider_function.tf' (test.unit.test_load.TestLoad.test_load_terraform_from_cache:10
'provider_function.tf')
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../python-hcl2/.tox/py312-unit/lib/python3.12/site-packages/lark/visitors.py", line 124, in _call_userfunc
    return f(children)
           ^^^^^^^^^^^
TypeError: sequence item 1: expected str instance, Tree found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../python-hcl2/test/unit/test_load.py", line 43, in check_terraform
    hcl2_dict = hcl2.load(hcl_file)
                ^^^^^^^^^^^^^^^^^^^
lark.exceptions.VisitError: Error trying to process rule "provider_function_call":

sequence item 1: expected str instance, Tree found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../python-hcl2/test/unit/test_load.py", line 45, in check_terraform
    assert False, f"failed to tokenize terraform in `{hcl_path_str}`: {exc}"
           ^^^^^
AssertionError: failed to tokenize terraform in `provider_function.tf`: Error trying to process rule "provider_function_call":

sequence item 1: expected str instance, Tree found

I'm not so fluent, maybe someone could assist?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I looked into that and this happens because of how the provider_function_call works. This function is consistent with function_call you seemed to base on so let's stick to the implementation you proposed.
Thanks!

@kkozik-amplify kkozik-amplify merged commit 04c3f6d into amplify-education:main Jun 11, 2024
10 checks passed
@lkwg82 lkwg82 deleted the support_provider_functions branch June 13, 2024 10:24
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.

2 participants