scsh-hackers
[Top] [All Lists]

[ scsh-Bugs-1047217 ] bug in simplify-regexp?

To: scsh-hackers@scsh.net
Subject: [ scsh-Bugs-1047217 ] bug in simplify-regexp?
From: "SourceForge.net" <noreply@sourceforge.net>
Date: Thu, 14 Oct 2004 10:58:46 -0700
List-id: Discussion among the implementors <scsh-hackers.list-id.scsh.net>
Sender: Nobody <nobody@sourceforge.net>
Bugs item #1047217, was opened at 2004-10-14 19:58
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=110493&aid=1047217&group_id=10493

Category: run-time
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Andreas Bernauer (interp)
Assigned to: Nobody/Anonymous (nobody)
Summary: bug in simplify-regexp?

Initial Comment:
As posted on scsh-users@scsh.net, I seem to have found
a bug in the regexp machinery of scsh.  The regular
expression tmprx does not work, but while the RE
tmp2rx, derived from tmprx, does:

Top level
;; 
> (fold (lambda (choice regexp)
                                (rx (| (submatch ,choice) ,regexp)))
                              (rx eos bos) ;; the regexp that never
                              ;; matches anything
                              '("yes" "no"))
'#{Re-choice}
> (define tmprx ##)
> (regexp-search tmprx "yes")

Error: exception
       wrong-type-argument
       (checked-record-ref '#{Re-choice} '#{Record-type
48 re-seq} 1)
1> (define tmp2rx (rx ,tmprx))
1> (regexp-search tmp2rx "yes")
'#{regexp-match}


Michel Schinz did some analysis on this already, from
which I quote here:

> (define ab-rx (fold (lambda (choice regexp)
                        (rx (| (submatch ,choice)
,regexp)))
                      (rx eos bos)
                      '("yes" "no")))
> (regexp->sre ab-rx)
'(| (submatch "no") (| "yes" (: eos bos)))

Now the reason why I think there is a problem:

----------------------------------------------------------------
> (simplify-regexp ab-rx)

Error: exception
       wrong-type-argument
       (checked-record-ref '#{Re-choice} '#{Record-type
48 re-seq} 1)
1> 
-----------------------------------------------------------------

Now, if I do a round-trip with regexp->sre and
sre->regexp (the composition of which should be the
identity function, as I understand it), it works:

-----------------------------------------------------------------
> (simplify-regexp (sre->regexp (regexp->sre ab-rx)))
'#{Re-choice}
> (regexp->sre ##)
'(| (submatch "no") "yes" (: eos bos))
-----------------------------------------------------------------

But it's still not what you want. What I proposed above
works, though:

-----------------------------------------------------------------
> (re-choice (map (lambda (s) (make-re-submatch
(re-string s)))
                  '("yes" "no")))
'#{Re-choice}
> (regexp->sre ##)
'(| (submatch "yes") (submatch "no"))
-----------------------------------------------------------------

See also the discussion on scsh-users@scsh.net, e.g. at
http://news.gmane.org/find-root.php?message_id=%3cd3hdp1vhqz.fsf%40informatik.uni%2dtuebingen.de%3e


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=110493&aid=1047217&group_id=10493

<Prev in Thread] Current Thread [Next in Thread>
  • [ scsh-Bugs-1047217 ] bug in simplify-regexp?, SourceForge.net <=