Closed haltman-at closed 3 years ago
Oh, wait, I think I need to test this more.
OK, yup, tested it out and there was a problem. Fixed it now though.
The problem was that in certain contexts I had put operators above comments; it seems like highlight.js prioritizes things that are above. This caused certain comments not to be recognized. Oops. I moved it below in all contexts now to prevent the problem.
Yes. The mode rule set is "executed" sequentially so the first rule that matches in a given mode is how it works. 
Ah, OK, good. Glad to know I can rely on that. That makes things easier than having to come up with some other way of ensuring that comment starts are never recognized as operators. (It'll come in handy too later, I'm intending to add doctag highlighting later, ordering provides a good way of ensuring that doctags are only highlighted in doc comments. :) )
Alright, @cds-amal says it's OK, so I'm going to merge and release this despite the punctuation weirdness! :)
This PR adds operator and punctuation highlighting for Solidity and Yul. Well -- I did some of this in maybe an iffy way, but, well, obviously it can be changed if need be.
For Yul this was straightforward; I added
:=
and->
as operators, and the obvious things as punctuation. Arguably->
should be punctuation, but it seemed worth highlighting as an operator to me.For Solidity... well, Solidity has a number of operators, but they're all made of the same few characters, so I just checked for those characters. (So,
=>
will be highlighted as an operator, which makes sense to me.) For punctuation I put the obvious things.Except... I did one thing that is maybe kind of off; I put
?
and:
as punctuation. Now,?
should be an operator, right? It's the ternary operator. Problem is, then:
should be an operator too. And:
occurs in a lot of contexts where it is not in fact an operator, but we don't really have a good way of checking for that right now. So I thought, what if I just classed them as punctuation instead? Maybe that'd be OK? Like I said, let me know what you think.Note I didn't include punctuation highlighting inside function parameters.
Also I removed
*
as a possible lexeme and removed it from keywords, adding operator highlighting to those contexts instead so it'll be highlighted as an operator.I also added a rudimentary test.