highlightjs / highlightjs-solidity

Do What The F*ck You Want To Public License
48 stars 17 forks source link

Updates for Solidity 0.6.2 #24

Closed haltman-at closed 4 years ago

haltman-at commented 4 years ago

This PR contains updates for Solidity 0.6.2. Specifically:

  1. The literals true and false are now allowed in assembly mode.

  2. I added gas,value, and salt as builtins due to the new function-call syntax? I'm not sure builtin is really the right place for these, but I couldn't figure out what was better... I mean they're not keywords, surely? (Like, pretty sure you can still use them as variable names, e.g.) IDK, if anyone has a better idea, please suggest it. (I mean ideally we'd only highlight them in context, but that seems really hard!)

(Also, in my previous PR, I accidentally used tabs instead of spaces at one point... oops! Fixed here.)

frangio commented 4 years ago

value is pretty common as a variable name. What do you think about highlighting any identifier followed by a colon?

haltman-at commented 4 years ago

Yeah, the value problem bothered me too. On the other hand, I'm not sure "identifier followed by a colon" works well either. There are two obstacles I notice that bother me. One is that there could be whitespace inbetween, but seems minor and handleable; we can account for that. The bigger problem to my mind is that this overlaps with Solidity's named-argument syntax (yeah, it's not well-documented, quite annoyingly), which also uses identifiers followed by colons.

Maybe we could distnguish the two? Like, maybe with more work we could distinguish named arguments from these sorts of parameters? Like, maybe a ( followed by a { (possibly with whitespace inbetween) would put us in a "named arguments" mode, but outside that mode we'd have the identifier-followed-by-colon rule? Or maybe just specifically gas, value, salt when followed by colon? This all might require some mode-wrangling...

frangio commented 4 years ago

I thought about named arguments, and there's also struct construction. But I don't see a problem with highlighting all of those too.

frangio commented 4 years ago

On the other hand we could also just leave all of gas, value, salt without any highlighting at all. I don't see a problem with that.

haltman-at commented 4 years ago

Whoo, finally getting back to this. I think there just isn't any totally satisfactory solution to this unfortunately. Current thinking: Maybe just highlight gas, value, and salt when followed immediately by a colon? That should probably be good enough most of the time...

frangio commented 4 years ago

Let's go ahead with that and see how it works out. We can always roll back if we don't like the result.

haltman-at commented 4 years ago

OK, pushed that!

haltman-at commented 4 years ago

Whoops, one last change: I made it so that the special parameters can be used in a few other places too (as technically they could appear in a modifier invocation or base constructor invocation).

Anyway I'll merge and release this in a bit I guess!