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 an expect statement to validate certain fields are provided #166

Open
darnocian opened this issue Nov 16, 2023 · 1 comment
Open

Add an expect statement to validate certain fields are provided #166

darnocian opened this issue Nov 16, 2023 · 1 comment

Comments

@darnocian
Copy link
Collaborator

darnocian commented Nov 16, 2023

<% template "mytemplate", { "name" : "string", "age": "integer" },  { "optional": "boolean" } %>
    <% name %> is <% age %> years old. <% if optional %> optional was provided. <% end %>
<% end %>

parameters could be described as shown above. if we are lazy, and just want to validate data is present:

<% template "mytemplate", ["name", "age"], ["optional"] %>
    <% name %> is <% age %> years old. <% if optional %> optional was provided. <% end %>
<% end %>

in the above , the types are missing and could be anything. code generation may not appreciate this form.

This complements the 'requires' statement. Require is mainly ensuring that the input type to a template is of a given type.
expect is mainly to ensure that fields are present. if requires and expect is used together, expect validates that the fields are present on the given type. there are two forms of usage of expect above... the first checks the types, the second doesn't care.

this will help with the native code generation when validating templates are correctly constructed. for code generation, the 'type' checking version should be used.

@darnocian darnocian changed the title Add an expect statement to validate certain fields are implemented Add an expect statement to validate certain fields are provided Nov 16, 2023
@darnocian
Copy link
Collaborator Author

darnocian commented Nov 19, 2023

Maybe the above is too complex... could implement:

<% template "mytemplate", validate %>

    <% name %> is <% age %> years old. <% if optional %> optional was provided. <% end %>
<% end %>

validate can use the 'variable extractor' to identify variables referenced and ensure that they are passed in on the stack. actually, may want to store the metadata when parsing is done. when a new template is parsed that references the template with validation meta, it is able to validate immediately without waiting for the evaluation phase.

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

No branches or pull requests

1 participant