Syntax highlight bug when division arguments are on different lines #171

Closed
bogdan opened this Issue Sep 6, 2013 · 3 comments

Comments

Projects
None yet
4 participants
@bogdan

bogdan commented Sep 6, 2013

a = calculate(90).and_some_long_expression /
  and_long_expression_here   
puts a

Cause 2nd and 3rd line highlighted as string(probably treat it as regexp).

@AndrewRadev

This comment has been minimized.

Show comment
Hide comment
@AndrewRadev

AndrewRadev Feb 23, 2014

Member

Hmm, this is a tricky one. The problem is that there is no unambigous way to parse this without backtracking (that I can think of). This would be perfectly valid:

a = calculate(90).and_some_long_expression /
  and_long_expression_here
/
puts a

And it would mean calling and_some_long_expression with a regex as an argument... Not only that, but this:

a = calculate(90).and_some_long_expression /
  and_long_expression_here / 5
puts a

would also be perfectly valid and it would parse as two divisions...

I'm not very familiar with Vim's syntax highlighting, so maybe there is a way to differentiate, but I can't think of anything.

The particular commit that introduces this "problem" is 971d932 by @tpope. But the old version of this highlighting basically had a special case for split, scan, gsub and sub and that's not a stable solution to the issue.

I'll think about the issue some more, but I'm afraid I can't promise anything. Regexes are hard.

Member

AndrewRadev commented Feb 23, 2014

Hmm, this is a tricky one. The problem is that there is no unambigous way to parse this without backtracking (that I can think of). This would be perfectly valid:

a = calculate(90).and_some_long_expression /
  and_long_expression_here
/
puts a

And it would mean calling and_some_long_expression with a regex as an argument... Not only that, but this:

a = calculate(90).and_some_long_expression /
  and_long_expression_here / 5
puts a

would also be perfectly valid and it would parse as two divisions...

I'm not very familiar with Vim's syntax highlighting, so maybe there is a way to differentiate, but I can't think of anything.

The particular commit that introduces this "problem" is 971d932 by @tpope. But the old version of this highlighting basically had a special case for split, scan, gsub and sub and that's not a stable solution to the issue.

I'll think about the issue some more, but I'm afraid I can't promise anything. Regexes are hard.

@matthewd

This comment has been minimized.

Show comment
Hide comment
@matthewd

matthewd Apr 10, 2017

And it would mean calling and_some_long_expression with a regex as an argument

Forgive the drive-by comment on an old issue, but: no, it wouldn't. Whitespace after an ambiguous /, including newline, makes it a division.

And it would mean calling and_some_long_expression with a regex as an argument

Forgive the drive-by comment on an old issue, but: no, it wouldn't. Whitespace after an ambiguous /, including newline, makes it a division.

@tpope tpope closed this in 96510b0 Apr 10, 2017

@tpope

This comment has been minimized.

Show comment
Hide comment
@tpope

tpope Apr 10, 2017

Member

When you put it like that the solution is pretty obvious.

Member

tpope commented Apr 10, 2017

When you put it like that the solution is pretty obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment