unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Leo Prikler <leo.prikler@student.tugraz.at>
To: magalilemes00@gmail.com
Cc: guix-devel@gnu.org
Subject: [Outreachy] Strategy to implement guix git log --pretty=<string>
Date: Wed, 06 Jan 2021 09:10:58 +0100	[thread overview]
Message-ID: <4bc2714885700ada6c72e19771789fda0ee634be.camel@student.tugraz.at> (raw)
In-Reply-To: c2de6cf1-b8af-5008-ebbd-d1c587ce1064@gmail.com

Hello Magali,

have you looked into (ice-9 peg)?  An easy pretty grammar, that would
catch your example would be the following:

--8<---------------cut here---------------start------------->8---
(use-modules (ice-9 peg))

(define-peg-pattern commit-hash all (ignore "%h"))
(define-peg-pattern subject all (ignore "%s"))

(define-peg-pattern pretty body
  (* (or commit-hash
         subject
         (* (and (not-followed-by "%") peg-any)))))

(peg:tree (match-pattern pretty "%h %s")) ;; => (commit-hash " "
subject)
--8<---------------cut here---------------end--------------->8---

Of course you have to extend it with all the other percent escapes.
Then you simply map a match-lambda over the "tree", which if given a
symbol returns a string containng the actual value and if given a
string returns the string unchanged.  Finally you string-concatenate
them.  Naturally, you have to check whether the string was valid as
well -- a lone "%" should not match, for instance.

Cheers,
Leo



             reply	other threads:[~2021-01-06  8:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06  8:10 Leo Prikler [this message]
2021-01-18 14:45 ` [Outreachy] Strategy to implement guix git log --pretty=<string> zimoun
  -- strict thread matches above, loose matches on Subject: below --
2021-01-06  4:35 Magali
2021-01-06  8:03 ` Gábor Boskovits
2021-01-14 21:29 ` Ludovic Courtès
2021-01-18 15:02   ` zimoun

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://guix.gnu.org/

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

  git send-email \
    --in-reply-to=4bc2714885700ada6c72e19771789fda0ee634be.camel@student.tugraz.at \
    --to=leo.prikler@student.tugraz.at \
    --cc=guix-devel@gnu.org \
    --cc=magalilemes00@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

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).