Robert Roessler wrote:
Philippe Lhoste wrote:
While we are on the topic, I asked some time ago a request on the PHP lexer which when unnoticed...
Is it possible to support hexadecimal numbers in PHP? In the form 0x1BADBEEF, of course.

How about this, Philippe? :)

// recognize bases 8,10 or 16 integers OR floating-point numbers
if (!IsADigit(ch)
   && strchr(".xXabcdefABCDEF", ch) == NULL
   && ((ch != '-' && ch != '+') || (chPrev != 'e' && chPrev != 'E'))) {

Thank you Robert. I am quite busy these times, and I am quite reluctent to dive into LexHTML...
I can at least apply this patch.
I expect it to become official.


These FOUR lines replace line 1515 in [naturalment] LexHTML.cxx. I am not sure who the "owner" of this module is, but this code works well for me. BTW, it fixes a small bug in the original, in that POSITIVE exponents were not seen as part of the float.

N.B. - the 'strchr' also handles the 'e' and 'E' exponent cases.

OTOH, the PHP numeric constant recognition and handling still has a number of "weak" spots because it does not track from the beginning what kind of literal it is: octal and hexadecimal numbers can NOT have decimal points and exponents, but decimal literals CAN "morph" into floating-point ones.

Well, that's the case for most lexers. I improved the CPP lexer (and similar ones amongst those I maintain/use, like POV, Lua, etc.) with a much better number parsing, using an automaton.
It was able, for example, to end number style when finding a second decimal point.


Its weak spot was when finding something like 3.14.159, it sees two consecutive correct decimal numbers and display them as regular numbers... So I added some rules like you can't have two consecutive numbers, you can't have a number immediately after a string, etc.

Well, I found, according to Neil, that those rules were fragiles (false positives on correct constructs) and complicated the code too much for too little benefit as these bad constructs happen rarely, except when typing. To be consistent, one should detect and indicate more bad syntax, which is very hard... except the Eclipse way, ie. by compiling the file on each keystroke and indicating errorswith squiggly underlines... VB did that in much more instrusive and annoying way, by popping out a message box when leaving a line with an error, which happens often for me as I go to another line to drag'n'drop fragments of code.

So, whenever I find some time, I remove these rules from my code, move the number parser to another class (I put it in StyleContext but Neil doesn't like that) and retry to ask to integrate this to the official Scintilla.
Or I just give my code and hope that somebody less busy does that... :-)


But this IS an improvement, and it will make Philippe happy! :)

Yes, thank you again. :-D

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --
_______________________________________________
Scintilla-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Reply via email to