[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Outreachy] Strategy to implement guix git log --pretty=<string>
From: |
Leo Prikler |
Subject: |
[Outreachy] Strategy to implement guix git log --pretty=<string> |
Date: |
Wed, 06 Jan 2021 09:10:58 +0100 |
User-agent: |
Evolution 3.34.2 |
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