GNU bug report logs - #34531
Guix profile fails on Overdrive 1000

Previous Next

Package: guix;

Reported by: Andreas Enge <andreas <at> enge.fr>

Date: Mon, 18 Feb 2019 20:07:01 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #53 received at 34531 <at> debbugs.gnu.org (full text, mbox):

From: Ricardo Wurmus <rekado <at> elephly.net>
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 34531 <at> debbugs.gnu.org, Andreas Enge <andreas <at> enge.fr>
Subject: Re: bug#34531: Guix profile fails on Overdrive 1000
Date: Sat, 23 Feb 2019 12:20:06 +0100
Danny Milosavljevic <dannym <at> scratchpost.org> writes:

> (define (skip-comments text)
>   (replace (string-append "//[^\n]*?|"
>                           "/[*].*?[*]/|"
>                           "'([.]|[^'])*?'|"
>                           "\"([.]|[^\"])*?\"")

This last part will remove anything between double quotes, such as every
string.  Another problem seems to be the handling of /* comments */.
It’s a greedy regex that will swallow any character until it finally
hits */ — even if the characters in between may have been */.

I would not use regular expressions here but a read loop such as this:

--8<---------------cut here---------------start------------->8---
(define (strip-comments port)
  (let loop ((char (get-char port))
             (balance 0)
             (chars '()))
    (cond
     ;; done!
     ((eof-object? char)
      (list->string (reverse chars)))
     ;; line comment
     ((and (equal? char #\/)
           (equal? #\/ (peek-char port)))
      (begin (read-line port)
             (loop (get-char port) balance chars)))
     ;; begin of block comment
     ((and (equal? char #\/)
           (equal? #\* (peek-char port)))
      (begin (read-char port)
             (loop (get-char port) (1+ balance) chars)))
     ;; end of block comment
     ((and (positive? balance)
           (equal? char #\*)
           (equal? #\/ (peek-char port)))
      (begin (read-char port)
             (loop (get-char port) (1- balance) chars)))
     ;; inside block comment
     ((positive? balance)
      (loop (get-char port) balance chars))
     ;; just a plain ol’ character
     (else (loop (get-char port) balance (cons char chars))))))

;; Strip all comments from the file “fname” and show the result.
(display (call-with-input-file fname strip-comments))
--8<---------------cut here---------------end--------------->8---

--
Ricardo





This bug report was last modified 6 years and 52 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.