unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Guile User <guile-user@gnu.org>
Subject: PEG parsing reverse (generating a string) and other question
Date: Sat, 12 Jun 2021 11:28:24 +0000	[thread overview]
Message-ID: <b7110ca3-76b9-81a9-703f-598b8e0b3f4f@posteo.de> (raw)

Hello Guile Users!

I currently have a project
(https://notabug.org/ZelphirKaltstahl/lf2-data-decrypt
<https://notabug.org/ZelphirKaltstahl/lf2-data-decrypt>), 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,
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl




                 reply	other threads:[~2021-06-12 11:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b7110ca3-76b9-81a9-703f-598b8e0b3f4f@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).