unofficial mirror of 
 help / color / mirror / Atom feed
* PEG parsing reverse (generating a string) and other question
@ 2021-06-12 11:28 Zelphir Kaltstahl
  0 siblings, 0 replies; only message in thread
From: Zelphir Kaltstahl @ 2021-06-12 11:28 UTC (permalink / raw)
  To: Guile User

Hello Guile Users!

I currently have a project
<>), in which I am parsing
a text file using PEG parsing. (ice-9 peg) parsing gives me a data structure, a
nested list to work with and that is great. However, I know, that I later also
want to modify that data structure and then output something akin to what I read
and parsed.

I am aware, that where there is "choice" in parsing, like the (or ...) construct
or the (* ...) construct, there can be no "one correct way" to go the reverse
way, from data structure to string in file.

But I was wondering, whether there is any tooling, to be able to choose one
alternative output out of many, perhaps something "greedy", always choose the
first option when looking at the grammar. Or randomized even, only making sure,
that everything from my data structure lands back in the file at the end and
telling me, if that is not possible.

For example whitespace is often ignored in my grammar and I could not know,
whether the original file had 1, 2 or whatever amount of spaces between some
attributes I am parsing. So I could not know how many spaces to output, when
"generating" a string from my data structure. However, I could make a decision,
to only use the minimal amount of spaces (one space between attributes in my
case) and generate a string using such decisions.

Is there any tooling for generating a string from my peg-tree data structure?

Also I have one more question about peg-parsing: How would one go about making
sure something only appears once?

For example I have some entity, that is in the file written as: "id: 3000 hp:
50  times: 3  ratio: 1". Now I would like to make sure, that there is only one
"id: ..." and only one "hp: ..." and so on, without creating hundreds of PEG
patterns, distinguishing all the possible orders of attributes and so on.

Is there a simple way to achieve this?

Best regards,


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-12 11:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12 11:28 PEG parsing reverse (generating a string) and other question Zelphir Kaltstahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).