all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Efraim Flashner <efraim@flashner.co.il>
Cc: guix-devel@gnu.org, David Thompson <davet@gnu.org>
Subject: Re: Adding wc to Bournish
Date: Wed, 15 Jun 2016 15:56:43 +0200	[thread overview]
Message-ID: <87shwed084.fsf@gnu.org> (raw)
In-Reply-To: <20160614105037.GC10636@debian-netbook> (Efraim Flashner's message of "Tue, 14 Jun 2016 13:50:37 +0300")

Efraim Flashner <efraim@flashner.co.il> skribis:

> From 09eef9cd841a7d212e024be0609168611923696b Mon Sep 17 00:00:00 2001
> From: Efraim Flashner <efraim@flashner.co.il>
> Date: Sun, 22 May 2016 14:56:06 +0300
> Subject: [PATCH] bournish: Add `wc' command.
>
> * guix/build/bournish.scm (lines+chars, only-files, wc-commands,
> wc-command-implementation, wc-l-command-implementation,
> wc-c-command-implementation): New variables.

s/variables/procedures/ :-)

> (%commands): Add wc command.

[...]

> +(define (only-files files)
> +  (filter (lambda (file)
> +            (catch 'system-error
> +              (lambda ()
> +                (stat file))
> +              (lambda args
> +                (let ((errno (system-error-errno args)))
> +                  (format (current-error-port) "~a: ~a~%"
> +                          file (strerror errno))
> +                  #f))))
> +          files))
> +
> +(define (wc-command-implementation . files)
> +  (for-each
> +    (lambda (file)
> +      (let-values (((lines chars)
> +                    (call-with-input-file file lines+chars)))
> +                  (format #t "~a ~a ~a~%" lines chars file)))
> +    ((@@ (guix build bournish) only-files) files)))

I prefer the approach Ricardo suggested, I think it’s more concise and
clearer:

  https://lists.gnu.org/archive/html/guix-devel/2016-06/msg00525.html

Also, note that @@ would not be needed here; @@ serves to access private
bindings within a specific module:

  https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.html

Last, do not miss the bit about docstrings at:

  https://www.gnu.org/software/guix/manual/html_node/Formatting-Code.html

:-)

With these changes, we’re all set.  Thanks!

From a GSoC viewpoint, I think we must move to the compilation part
now.  Specifically, I think the next step is to start parsing Bash
code.

For that we could use SILex + parse-lalr, but these are not the nicest
tools for the job.  Better tools would be “parsing expression grammars”
(the (ice-9 peg) module in Guile 2.1) or parser combinators, though I
don’t think there’s a directly usable Guile library for that.  Maybe
Eric or David can comment?

The goal is to have a parser that returns an abstract syntax tree (AST)
as an sexp:

  (parse "(cd /foo; ls $HOME) && echo *.a ; echo done")
  =>
  '(sequence
     (success-sequence
       (subshell
         (sequence (command "cd" "/foo")
                   (command "ls" (variable-ref "HOME"))))
       (command "echo" (glob "*.a")))
     (command "echo" "done"))

Thoughts?

Ludo’.

  parent reply	other threads:[~2016-06-15 13:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24 18:47 Adding wc to Bournish Efraim Flashner
2016-05-25  9:03 ` Ricardo Wurmus
2016-05-25  9:43   ` Efraim Flashner
2016-05-25  9:26 ` Ricardo Wurmus
2016-05-25 10:05   ` Efraim Flashner
2016-05-26  8:46 ` Ludovic Courtès
2016-05-26 17:50   ` Efraim Flashner
2016-05-26 19:27 ` Efraim Flashner
2016-05-27 13:37   ` Eric Bavier
2016-05-27 15:28     ` Taylan Ulrich Bayırlı/Kammer
2016-05-27 15:32       ` Thompson, David
2016-06-05 12:40 ` Efraim Flashner
2016-06-05 20:37   ` Ludovic Courtès
2016-06-07  7:41     ` Efraim Flashner
2016-06-08 15:43       ` Ludovic Courtès
2016-06-14  9:27         ` Efraim Flashner
2016-06-14  9:57           ` Ricardo Wurmus
2016-06-14 10:20             ` Efraim Flashner
2016-06-14 10:50               ` Efraim Flashner
2016-06-14 11:08                 ` Ricardo Wurmus
2016-06-15 13:56                 ` Ludovic Courtès [this message]
2016-06-15 20:28                   ` Efraim Flashner
2016-06-23  8:34                     ` Ludovic Courtès

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

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

  git send-email \
    --in-reply-to=87shwed084.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=davet@gnu.org \
    --cc=efraim@flashner.co.il \
    --cc=guix-devel@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.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.