[issue27586] Is this a regular expression library bug?

2016-07-22 Thread Bruce Eckel

Bruce Eckel added the comment:

Thank you ebarry, very helpful. Tim, sorry I missed you at Pycon.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Emanuel Barry

Emanuel Barry added the comment:

For future reference, if your input can have arbitrary escapes, it might be a 
good idea to pass it through re.escape; it does proper escaping so that stuff 
like e.g. \g in your input will get treated as a literal backslash, followed by 
a literal 'g', and not an escape sequence.

--
nosy: +ebarry
type: compile error -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Bruce Eckel

Bruce Eckel added the comment:

Urk. There was exactly a \g in the input. Sorry for the bother.

--
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Tim Peters

Changes by Tim Peters :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Tim Peters

Tim Peters added the comment:

Well, some backslash escapes are processed in the "replacement" argument to 
`.sub()`.  If your replacement text contains a substring of the form

\g

not immediately followed by

<

that will raise the exception you're seeing.  The parser is expecting to see a 
"matched group" reference after "\g", like

\g<1>
\g

So it depends on the value of your `new_output`.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Bruce Eckel

Bruce Eckel added the comment:

Sorry, I thought maybe the error message would be indicative of something. 
Here's the re:

find_output = re.compile(r"/\* (Output:.*)\*/", re.DOTALL)

Here's the program:

#! py -3
# Requires Python 3.5
# Updates generated output into extracted Java programs in "On Java 8"
from pathlib import Path
import re
import pprint
import sys

if __name__ == '__main__':
find_output = re.compile(r"/\* (Output:.*)\*/", re.DOTALL)
for outfile in Path(".").rglob("*.p1"):
print(str(outfile))
javafile = outfile.with_suffix(".java")
if not javafile.exists():
print(str(outfile) + " has no javafile")
sys.exit(1)
javatext = javafile.read_text()
if "/* Output:" not in javatext:
print(str(javafile) + " has no /* Output:")
sys.exit(1)
new_output = outfile.read_text()
new_javatext = find_output.sub(new_output, javatext)
javafile.write_text(new_javatext)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Tim Peters

Tim Peters added the comment:

If you don't show us the regular expression, it's going to be darned hard to 
guess what it is ;-)

--
nosy: +tim.peters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27586] Is this a regular expression library bug?

2016-07-21 Thread Bruce Eckel

New submission from Bruce Eckel:

This looks suspicious to me, like it could be a library bug, but before chasing 
it down I was hoping someone might be able to tell me whether I might be on to 
something:

Traceback (most recent call last):
  File "update_extracted_example_output.py", line 22, in 
new_javatext = find_output.sub(new_output, javatext)
  File "C:\Python35\lib\re.py", line 325, in _subx
template = _compile_repl(template, pattern)
  File "C:\Python35\lib\re.py", line 312, in _compile_repl
p = sre_parse.parse_template(repl, pattern)
  File "C:\Python35\lib\sre_parse.py", line 872, in parse_template
raise s.error("missing <")
sre_constants.error: missing < at position 100 (line 4, column 41)

--
components: Library (Lib)
messages: 270956
nosy: Bruce Eckel
priority: normal
severity: normal
status: open
title: Is this a regular expression library bug?
type: compile error
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com