Double Backslash example patch

Started by David Fetterabout 22 years ago17 messages
#1David Fetter
david@fetter.org
1 attachment(s)

Kind people,

Please find enclosed a patch exemplifying typical use of the ARE
Class-Shorthand Escapes��. I believe it will help intrepid regex
users. :)

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

Attachments:

are_example.difftext/plain; charset=us-asciiDownload
Index: func.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/func.sgml,v
retrieving revision 1.180
diff -2 -c -r1.180 func.sgml
*** func.sgml	29 Nov 2003 19:51:37 -0000	1.180
--- func.sgml	7 Dec 2003 01:46:46 -0000
***************
*** 2634,2638 ****
       regular expression is allowed to match anywhere within a string, unless
       the regular expression is explicitly anchored to the beginning or
!      end of the string.
      </para>
  
--- 2634,2640 ----
       regular expression is allowed to match anywhere within a string, unless
       the regular expression is explicitly anchored to the beginning or
!      end of the string.  The last example includes a double backslash,
!      which is usually required for using ARE shorthand <xref
!      linkend="posix-class-shorthand-escapes-table">.
      </para>
  
***************
*** 2644,2647 ****
--- 2646,2650 ----
  'abc' ~ '(b|d)'  <lineannotation>true</lineannotation>
  'abc' ~ '^(b|c)' <lineannotation>false</lineannotation>
+ '123' ~ '^\\d{3}' <lineannotation>true</lineannotation>
  </programlisting>
     </para>
#2Peter Eisentraut
peter_e@gmx.net
In reply to: David Fetter (#1)
Re: Double Backslash example patch

David Fetter wrote:

Please find enclosed a patch exemplifying typical use of the ARE
Class-Shorthand Escapes®. I believe it will help intrepid regex
users. :)

If you want to explain something, it's normally better to create an
example just for that point, instead of piggybacking it onto another
example. Else you just make it harder for people to recognize the
relevant information.

For instance, in the case you want to patch the example aims to show how
patterns are not anchored, as opposed to the pattern for the LIKE
operator. What does the escape syntax of the pattern have to do with
that?

#3Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Peter Eisentraut (#2)
Re: Double Backslash example patch

Peter Eisentraut wrote:

David Fetter wrote:

Please find enclosed a patch exemplifying typical use of the ARE
Class-Shorthand Escapes??. I believe it will help intrepid regex
users. :)

If you want to explain something, it's normally better to create an
example just for that point, instead of piggybacking it onto another
example. Else you just make it harder for people to recognize the
relevant information.

For instance, in the case you want to patch the example aims to show how
patterns are not anchored, as opposed to the pattern for the LIKE
operator. What does the escape syntax of the pattern have to do with
that?

He is reminding folks about double-backslashes in a relivant place ---
makes sense to me.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#4Bruce Momjian
pgman@candle.pha.pa.us
In reply to: David Fetter (#1)
Re: Double Backslash example patch

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

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

David Fetter wrote:

Kind people,

Please find enclosed a patch exemplifying typical use of the ARE
Class-Shorthand Escapes��. I believe it will help intrepid regex
users. :)

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#5Peter Eisentraut
peter_e@gmx.net
In reply to: Bruce Momjian (#4)
Re: Double Backslash example patch

Bruce Momjian writes:

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

Please don't.

Add a new example if you want, but don't overload existing examples with
unrelated information.

Show quoted text

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

David Fetter wrote:

Kind people,

Please find enclosed a patch exemplifying typical use of the ARE
Class-Shorthand Escapes®. I believe it will help intrepid regex
users. :)

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

[ Attachment, skipping... ]

---------------------------(end of
broadcast)--------------------------- TIP 4: Don't 'kill -9' the
postmaster

--
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 359-1001
+  If your life is a hard drive,     |  13 Roberts Road
+  Christ can be your backup.        |  Newtown Square, Pennsylvania
19073
#6Peter Eisentraut
peter_e@gmx.net
In reply to: Bruce Momjian (#3)
Re: Double Backslash example patch

Bruce Momjian wrote:

He is reminding folks about double-backslashes in a relivant place
--- makes sense to me.

The relevant place would be far below where it already says:

Note: Keep in mind that an escape's leading \ will need to be doubled
when entering the pattern as an SQL string constant.

So it's already covered.

#7David Fetter
david@fetter.org
In reply to: Peter Eisentraut (#6)
Re: Double Backslash example patch

On Tue, Dec 16, 2003 at 04:32:37PM +0100, Peter Eisentraut wrote:

Bruce Momjian wrote:

He is reminding folks about double-backslashes in a relivant place
--- makes sense to me.

The relevant place would be far below where it already says:

Note: Keep in mind that an escape's leading \ will need to be
doubled when entering the pattern as an SQL string constant.

So it's already covered.

With all due respect, Peter, it is only implicit in the docs, and that
is not always good enough. An explicit example will help, as
PostgreSQL's quoting system would qualify for an early place on the
'gotchas' page (cf. http://sql-info.de/mysql/gotchas.html) if
PostgreSQL had one.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

#8Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: David Fetter (#7)
Re: [PATCHES] Double Backslash example patch

On Tue, Dec 16, 2003 at 11:17:11AM -0800, David Fetter wrote:

[Moved to hackers -- this belongs to -docs anyway, doesn't it?]

With all due respect, Peter, it is only implicit in the docs, and that
is not always good enough. An explicit example will help, as
PostgreSQL's quoting system would qualify for an early place on the
'gotchas' page (cf. http://sql-info.de/mysql/gotchas.html) if
PostgreSQL had one.

BTW, what happened to the $QUOTE$ quoting idea? Was it applied, or
even developed?

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"The problem with the future is that it keeps turning into the present"
(Hobbes)

#9Peter Eisentraut
peter_e@gmx.net
In reply to: David Fetter (#7)
Re: Double Backslash example patch

David Fetter wrote:

With all due respect, Peter, it is only implicit in the docs, and
that is not always good enough. An explicit example will help, as

Sure, I'm just pointing out the most appropriate place to put it.

#10Jon Jensen
jon@endpoint.com
In reply to: Alvaro Herrera (#8)
Re: [PATCHES] Double Backslash example patch

On Tue, 16 Dec 2003, Alvaro Herrera wrote:

BTW, what happened to the $QUOTE$ quoting idea? Was it applied, or
even developed?

I believe it's still on the to-do list, but was pushed off until 7.5 or
whenever it gets done.

Jon

#11Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Alvaro Herrera (#8)
Re: [PATCHES] Double Backslash example patch

Alvaro Herrera wrote:

On Tue, Dec 16, 2003 at 11:17:11AM -0800, David Fetter wrote:

[Moved to hackers -- this belongs to -docs anyway, doesn't it?]

With all due respect, Peter, it is only implicit in the docs, and that
is not always good enough. An explicit example will help, as
PostgreSQL's quoting system would qualify for an early place on the
'gotchas' page (cf. http://sql-info.de/mysql/gotchas.html) if
PostgreSQL had one.

BTW, what happened to the $QUOTE$ quoting idea? Was it applied, or
even developed?

Not implemented yet.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#8)
Re: [PATCHES] Double Backslash example patch

Alvaro Herrera <alvherre@dcc.uchile.cl> writes:

BTW, what happened to the $QUOTE$ quoting idea? Was it applied, or
even developed?

I'd like to see it done for 7.5, but haven't personally had time to go
further than the proof-of-concept backend patch I posted awhile ago.

I think the minimum amount of additional work that has to be done before
we can apply it is to teach psql's input parser about $QUOTE$ ---
without that, the feature is not only useless but counterproductive.
After that we could get on with teaching pg_dump and other stuff about
it, at our leisure.

Any volunteers to fix psql?

regards, tom lane

#13Andreas Pflug
pgadmin@pse-consulting.de
In reply to: Tom Lane (#12)
Re: [PATCHES] Double Backslash example patch

Tom Lane wrote:

I think the minimum amount of additional work that has to be done before
we can apply it is to teach psql's input parser about $QUOTE$ ---
without that, the feature is not only useless but counterproductive.

IMHO it's not useless. pgAdmin already knows that quoting scheme... not
yet tested, I'll have to check that patch.

Regards,
Andreas

#14Andrew Dunstan
andrew@dunslane.net
In reply to: Andreas Pflug (#13)
Re: [PATCHES] Double Backslash example patch

Andreas Pflug wrote:

Tom Lane wrote:

I think the minimum amount of additional work that has to be done before
we can apply it is to teach psql's input parser about $QUOTE$ ---
without that, the feature is not only useless but counterproductive.

IMHO it's not useless. pgAdmin already knows that quoting scheme...
not yet tested, I'll have to check that patch.

OTOH we sure want it for psql - being able to use this in scripts fed to
psql is very important IMNSHO.

I see that psql/mainloop.c contains this comment:

* FIXME: rewrite this whole thing with flex

Is now the time to do that? It would be a pity if substantial changes
were made here only to be thrown away ...

cheers

andrew

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#14)
Re: [PATCHES] Double Backslash example patch

Andrew Dunstan <andrew@dunslane.net> writes:

I see that psql/mainloop.c contains this comment:
* FIXME: rewrite this whole thing with flex
Is now the time to do that?

If you feel like giving it a shot, ain't nobody gonna stand in your way.
MainLoop() is well past the level of unmaintainability IMHO (which is
why I'd not tried to touch it in the original quick patch).

I'm not totally convinced that flex can do the job, but in any case a
ground-up redesign for legibility might be the only cure.

regards, tom lane

#16Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#15)
Re: [PATCHES] Double Backslash example patch

Tom Lane wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

I see that psql/mainloop.c contains this comment:
* FIXME: rewrite this whole thing with flex
Is now the time to do that?

If you feel like giving it a shot, ain't nobody gonna stand in your way.
MainLoop() is well past the level of unmaintainability IMHO (which is
why I'd not tried to touch it in the original quick patch).

I'm not totally convinced that flex can do the job, but in any case a
ground-up redesign for legibility might be the only cure.

I will take a look - no guarantees though. I agree that flex might well
end up making things more obscure than less.

Keeping track of open quote operators to make sure we have proper
nesting and closing looks like it might be a bit messy, but doable.

cheers

andrew

#17Bruce Momjian
pgman@candle.pha.pa.us
In reply to: David Fetter (#1)
1 attachment(s)
Re: Double Backslash example patch

I have applied your additional example in the place Peter suggested.
Patch attached.

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

David Fetter wrote:

Kind people,

Please find enclosed a patch exemplifying typical use of the ARE
Class-Shorthand Escapes��. I believe it will help intrepid regex
users. :)

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100 cell: +1 415 235 3778

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Attachments:

/bjm/difftext/plainDownload
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/func.sgml,v
retrieving revision 1.182
diff -c -c -r1.182 func.sgml
*** doc/src/sgml/func.sgml	16 Dec 2003 15:27:58 -0000	1.182
--- doc/src/sgml/func.sgml	18 Dec 2003 03:53:59 -0000
***************
*** 3134,3140 ****
     <note>
      <para>
       Keep in mind that an escape's leading <literal>\</> will need to be
!      doubled when entering the pattern as an SQL string constant.
      </para>
     </note>
  
--- 3134,3143 ----
     <note>
      <para>
       Keep in mind that an escape's leading <literal>\</> will need to be
!      doubled when entering the pattern as an SQL string constant.  For example:
! <programlisting>
! '123' ~ '^\\d{3}' <lineannotation>true</lineannotation>
! </programlisting>
      </para>
     </note>