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 pretty print AST for debugging AST in CLI #976

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

krishvishal
Copy link
Contributor

@krishvishal krishvishal commented Feb 10, 2025

Why: @alpaylan wanted a way to pretty print AST in CLI for debugging purposes.

Usage and output:

Limbo v0.0.14
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> .pprint "SELECT 1;"

=== Input SQL ===
SELECT 1;

=== AST ===
Select(
    Select {
        with: None,
        body: SelectBody {
            select: Select(
                SelectInner {
                    distinctness: None,
                    columns: [
                        Expr(
                            Literal(
                                Numeric(
                                    "1",
                                ),
                            ),
                            None,
                        ),
                    ],
                    from: None,
                    where_clause: None,
                    group_by: None,
                    window_clause: None,
                },
            ),
            compounds: None,
        },
        order_by: None,
        limit: None,
    },
)
limbo> 

@krishvishal krishvishal changed the title Pretty print AST for debugging AST in CLI Add pretty print AST for debugging AST in CLI Feb 10, 2025
@@ -101,6 +102,12 @@ impl std::fmt::Display for OutputMode {
}
}

macro_rules! dbg_string {
($val:expr) => {{
format!("{:#?}", $val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used just the one time on ln436?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Its only used once.

@krishvishal
Copy link
Contributor Author

Fixed merge conflicts.

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.

2 participants