luke-gru / riml

Riml is a subset of VimL with some nice added features. It compiles to plain VimL.
MIT License
224 stars 6 forks source link

Whitespace at end of statements #11

Closed dsawardekar closed 11 years ago

dsawardekar commented 11 years ago

@luke-gru I've narrowed down a weird issue I was seeing, while refactoring code. It was occurring mostly when doing things like adding new conditions to if, statements, when extracting code to a method. I think this is related to how riml handles whitespace at the end of lines.

Consider this code,

def hello() 
end

This looks like valid riml code but it has an extra whitespace at the end of the line after the hello() function. Without the whitespace the code compiles fine. But with the whitespace you get the following error,

grammar.y:557:in `rescue in parse': on line 1:  (Riml::ParseError)
parse error on value "end" (END)

"end" is a keyword, and cannot be used as a variable name
    from grammar.y:547:in `parse'
... stacktrace

On further exploration I found this happens for nearly all statements. If you happen to accidentally add whitespace to code that was working earlier, it stops, with an error message very similar to the above.

luke-gru commented 11 years ago

Thanks for the bug report once again! This is probably happening because of fileformat issues, the lexer isn't looking for carriage returns as newlines. I'll get a fix out for this by Friday. If you change the fileformat to unix set fileformat=unix, that should make it compile for now. My guess is that it was set to dos or mac, and I just tested and confirmed the bug with these fileformats.

Thanks again!

dsawardekar commented 11 years ago

@luke-gru I'm not sure this is a fileformat issue. I'm on Ubuntu, and my fileformat is always unix. I tried setting the whitespace to be visible with, :set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

This shows the trailing whitespace as ~. Riml compiles correctly when I remove the trailing whitespaces.

luke-gru commented 11 years ago

That's really weird. I tried to reproduce by just putting trailing '' characters, but I couldn't. I'll look more into this tonight.

dsawardekar commented 11 years ago

Here's a couple of gists with the exact code, and the full stacktraces.

This pattern repeats for other statements. The error's messages are different, but I think the issues are related. And the errors do go away if you trim the trailing whitespaces.

luke-gru commented 11 years ago

Just figured out why I couldn't reproduce the issue initially. When I :wqed from vim, my autocmd to delete trailing whitespace kicked in. Forgot I had the autocmd, because at work I had to disable it due to some people's unexplained fondness for trailing whitespaces :smile:. I discovered the source of the problem, fix is coming now.

dsawardekar commented 11 years ago

Hah! I was beginning to doubt my eyes for a bit there. :wine_glass: