Thursday, September 20, 2012

Strange error with python interface

python << EOF
import re
patstr = r"""
^(?:[^%]|\\%)*(?:
\\def|
\\providecommand\s*{|
\\(?:re)?newcommand\s*{|
\\(?:re)?newenvironment\s*{|
\\(?:re)?newtheorem\s*{|
\\definecolor\s*{)
([^{}]*)"""
print("'%s'" % patstr.strip())
pat = re.compile(patstr, re.VERBOSE)
EOF
Hello,

I stumbled upon a strange error which I cannot figure out why it
happens. Let us write a small vim script (attached to this email) and
save it somewhere on the HD:

python << EOF
import re
patstr = r"""
^(?:[^%]|\\%)*(?:
\\def|
\\providecommand\s*{|
\\(?:re)?newcommand\s*{|
\\(?:re)?newenvironment\s*{|
\\(?:re)?newtheorem\s*{|
\\definecolor\s*{)
([^{}]*)"""
print("'%s'" % patstr.strip())
pat = re.compile(patstr, re.VERBOSE)
EOF

The script just defines a python verbose regular expression, and prints
it. When I open this file with

vim -u NONE script.vim

everythings works fine and as expected. The output of the script is:

'^(?:[^%]|\\%)*(?:
\\def|
\\providecommand\s*{|
\\(?:re)?newcommand\s*{|
\\(?:re)?newenvironment\s*{|
\\(?:re)?newtheorem\s*{|
\\definecolor\s*{)
([^{}]*)'


, but when I open it with
vim script.vim
or
vim --noplugin script.vim

I got the following error:

'^(?:[^%]|\\%)*(?:\def|\providecommand\s*{|\(?:re)?newcommand\s*{|\(?:re)?newenvironment\s*{|\(?:re)?newtheorem\s*{|\definecolor\s*{)
([^{}]*)'
Error detected while processing /tmp/script.vim:
line 14:
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "/usr/lib64/python2.7/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib64/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis

Note that this time the new lines are not shown when the print()
statement is executed (why?).

So I started bisecting my vimrc file. Then I ended in the 0 line with
the 'finish' command and the behaviour presists, I also added 'finish'
at the very begining of my system vimrc file and the vimrc file. And
nothing changed (still got the sre_constants.error)

Any ideas?

Best regards,
Marcin

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: