Closed michael-brade closed 6 years ago
Ok, forget it. It seems it was my fault: passing QPlainTextEdit::toPlainText().toStdString()
directly to pegtl::memory_input
creates a temporary that is destroyed too soon. Why it works with up to 15 spaces I have no idea. Just for the record, the correct and working code is:
QByteArray data = source->toPlainText().toUtf8();
pegtl::memory_input module(data.data(), "source");
The QByteArray
now holds the data long enough and is not a temporary anymore.
Interesting. Well, it's a bit unfortunate that memory_input
accepts an rvalue std::string
, I guess I'll add a deleted overload to prevent that in the future.
What you probably wanted is a string_input
which copies/moves its argument into itself. Anyways, you figured out the root cause so you already have a solution. :)
Yes exactly! I also had that idea - taking a const std::string &
and copying the .data()
pointer out of it is kind of mean :)
Hi, I am currently trying to find out why my seemingly correct grammar won't parse. Here's the first issue that I don't understand: take the JSON grammar as an example and start with 16 spaces:
It fails with:
Note
5 4 source:1:0(0) failure tao::pegtl::json::ws
: it fails already at the first space! If you delete one space, it works.