Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vigil fails for multiline expressions passed to implore or swear #6

Open
peterolson opened this issue Jan 3, 2013 · 1 comment
Open

Comments

@peterolson
Copy link

Vigil has a naïve implementation for parsing implore and swear statements. Here is the relevant section of the source, starting at line 82.

for line in source_lines:
    line = re.sub(r'(\s*)implore (.*)', r'\1vigil_implore(\2, """\2""")', line)
    line = re.sub(r'(\s*)swear (.*)', r'\1vigil_swear(\2, """\2""")', line)
    source += line

Vigil is just passing in everything on a line after an implore or swear statement into a vigil_implore or vigil_swear function call. This will fail if you have multiline expressions in you code, such as in this very contrived example

implore n >= (1 +
 3 -
 4)

Python will interpret everything inside the parentheses as part of a single line, but f.readlines will not. If I understand correctly, Vigil will rewrite the above example thus:

vigil_implore(n >= (1 +, """n >= (1 +, """)
3 -
4)

which is not syntactically valid.

Also, in Python you may put a \ before a newline and it will interpret the following line as if it were part of the current line. Vigil fails here for the same reason.

Vigil would be improved if it were able to parse these multiline expressions correctly.

@chall8908
Copy link

Or, perhaps, your coding style would be improved by adhering to Vigil's unspoken rules about swear and implore statements?

Why would you wish to divide yourself from a whole into parts? I believe that your code is immoral and must be punished!

In all seriousness, though, this would probably improve readability on long swear/implore statements. While, personally, I can't think of a particular reason that doesn't seem contrived, I'm sure someone will run into a valid use case eventually.

+1 from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants