Processing: $ (dollar sign) in a method name breaks syntax highlighting

Created on 1 Jul 2018  路  6Comments  路  Source: processing/processing



Description

$ is a valid character in Java identifier names.

Expected Behavior



I'd expect that I can use $ in any name, like mem$set() or something like that.

Current Behavior


However, that is not the case. Any method with a name that contains a $ will have somewhat broken syntax highlighting, the highlighter will think that anything after the $ is not part of the previous token and will start a new one.

Steps to Reproduce


  1. Paste the following code into the PDE:
void setup() { }

void myVariable$set(int val) {
}

Edit: Hey, even GitHub doesn't highlight the name properly!

  1. As you can see, set is incorrectly highlighted.

Your Environment



  • Processing version: 3.3.7
  • Operating System and OS version: Raspbian Stretch
  • Other information: None.

Possible Causes / Solutions


It just might be an issue with how the tokenizer handles method/field names: it does not know that $ is a valid character for a method name.
I am aware that not a lot of people use the dollar sign in method/field names, it is just a bug I found out of curiosity. It should be fixed anyway.

All 6 comments

@liquid600pgm The Processing language isn't Java! I get this error message (for you code) :

void is an invalid type for the variable myVariable$set

I use Linux Mint
I use the latest version of Processing.

Forgot to add that there should be a setup() and a draw().
Processing IS Java, did you ever hear about Java tabs, or have you ever looked through its source code? It's just simplified, so that it is accessible to more people whose aim is not to just learn coding, but engage in visual arts etc.

@liquid600pgm

Processing IS Java

It is written in Java (IDE and language), of course. But the language isn't Java. You can't written in Java single functions and run it (without a class) . Or put in single statements and run it. You will also no call Java as C/C++ ? Or?

Let me call this differently: Processing is a superset of Java, which makes it use the same syntax rules. Of course Processing reduces the amount of boilerplate code required to make apps with AWT/OpenGL/JavaFX, but fundamentally, it is still Java.

The original error occured, because you're not allowed to create methods in static sketches - you have to make them dynamic by adding setup() and draw(). You could still see the bad syntax highlighting in the method name despite the error, which was not even caused by the dollar sign.

Processing is a superset of Java, ... it is still Java.

And in some ways a subset, but totally agree it's still Java :smile:

As such though, it's also possibly worth considering the Java language spec here - https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8 and specifically,

The $ sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

Which could be a good reason for syntax highlighters _not_ to treat this as valid code! Given possibility of issues or confusion around its use, perhaps good that Processing mirrors the Java spec there.

@neilcsmith-net I absolutely agree.
But IDEs like Eclipse or IntelliJ IDEA handle those cases properly. Why does the PDE have to be different about that?
I know that the PDE is not supposed to be a full-blown IDE with lots of features, heck, it even doesn't highlight number constants, but this is a thing that the Java spec allows, even though its use is discouraged.

As for your subset "theory", I also agree, the lack of lambdas and the diamond operator make Processing a subset of Java in some ways.

Was this page helpful?
0 / 5 - 0 ratings