From: Ricardo Wurmus <rekado@elephly.net>
To: Danny Milosavljevic <dannym@scratchpost.org>
Cc: 34531@debbugs.gnu.org
Subject: bug#34531: Guix profile fails on Overdrive 1000
Date: Sat, 23 Feb 2019 12:20:06 +0100 [thread overview]
Message-ID: <87ef7y3g61.fsf@elephly.net> (raw)
In-Reply-To: <20190220230857.2282d9b1@scratchpost.org>
Danny Milosavljevic <dannym@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
next prev parent reply other threads:[~2019-02-23 11:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-18 20:05 bug#34531: Guix profile fails on Overdrive 1000 Andreas Enge
2019-02-18 20:49 ` Marius Bakke
2019-02-19 8:27 ` Andreas Enge
2019-02-19 13:23 ` Ricardo Wurmus
2019-02-19 15:19 ` Danny Milosavljevic
2019-02-20 10:51 ` Danny Milosavljevic
2019-02-20 11:46 ` Ricardo Wurmus
2019-02-20 13:26 ` Danny Milosavljevic
2019-02-20 15:56 ` Ricardo Wurmus
2019-02-20 16:26 ` Danny Milosavljevic
2019-02-20 20:53 ` Ricardo Wurmus
2019-02-20 22:08 ` Danny Milosavljevic
2019-02-20 22:28 ` Danny Milosavljevic
2019-02-23 11:20 ` Ricardo Wurmus [this message]
2019-02-24 10:40 ` Danny Milosavljevic
2019-02-24 11:45 ` Ricardo Wurmus
2019-02-24 12:12 ` Danny Milosavljevic
2019-02-26 21:07 ` Ricardo Wurmus
2019-02-20 13:28 ` Danny Milosavljevic
2019-02-19 15:35 ` Andreas Enge
2019-02-19 15:40 ` Danny Milosavljevic
2019-04-04 11:28 ` 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
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=87ef7y3g61.fsf@elephly.net \
--to=rekado@elephly.net \
--cc=34531@debbugs.gnu.org \
--cc=dannym@scratchpost.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 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).