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

Ruby ternary operator and regex highlighting #69

Closed
zufuliu opened this issue Mar 26, 2022 · 7 comments
Closed

Ruby ternary operator and regex highlighting #69

zufuliu opened this issue Mar 26, 2022 · 7 comments
Labels
ruby Caused by the ruby lexer

Comments

@zufuliu
Copy link
Contributor

zufuliu commented Mar 26, 2022

Created for https://sourceforge.net/p/scintilla/bugs/1927/ and https://sourceforge.net/p/scintilla/bugs/2126/

Here need update for ? (question mark single character string) and : (symbol).
https://ruby-doc.org/core-3.1.1/doc/syntax/literals_rdoc.html#label-Strings
https://ruby-doc.org/core-3.1.1/doc/syntax/literals_rdoc.html#label-Symbol+Literals

@nyamatongwe nyamatongwe added the ruby Caused by the ruby lexer label Mar 26, 2022
@zufuliu
Copy link
Contributor Author

zufuliu commented Mar 27, 2022

ruby-ternary-0327.zip

Contains following changes:

  1. for :, treat it as operator instead of symbol if followed by space
  2. for ?
    1. if followed by an identifier with at least two code points, then treat it as operator instead of number. e.g. ?ab is colored as operator ? with identifier ab.
    2. correctly handle multi-byte character after it with GetCharacterAndWidth(), which fixed highlighting bug for ?あ from linked doc.

As show in the test file, this is not full fixed, I think maybe further complex work is needed to handle ternary operator not followed by space (not a good code style though).

# TODO: space after '?' and ':' is not needed
puts true ?ab : cd
puts true ? /d+/ : /w+/
puts false ?ab : cd
puts false ? /d+/ : /w+/

@nyamatongwe
Copy link
Member

One of the hassles with noexcept is that it's viral.

lexilla\lexers\LexRuby.cxx(69): warning C26447: The function is declared 'noexcept' but calls function 'isSafeAlnum()' which may throw exceptions (f.6).
lexilla\lexers\LexRuby.cxx(70): warning C26447: The function is declared 'noexcept' but calls function 'isSafeWordcharOrHigh()' which may throw exceptions (f.6).

The original LexRuby.cxx uses space indentation so its best to maintain that.

Can't see how it is supposed to disambiguate ? and : when there are no spaces.

@zufuliu
Copy link
Contributor Author

zufuliu commented Mar 28, 2022

ruby-ternary-0329-3.zip

Removed noexcept and converted indentation to spaces. changed regex to /\d+/ and /\w+/.

I also not find how to disambiguate them, but ?/\ and :/\ are invalid when \ not followed by new line, maybe can be special handled.

@nyamatongwe
Copy link
Member

For line 5, puts ?\\ the first byte of the following newline is still in SCE_RB_NUMBER. I would expect the 'number' to include just the two \.

This hasn't changed but the example will cause trouble with TestLexers due to the bytes of \r\n having different styles. Making the example line puts ?\\# would avoid warnings from TestLexers until the underlying problem is fixed.

@zufuliu
Copy link
Contributor Author

zufuliu commented Apr 1, 2022

ruby-ternary-0401.zip

Fixed ?\\.

nyamatongwe pushed a commit that referenced this issue Apr 6, 2022
nyamatongwe pushed a commit that referenced this issue Apr 6, 2022
Correct handling of multi-byte character literal.
@nyamatongwe
Copy link
Member

Pushed in 2 commits listed above.

@nyamatongwe
Copy link
Member

Included in 5.1.7 release.

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

No branches or pull requests

2 participants