From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: PEG parsing reverse (generating a string) and other question Date: Sat, 12 Jun 2021 11:28:24 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11635"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jun 12 13:28:56 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ls1ou-0002pj-FA for guile-user@m.gmane-mx.org; Sat, 12 Jun 2021 13:28:56 +0200 Original-Received: from localhost ([::1]:48344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ls1ot-0007w5-HA for guile-user@m.gmane-mx.org; Sat, 12 Jun 2021 07:28:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls1oZ-0007vv-6g for guile-user@gnu.org; Sat, 12 Jun 2021 07:28:36 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:37427) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ls1oV-0004VM-32 for guile-user@gnu.org; Sat, 12 Jun 2021 07:28:34 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 14AF7240027 for ; Sat, 12 Jun 2021 13:28:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1623497306; bh=ac999WQNZZ2jhzD5R+UTRwu17AT8AF9HO0F0/lryTw4=; h=To:From:Subject:Date:From; b=o7S34dEA5+5HVzpB4+1FASIG9Ch0QdlKsDL+BWsWYS3MP5ryOBbXlXOEXLhhXLkd0 gK7jpmd8EFeidI1nPz/IOza+3wcT/0mgW5mXg36VY/HW3bXvQvs8g+34/y7RMx60P6 xOAWuGXX9J5gtvIg2/Im/Ct5FuQ8YT6lBbuSjWsDZRvuf/dr70DfVMsZUOMNbfHpwH l+pbMcKlNWlfGZeHWacALDHxZau56H0NINSm7jhzDXTebbnfPpYu3VTXvDngJ+/vm3 hxwBvRxDbQpJOrxIX5MN55rD/kaMzCMnxLH/CW9V+SbRW9bf+4DCf7NYhBy+UMTMJj agpvknUgs2SUQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4G2Fp14G6sz9rxM for ; Sat, 12 Jun 2021 13:28:25 +0200 (CEST) Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17597 Archived-At: Hello Guile Users! I currently have a project (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