Re: [Python-Dev] [Python-checkins] python/dist/src/Lib sre_compile.py, 1.57, 1.58

2005-06-02 Thread Raymond Hettinger
 Index: sre_compile.py
 ===
 RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
 retrieving revision 1.57
 retrieving revision 1.58
 diff -u -d -r1.57 -r1.58
 --- sre_compile.py28 Feb 2005 19:27:52 -  1.57
 +++ sre_compile.py2 Jun 2005 13:35:52 -   1.58
 @@ -167,7 +167,7 @@
  emit(av-1)
  elif op is GROUPREF_EXISTS:
  emit(OPCODES[op])
 -emit((av[0]-1)*2)
 +emit(av[0]-1)
  skipyes = _len(code); emit(0)
  _compile(code, av[1], flags)
  if av[2]:


The times two operation also occurs twice in nearby code.  Are those
also incorrect?


Raymond Hettinger
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] [Python-checkins] python/dist/src/Lib sre_compile.py, 1.57, 1.58

2005-06-02 Thread A.M. Kuchling
On Thu, Jun 02, 2005 at 03:34:17PM -0400, Raymond Hettinger wrote:
 The times two operation also occurs twice in nearby code.  Are those
 also incorrect?

I believe they're correct.  

EXPN: The regex engine refers to both 'groups', where group #N means
the corresponding group in the pattern, and 'marks', which is a table
of indexes into the string; group #0 - mark 0 and 1, group #1 - mark
2 and 3, etc.  The compiler was storing the mark value, but then the
code for the GROUPREF_EXISTS opcode was doubling it, converting group
to mark:

case SRE_OP_GROUPREF_EXISTS:
TRACE((|%p|%p|GROUPREF_EXISTS %d\n, ctx-pattern,
   ctx-ptr, ctx-pattern[0]));
/* GROUPREF_EXISTS group skip codeyes JUMP codeno ... */
i = ctx-pattern[0];
{
int groupref = i+i;
if (groupref = state-lastmark) {
ctx-pattern += ctx-pattern[1];
break;
} else {
...
 }

The two other uses of *2 are for the MARK opcode, which stores the
current position in the string in the corresponding entry in the
table; it really does want the mark number, so the doubling is
correct.

The 'groupref = i+i' in the above code is a bit odd -- why not write 2*i?  I
thought it might be a typo for i+1, but that wouldn't make sense
either; eventually I decided this was just a stylistic thing.

--amOnly the effbot knows for surek



___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com