rajnishyadav321 / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

skip comment #{ #} give unexpected indent error if #} has more text on the line. #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. make file called in.py

#in.py

print "hi there"

#{ comment here ok
print "hi there"
#} comment here not ok

2. run shedskin

% shedskin in.py
*ERROR* in.py:7: unexpected indent

What is the expected output? What do you see instead?

I'd expect text after #} to be ignored.

no big deal - just thought you would like to know.

Original issue reported on code.google.com by paulhaeb...@gmail.com on 30 Jan 2013 at 6:54

Attachments:

GoogleCodeExporter commented 9 years ago
thanks paul, yes this is a bug. I will have a look.

Original comment by mark.duf...@gmail.com on 30 Jan 2013 at 2:37

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 30 Jan 2013 at 2:45

GoogleCodeExporter commented 9 years ago
I changed this regex from:
re.compile(r"#{.*?#}", re.MULTILINE | re.DOTALL)

to this:
re.compile(r"#{.*?#}[^\r\n]*$", re.MULTILINE | re.DOTALL)

The difference being that this also matches everything that comes after #} up 
to the next newline. Notice that in this case I can't use the dot character 
since that one will consume the newline (re.DOTALL). If I use the dot 
character, everything after #} gets commented.

As far as I can tell, this will also work in Windows. It's been a while since I 
used regular expressions (I used to be a big fan, used to... 
http://www.xkcd.com/1171/, now I use things like pyparsing)

Anyway, let me know how it goes.

Original comment by ernestof...@gmail.com on 21 Mar 2013 at 2:18

Attachments:

GoogleCodeExporter commented 9 years ago
thanks a lot ernesto! I pushed the patch, and added a test to tests/201.py. 
yeah, perhaps it would be nicer to replace the regular expression obfuscation 
with a simple loop over the lines in the source code.. but this should work 
fine, too.

Original comment by mark.duf...@gmail.com on 21 Mar 2013 at 8:21

GoogleCodeExporter commented 9 years ago
Excellent. I'm glad it worked!

Original comment by ernestof...@gmail.com on 22 Mar 2013 at 2:41