Make tracing trace whole sequences
andremarianiello opened this issue Β· comments
Right now the trace option only traces the first element of a sequence. This means tracing is not much help for debugging the behavior of later productions. It would be great if tracing worked on everything π
Right now the trace option only traces the first element of a sequence.
I was the author of a PR which was merged within the last couple of days that made some changes to tracing. If this is a new issue it is likely I introduced it, so if you can provide an example I'll open a PR to fix it
@andremarianiello can you please provide a reproducible minimal example?
I have no idea if this is new as I haven't used the tracing before this, but here is my example
main.go
package main
import (
"fmt"
"os"
"github.com/alecthomas/participle/v2"
)
type foo struct {
Bar bar `parser:"'{' @@ '}'"`
}
type bar struct {
Next *bar `parser:"'(' @@? ')'"`
}
func main() {
myfoo := foo{}
parser := participle.MustBuild(
&myfoo,
participle.Trace(os.Stdout),
)
err := parser.ParseString("", "{(((((((())))))))}", &myfoo)
if err != nil {
panic(err)
}
fmt.Println("successful parse")
}
stdout
"{" foo
"{" sequence{}
"{" literal{"{", "EOF"}
successful parse
It is appears that tracing is not happening when parsing the parens.
@andremarianiello Can you do me a favor and try this using the very tip of master
branch?
You'll need to make one small change - Trace
is a ParseOption
now (meaning you specify it per-parse, rather than when you construct the parser):
myfoo := foo{}
parser := participle.MustBuild(&myfoo)
err := parser.ParseString("", "{(((((((())))))))}", &myfoo, participle.Trace(os.Stdout))
if err != nil {
panic(err)
}
fmt.Println("successful parse")
The trace I get when I run it using the latest code is this:
"{" foo
"{" sequence{}
"{" literal{"{", "EOF"}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
"(" group{n?}
"(" capture{}
"(" bar
"(" sequence{}
"(" literal{"(", "EOF"}
")" group{n?}
")" capture{}
")" bar
")" sequence{}
")" literal{"(", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
")" literal{")", "EOF"}
"}" literal{"}", "EOF"}
This looks like what you want, right?
Yup, that looks right! Thanks for the quick resolution, and sorry for reporting an issue that was already fixed. I'll make sure to test with HEAD next time!