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 prettier method to API #70

Open
javihern98 opened this issue Feb 12, 2025 · 0 comments
Open

Add prettier method to API #70

javihern98 opened this issue Feb 12, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@javihern98
Copy link
Contributor

javihern98 commented Feb 12, 2025

Overview

We would like to add the Prettier method to the vtlengine library. The main goal is to migrate from the old engine the prettier method based on the AST Template.

Tasks to perform

  • Generate the prettier method at API. The input will be a vtl script and the output will be the same vtl script, but formatted:
def prettier(script: str) -> str:
    ....
  • Generate an internal function called stringify and a AST Template method called ASTStringify that will take the AST Object and it will extract the string representation. This string representation will include as well all children, and perform indentation where needed.
  • Add some tests with unformatted code and formatted code

Important

This is a hard requisite for #67

How do we pretty up code

  • We leave a space between each token
  • We leave a blank line between each transformation
  • On complex operators (like aggregation, analytic, joins), we open the ( and jump to the next line, adding some indentation (4 spaces or tab). We fill the code and close the )
  • On clause operators, we jump to the next line before adding the [ and jump another line and adding indentation. We here fill each clause on each line and jump another line to close the operator with ]

Examples of pretty code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants