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

Implement constant folding #54

Closed
wants to merge 6 commits into from
Closed

Implement constant folding #54

wants to merge 6 commits into from

Conversation

erezsh
Copy link
Contributor

@erezsh erezsh commented Jan 12, 2021

This doesn't fold arithmetic expressions, because there are nuances there that need to be decided. Like, is there overflow, and does division of ints return int or float?

Solves issue #32

@erezsh erezsh changed the title Use Lark with its cache feature, instead of creating a standalone parser Implement constant folding Jan 12, 2021
@erezsh erezsh changed the title Implement constant folding Implement constant folding (Issue #32) Jan 12, 2021
@erezsh erezsh changed the title Implement constant folding (Issue #32) Implement constant folding Jan 12, 2021
@aoskotsky-amplify
Copy link
Member

aoskotsky-amplify commented Jan 22, 2021

Hey thanks for the PR! I'm not sure if this should be the default behavior. There might be some cases where users want to work with HCL2 exactly as is. What do you think about having an optional flag argument on the load methods to enable/disable folding? It might require creating 2 different transformers and flipping between them based on the flag.

@htorianik
Copy link
Contributor

htorianik commented Feb 2, 2023

Hi @erezsh! First thing first, thank you very much for contributing. The solution you provided is not a complete constant folding, as it doesn't test for non-predicate arithmetic operations. We believe, that the convenient solution is to:

  1. Modify the grammar so arithmetical and logical operators will be with the right priorities, so the lexer can build a valid syntax tree.
  2. Create 2 different transformer classes, one of them will test expressions for constant folding.
    It's a time-consuming task, which we put into our backlog, but for now, we are going to close it.

And again, thanks for contributing to the project.

@erezsh erezsh closed this by deleting the head repository Sep 19, 2023
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.

None yet

3 participants