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

Explore and documentation what Backtrackable means #3

Open
MangelMaxime opened this issue Jul 21, 2024 · 1 comment
Open

Explore and documentation what Backtrackable means #3

MangelMaxime opened this issue Jul 21, 2024 · 1 comment

Comments

@MangelMaxime
Copy link
Contributor

  • Describe what Backtrackable does
  • Create examples / matrice of what is the result of the different composition functions in regards of Backtrackable state
    • oneOf
    • map
    • map2
    • andThen
    • etc.
@MangelMaxime
Copy link
Contributor Author

MangelMaxime commented Jul 21, 2024

Parser.token seems to be a good place to understand what Backtrackable means.

However, I would say there is a conflict in the naming between progress and Backtrackable. Also, why is the decision based on the input str and not on result of findSubString.

Is it to protect user code from empty tokens ?

    let token (Token(str, expecting)) : Parser<'Context, 'Problem, unit> =
        ParserFunc
        <| fun state ->
            let progress = not (String.isEmpty str)

            let result = findSubString str state.Offset state.Row state.Column state.Source

            match result with
            | SubStringResult.NoMatch _ ->
                ParserStep.Failed
                    {
                        Backtrackable = false
                        Bag = fromState state expecting
                    }

            | SubStringResult.Match result ->
                ParserStep.Success
                    {
                        Backtrackable = progress
                        Value = ()
                        State =
                            { state with
                                Offset = result.Offset
                                Row = result.Row
                                Column = result.Column
                            }
                    }

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

1 participant