Re: Quirk with printing regexps

2013-04-01 Thread Mark Engelberg
On Mon, Apr 1, 2013 at 1:00 AM, Michał Marczyk wrote: > Could you just preprocess the strings passed to re-pattern (or > patterns if you're getting those as input) to replace literal newlines > with escape sequences? I'm assuming you don't care about ?x given the > result you wish to achieve. > T

Re: Quirk with printing regexps

2013-04-01 Thread Michał Marczyk
(The examples from the REPL still apply.) On 1 April 2013 10:15, Michał Marczyk wrote: > Oh, wait, I posted the wrong function. Here's the one I meant: > > (defn pr-pattern [pat] > (pr (re-pattern (.replaceAll (re-matcher (re-pattern "\n") >(.toStrin

Re: Quirk with printing regexps

2013-04-01 Thread Michał Marczyk
Oh, wait, I posted the wrong function. Here's the one I meant: (defn pr-pattern [pat] (pr (re-pattern (.replaceAll (re-matcher (re-pattern "\n") (.toString pat)) "n" On 1 April 2013 10:00, Michał Marczyk wrote:

Re: Quirk with printing regexps

2013-04-01 Thread Michał Marczyk
On 1 April 2013 07:53, Mark Engelberg wrote: > Yeah, my goal is simply to get (re-pattern #"a\nb") to print (or more > precisely, pr) as #"a\nb" without affecting the semantics of printing other > regular expressions, but that seems to be impossible to achieve. Sigh... Could you just preprocess

Re: Quirk with printing regexps

2013-03-31 Thread Mark Engelberg
On Sun, Mar 31, 2013 at 10:46 PM, Andy Fingerhut wrote: > If you print it as a string, then want to read it back in and convert back > to a regex, you must read it as a string, then call re-pattern on it. That > should preserve the original meaning. > > Printing it as a string, and trying to read

Re: Quirk with printing regexps

2013-03-31 Thread Andy Fingerhut
If you print it as a string, then want to read it back in and convert back to a regex, you must read it as a string, then call re-pattern on it. That should preserve the original meaning. Printing it as a string, and trying to read it as a regex by prepending it directly with # before the " of th

Re: Quirk with printing regexps

2013-03-31 Thread Mark Engelberg
On Sat, Mar 30, 2013 at 11:33 AM, Mark Engelberg wrote: > On Thu, Mar 28, 2013 at 6:36 PM, Andy Fingerhut > wrote: > >> (defn print-regex-my-way [re] >> (print "#regex ") >> (pr (str re))) >> >> That might be closer to what you want. >> > > Yes. That does the trick. That extra level of conv

Re: Quirk with printing regexps

2013-03-30 Thread Mark Engelberg
On Thu, Mar 28, 2013 at 6:36 PM, Andy Fingerhut wrote: > (defn print-regex-my-way [re] > (print "#regex ") > (pr (str re))) > > That might be closer to what you want. > Yes. That does the trick. That extra level of converting the regular expression to a string does the trick because pr "doe

Re: Quirk with printing regexps

2013-03-30 Thread Mark Engelberg
On Thu, Mar 28, 2013 at 7:52 PM, Mikhail Kryshen wrote: > On Thu, 28 Mar 2013 17:08:46 -0700 > Mark Engelberg wrote: > > > Bug or feature? > > Certainly a feature for complex patterns with whitespace and embedded > comments. > > For example, the following regexp parses line in Combined Log Format

Re: Quirk with printing regexps

2013-03-28 Thread Mikhail Kryshen
On Thu, 28 Mar 2013 17:08:46 -0700 Mark Engelberg wrote: > Bug or feature? Certainly a feature for complex patterns with whitespace and embedded comments. For example, the following regexp parses line in Combined Log Format used by Apache httpd and other web servers: (def clf-pattern #"(?x)^

Re: Quirk with printing regexps

2013-03-28 Thread Mikhail Kryshen
On Fri, 29 Mar 2013 05:32:52 +0400 Mikhail Kryshen wrote: > (re-pattern "a\nb") returns regexp pattern that contains the newline > char literally. > > (re-patter "a\\\nb") returns pattern that contains '\n' (two-char > sequence). ^ should be (re-pattern "a\\nb"). And (re-pattern "a\\\nb") re

Re: Quirk with printing regexps

2013-03-28 Thread Andy Fingerhut
On Thu, Mar 28, 2013 at 6:23 PM, Mark Engelberg wrote: > On Thu, Mar 28, 2013 at 6:16 PM, Andy Fingerhut > wrote: > >> When you say a "sane, readable way", do you mean human-readable, or >> readable via clojure.core/read or clojure.core/read-string? >> > > I meant human readable > > >> >> (defn p

Re: Quirk with printing regexps

2013-03-28 Thread Mikhail Kryshen
(re-pattern "a\nb") returns regexp pattern that contains the newline char literally. (re-patter "a\\\nb") returns pattern that contains '\n' (two-char sequence). These are not the same. '\n' always matches newline, while literal newline will be ignored if ?x flag is present. => (re-matches (re-p

Re: Quirk with printing regexps

2013-03-28 Thread Mark Engelberg
On Thu, Mar 28, 2013 at 6:16 PM, Andy Fingerhut wrote: > When you say a "sane, readable way", do you mean human-readable, or > readable via clojure.core/read or clojure.core/read-string? > I meant human readable > > (defn print-regex-my-way [re] > (print "#regex \"" (str re) "\"")) > If you

Re: Quirk with printing regexps

2013-03-28 Thread Andy Fingerhut
On Thu, Mar 28, 2013 at 5:49 PM, Mark Engelberg wrote: > I'm on 1.5.1 and I get that too, but even though: > (pr #"a\nb") prints in a sane, readable way > (pr (re-pattern "a\nb")) does not. > > The latter is what I need to print in a nice way. > Sorry, I missed that fine point. When you say a "s

Re: Quirk with printing regexps

2013-03-28 Thread Alan Malloy
On Thursday, March 28, 2013 5:36:45 PM UTC-7, Andy Fingerhut wrote: > > I don't understand why (re-pattern "a\\\nb") would match the same thing. > I would have guessed that it wouldn't, but it does indeed do so. For all I > know that could be bug or weird dark corner case in the Java regex >

Re: Quirk with printing regexps

2013-03-28 Thread Mark Engelberg
I'm on 1.5.1 and I get that too, but even though: (pr #"a\nb") prints in a sane, readable way (pr (re-pattern "a\nb")) does not. The latter is what I need to print in a nice way. On Thu, Mar 28, 2013 at 5:42 PM, Andy Fingerhut wrote: > On Thu, Mar 28, 2013 at 5:15 PM, Mark Engelberg > wrote:

Re: Quirk with printing regexps

2013-03-28 Thread Andy Fingerhut
On Thu, Mar 28, 2013 at 5:15 PM, Mark Engelberg wrote: > On Thu, Mar 28, 2013 at 5:08 PM, Mark Engelberg > wrote: > >> However, the first and last example print as: >> #"a >> b" >> > > Follow up question: > Is there any way to make (re-pattern "a\nb") print as #"a\nb"? > > I've tried pr, print-du

Re: Quirk with printing regexps

2013-03-28 Thread Andy Fingerhut
Look in the Clojure source, file LispReader.java, classes RegexReader and StringReader for the code that reads strings and regular expressions. Basically the difference for regular expressions is that since things like \d to match a single decimal digit, or \s to match a single whitespace characte

Re: Quirk with printing regexps

2013-03-28 Thread Mark Engelberg
On Thu, Mar 28, 2013 at 5:08 PM, Mark Engelberg wrote: > However, the first and last example print as: > #"a > b" > Follow up question: Is there any way to make (re-pattern "a\nb") print as #"a\nb"? I've tried pr, print-dup, and various combinations of printing the outputs of those under with-ou