Skip to content

New interface for Pratt #171

@Whiteknight

Description

@Whiteknight

Consider an interface like this for setting up a TDOP with Pratt:

var parser = OperatorPrecidence(c => c
    .Level(l => l
        .Left(Number())
    )
    .Level(l => l
        .Left(Match('-'), (ctx, state, token) => { ... })
    )
    .Level(l => l
        .Right(Match('+'), (ctx, state, token) => { ... })
        .Right(Match('-'), (ctx, state, token) => { ... })
    )
    .Level(l => l
        .Right(Match('*'), (ctx, state, token) => { ... })
        .Right(Match('/'), (ctx, state, token) => { ... })
    )
    .Level(l => l
        .RightAssociative(r => r
            .Right(Match('.'), (ctx, state, token) => { ... })
       )
    )
);

With a setup like this, we don't have to manually change precedence levels every time we want to insert something into the table, we just add a new .Level() call and everything just works. Need to do some work on the Left/Right associativity though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestexploratoryWe might do it, pending investigation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions