Closed gwd closed 5 months ago
BTW, the following works for all tests:
type VersionSlice struct {
Range []VersionSingle `parser:"@@ ( VersionDash @@ )*"`
}
...
pVersionSlice := participle.MustBuild[VersionSlice](participle.Lexer(lexProject))
t.Log("Testing pVersionSlice with simple and range")
for _, in := range append(simpletests, rangetests...) {
out, err := pVersionSlice.ParseString("", in)
if err != nil {
t.Errorf("ERROR: Parsing %v: %v", in, err)
} else {
t.Logf("Parsing %v resulted in %v", in, out)
}
}
...
So I think I have a work-around for now; but if the first version is supposed to work, it would be good to track down what's going on.
First, thank you so much for this library -- made my first grammar on Friday and I think the setup really helped make things straightforward.
I'm using participle v2.10.0, and trying to write a parser for strings like the following:
i.e., a version that may be a single version, or a range (separated by
-
); that may be a single string, or<project> <version number>
.I wrote the following
participle
structures:Unfortunately, I get errors like the following:
In other words, it's somehow getting stuck on parsing something as a VersionRange, and not backing out and parsing it simply as a VersionSingle.
But this only happens if both Version and VersionSingle have at least two ways to be interpreted. If I replace the ProjectVersion with a single regexp that matches the same string, it works (here replacing the
Version
lexer token with aProjectVersion
token with the appropriate regexp).The problem for single items goes away if I get rid of the RangeVersion; but then of course you can't parse ranges:
Any idea what's going on?
For completeness, here's a complete testing function you can use to trigger the issue: