Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Update indent.rs in order to have a proper Pratt parser#808

Open
Germ210 wants to merge 1 commit intozesterer:mainfrom
Germ210:main
Open

Update indent.rs in order to have a proper Pratt parser#808
Germ210 wants to merge 1 commit intozesterer:mainfrom
Germ210:main

Conversation

@Germ210
Copy link
Copy Markdown

@Germ210 Germ210 commented May 29, 2025

This rewrites indent.rs to use a real Pratt parser. Previously, the file had a TODO noting that it should eventually use expression parsing, but in the meantime it didn’t actually implement any precedence rules—it just matched the text "expr" directly. This change introduces proper precedence handling using a Pratt parser, making the indentation-sensitive parser more accurate and extensible, while keeping the overall behavior consistent.

@zesterer
Copy link
Copy Markdown
Owner

zesterer commented Jun 11, 2025

Hi, looks like you need to enable the pratt feature for the indent example in Cargo.toml.

My feeling is that we should keep the pratt parser here simple, simpler than this example (perhaps just + and * is fine). The pratt parser is not the focus of the example and shouldn't really 'stand out'.

Comment thread examples/indent.rs
Comment on lines +73 to +76
*1 + -2 * 3!
loop:
10

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It's important to also show that trailing expressions work here too (i.e: expressions that appear after a nested block). I'd suggest something like the following example:

loop:
    1 + 2 * 3
    loop:
        10 + 3
    42 * 3
3 + 2 * 9

Copy link
Copy Markdown
Author

@Germ210 Germ210 Jun 13, 2025

Choose a reason for hiding this comment

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

Alright, I can add that later, but in the original parser (and presumably this one), when given the input:

expr
expr  
loop:  
expr  

It will output the tree:

Some(
    [
        Expr,
        Expr,
        Loop(
            [
                Expr,
            ],
        ),
    ],
)

Is this the intended behavior? I would assume that in order to be nested, it would need to have the corresponding indentation? Or is this intentional?

@zesterer zesterer force-pushed the main branch 2 times, most recently from 0f2b61a to e350fc6 Compare November 5, 2025 19:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants