Skip to content

Ensure Grammar Matching is Complete #345

@SJrX

Description

@SJrX

The current implementation of our grammar using parser combinators, is not complete, because it's is greedy.

For instance the following:

Seq(ZeroOrMore("a"),"a")

And the string "aa" . The Zero or More will gobble the both as, the second part of Seq won't match and we will be done.

My recollection from Mastering Regular Expressions is that the two different Regex engines DFA and NFA solve this in different ways, a DFA based approach (and this might be backwards), builds every possible match in memory and keeps track of it as it goes through. An NFA approach involves backtracking.

I think we just want something ... simple, but I'm unclear exactly how to build this with Parser Combinators.

One ... gross idea I had is I could maybe map each combinator to a Regex fragment, then build a giant regex. This didn't seem like it would 'teach' me anything, and also at one point I thought maybe there were some combinators that couldn't be Regexs

It sees like I might need to build either backtracking or "building up everything into memory" manually.

Image

I suspect that #343 would benefit from "building up everything into memory" approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions