Replies: 2 comments 2 replies
-
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. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm not sure if this is still an issue, or what the exact problem is, but one thing that stands out to me is that your lexer is too complex. It's best to keep your lexer very straightforward, and only match very simple tokens. For example I would expect something more like this: var rulesCommon = []lexer.SimpleRule{
{"Ident", `\w+`},
{"Number", `\d+`},
{"Punct", "[-.]"}, // Maybe more?
{"Space", ` `},
} Then move the more complex matching into the parser: type ProjectVersion struct {
Project string `parser:"@('Xen'|'Linux'|'QEMU'|'xapi')'"`
Version string `parser:"Space @(....)"`
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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:
Beta Was this translation helpful? Give feedback.
All reactions