munificent / vigil

Vigil, the eternal morally vigilant programming language
2.9k stars 61 forks source link

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

Open peterolson opened 11 years ago

peterolson commented 11 years ago

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 commented 11 years ago

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.