Hello,
I need help with constructing an npeg parser.
I am able to create a parser that matches consecutive matches of a given pattern. But I am unable to create one that allows random text before/inbetween/after the pattern matches.
You can see my attempts in this minimal reproducible example: https://play.nim-lang.org/#ix=2VdK
In there, p1 is the simple parser that parsers only consecutive occurrences of patterns in the provided text.
p2 is the failed attempt where I need to allow any number of arbitrary text lines before each "record".
Can someone please help the p2 parser so that the doAssert at the end of it passes?
Thanks!
cc: @zevv
Thanks, that fix helped me instantly fix the parsing of a 55k lines log file. I really appreciate your prompt help. Your fixed version makes a lot of sense. I had been dabbling with putting the "random" in the record and also in the main "records" sequence, but I never came across the +(record | random) variant in my experiments :)
This is just beautiful.. thousands of lines parsed in a snap!
Thanks @zevv for this wonderful package.
(Next step: parse the records to JSON and then to HTML.)
Not sure why you're going via JSON to HTML though.
May be you are wondering that based on the example above. The actual parsed object is more complex: It's nested objects and some of those objects have seq type members.
I am thinking that JSON would be a good intermediate format. The final HTML is for sharing the parsed data for others to study. Idea is to convert JSON into HTML tables (which can contain nested tables).
I need to still finalize the structure of the nested data.
To parse it into JSON all you need to do is change how the Record type is generated, should be pretty easy.
+1
I haven't yet reached that point. But yes, the Json type is easy to play with.