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

Faulty padding with triple-quoted strings and empty lines #175

Closed
copygirl opened this issue Oct 9, 2012 · 4 comments
Closed

Faulty padding with triple-quoted strings and empty lines #175

copygirl opened this issue Oct 9, 2012 · 4 comments
Labels

Comments

@copygirl
Copy link

copygirl commented Oct 9, 2012

There appears to be a problem with empty lines in triple-quoted strings:

"""foo

   bar"""

(Note: 3 spaces in the empty line)
Produces the string "foo\n \n bar"

This is similar for when you put foo on a seperate line. To fix this you'll have to either leave the empty line completely empty, or add an extra space to it. For some reason, less spaces in the empty line means more padding to the rest of the string - if this example had only one space in the empty line, it would produce 3 spaces in front of bar instead of 1.

I should mention that CoffeeScript doesn't seem to have this issue.

@satyr
Copy link
Owner

satyr commented Oct 9, 2012

Wondering if we should ignore space-only lines for heredocs as well.

It seems bad when invisible changes matter, not to mention many tools don't like trailing spaces.

@satyr
Copy link
Owner

satyr commented Oct 9, 2012

I.e.,

'''
  0

   1
'''

would equal to '0\n\n 1' no matter how many spaces the empty lines has.

To explicitly indicate space-only lines, we can (already) use \:

'''
  0
   \
   1
'''

↓↑

'0\n \n 1'

@copygirl
Copy link
Author

copygirl commented Oct 9, 2012

I wouldn't really change it much from the way CoffeeScript does it, and I don't like the \ idea if it was required. To fix the problem of spacing the rest of the string accidentally when having less spaces on empty lines than the rest, maybe add a compile error?

(- = space)

"""foo
-
---bar"""

would cause this error, whereas the following won't

"""--foo
---         # no spaces would do the same
-----bar"""

and it should produce "--foo\n\n--bar".
Also try this with CoffeeScript, it's not how I think it's supposed to be.

Although then I don't know how intentional padding would work with the """ on their own lines.
Nevermind, that's what the \ would be for, I guess, but it's still a bit unintuitive, which I think is not a problem since this is a rare special case.

@satyr
Copy link
Owner

satyr commented Oct 9, 2012

I wouldn't really change it much from the way CoffeeScript does it

That's certainly safer. I guess I'll open a separate issue for the trimming idea.

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

No branches or pull requests

2 participants