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

Syntax highlighting does not allow for non-alphanumeric charactes in function names #133

Open
Shannarra opened this issue May 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Shannarra
Copy link

Shannarra commented May 12, 2024

Describe the bug
As part of adding Ruby support I came across multiple issues when it comes to syntax highlighting.

In some languages, functions can have non-alphanumeric characters as part of their names.

One of which is Ruby. In Ruby, your function names can end with an exclamation mark (!) or a question mark (?).
This has a significance especially when it comes to semantics, as the naming of the function is part of the standard of writing Ruby code.

For example, the difference between:

arr = [1, 2, 3, 4]
arr.map(&:to_s)

and

arr = [1, 2, 3, 4]
arr.map!(&:to_s)

is that in the first example, the original array arr will not be modified, instead a modified copy of it will be returned, whereas in the second snippet, the base array will be modified and all it's items will be turned into strings.

Same for the ruby Array#empty? method, generally, method names ending with a question mark (?) should always return a boolean.

This issue holds true even though the piece of code that handles functions actually handles functions ending with ! and ?, the syntax highlighting does not work properly. And yes, the ! or ? is part of the function's name.

This issue holds true also for languages that support kebab-case function names (such as CSS (yes, the current css mode doesn't handle kebab-case), or any LISP-based programming language), or other weird function names.

Another example is Haskell and the way it handles function names, as it supports adding a ' at the end of a function name, for example:

fact :: Int -> Int 
fact 0 = 1 
fact n = n * fact ( n - 1 ) 

and re-writing the same function using guards, we can call it "fact prime", or in Haskell terms:

fact' :: Integer -> Integer 
fact' n | n == 0 = 1 
        | n /= 0 = n * fact' (n-1) 

The compilers will do just fine, but missing syntax highlighting can and will lead to inevitable confusion.

As a potential fix, I'd suggest maybe adding a way to extend or modify the regex Godot uses to detect function names, so that said functions can be detected on a language basis.

@Shannarra Shannarra added the bug Something isn't working label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant