[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding wc to Bournish
From: |
Efraim Flashner |
Subject: |
Re: Adding wc to Bournish |
Date: |
Wed, 15 Jun 2016 23:28:14 +0300 |
User-agent: |
Mutt/1.6.1 (2016-04-27) |
On Wed, Jun 15, 2016 at 03:56:43PM +0200, Ludovic Courtès wrote:
> Efraim Flashner <address@hidden> skribis:
>
> > From 09eef9cd841a7d212e024be0609168611923696b Mon Sep 17 00:00:00 2001
> > From: Efraim Flashner <address@hidden>
> > 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!
I've attached another patch
>
> 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.
This part took much longer than I thought it would. Going forward I'll
try to be more pro-active on IRC about asking for help.
>
> 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?
>
I get lalr as look-ahead left->right parser and found this¹, but what's SILex?
I also found peg in the master branch of the guile manual².
> 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’.
¹
https://www.gnu.org/software/guile/manual/html_node/LALR_00281_0029-Parsing.html#LALR_00281_0029-Parsing
²
https://www.gnu.org/software/guile/docs/master/guile.html/PEG-Parsing.html#PEG-Parsing
--
Efraim Flashner <address@hidden> אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
0001-bournish-Add-wc-command.patch
Description: Text document
signature.asc
Description: PGP signature
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/05
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/05
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/07
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/08
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/14
- Re: Adding wc to Bournish, Ricardo Wurmus, 2016/06/14
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/14
- Re: Adding wc to Bournish, Efraim Flashner, 2016/06/14
- Re: Adding wc to Bournish, Ricardo Wurmus, 2016/06/14
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/15
- Re: Adding wc to Bournish,
Efraim Flashner <=
- Re: Adding wc to Bournish, Ludovic Courtès, 2016/06/23