Skip to content

Design suggestion: change ASTNode variants to contain concrete structs #40

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

Closed
khionu opened this issue Jan 26, 2019 · 3 comments
Closed

Comments

@khionu
Copy link

khionu commented Jan 26, 2019

As is, the example below can be a necessary evil. Using separate, concrete structs allows the data to be passed as a single value.

fn main() {
    // ...
    match sql_ast {
        SQLSelect { projection, relation, joins, selection, 
                    order_by, group_by, having, limit } =>  {
            select(projection, relation, joins, selection,
                   order_by, group_by, having, limit, &mut out_ts);
        },
        _ => {}
    }
}

fn select(projection: Vec<ASTNode>, relation: Option<Box<ASTNode>>, joins: Vec<Join>,
          selection: Option<Box<ASTNode>>, order_by: Option<Vec<SQLOrderByExpr>>,
          group_by: Option<Vec<ASTNode>>, having: Option<Box<ASTNode>>, limit: Option<Box<ASTNode>>,
          out_ts: &mut TokenStream) {
    // ...
}
@nickolay
Copy link
Contributor

FWIW, I did this to SQLSelect locally in an experiment to make the AST more strongly typed, because it lets me to use the struct both from an ASTNode (for a subquery) and from an SQLStatement (as a top-level statement).

@nickolay
Copy link
Contributor

nickolay commented May 7, 2019

The branch I mentioned above has been merged, so SQLSelect / SQLQuery are separate structs now. Some ASTNode variants are still inlined though, but I'm not sure it makes sense to mechanically create a separate struct for each variant. Are there any variants where this is still a problem?

@alamb
Copy link
Contributor

alamb commented Dec 12, 2021

Closing as a dupe of #311 as suggested in #311 (comment)

@alamb alamb closed this as completed Dec 12, 2021
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

3 participants