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

Detect reserved keywords in specific generator languages #759

Open
hellovai opened this issue Jul 8, 2024 · 1 comment
Open

Detect reserved keywords in specific generator languages #759

hellovai opened this issue Jul 8, 2024 · 1 comment

Comments

@hellovai
Copy link
Contributor

hellovai commented Jul 8, 2024

When users add an enum or class field named True or None we run into issues in python that are very hard for the user to debug due to reserved word usage.

To address this we should instead preemptively detect this in our static analyzer.

Copy link

greptile-apps bot commented Jul 8, 2024

To detect reserved keywords in specific generator languages, extend the assert_is_not_a_reserved_scalar_type function in /engine/baml-lib/parser-database/src/names/mod.rs to include checks for reserved keywords in Python (e.g., True, None).

fn assert_is_not_a_reserved_scalar_type(ident: &ast::Identifier, ctx: &mut Context<'_>) {
    let reserved_keywords = ["True", "None"];
    if StaticType::try_from_str(ident.name()).is_some() || reserved_keywords.contains(&ident.name()) {
        ctx.push_error(DatamodelError::new_reserved_scalar_type_error(
            ident.name(),
            ident.span().clone(),
        ));
    }
}

This will preemptively detect and report errors for reserved keywords in Python during the static analysis phase.

References

/engine/baml-lib/parser-database/src/names/mod.rs
/engine/baml-lib/baml-core/src/configuration.rs

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Ask Greptile · Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant