[njs] Lexer support for hexadecimal literal values.

Paulo Pacheco fooinha at gmail.com
Wed May 31 13:19:03 UTC 2017


Hi Дмитрий

Thanx for this. This is great.

I'm going to update and test.

Best regards to all nginx team,

--------------------------------------
Paulo Pacheco | Паулу Пашеку


On Wed, May 31, 2017 at 12:56 PM, Dmitry Volyntsev <xeioex at nginx.com> wrote:

> Hi, Paulo
>
> the support for hexadecimal literal values was committed in
> http://hg.nginx.org/njs/rev/a38c33e9f728
>
> Thank you for prodding.
>
> On 21.05.2017 20:52, Paulo Pacheco wrote:
>
>> # HG changeset patch
>> # User Paulo Pacheco <fooinha at gmail.com <mailto:fooinha at gmail.com>>
>>
>> # Date 1495388206 0
>> #      Sun May 21 17:36:46 2017 +0000
>> # Node ID 22db6b6a3a0eebff8453fb22035628410c05c5c8
>> # Parent  96fda9957427e1ea78d0096b019a3f3183db7346
>> [njs] Lexer support for hexadecimal literal values.
>>
>> diff -r 96fda9957427 -r 22db6b6a3a0e njs/njs_lexer.c
>> --- a/njs/njs_lexer.c    Wed Apr 19 17:48:56 2017 +0300
>> +++ b/njs/njs_lexer.c    Sun May 21 17:36:46 2017 +0000
>> @@ -19,7 +19,7 @@
>>  #include <njs_variable.h>
>>  #include <njs_parser.h>
>>  #include <string.h>
>> -
>> +#include <stdlib.h>
>>
>>  typedef struct njs_lexer_multi_s  njs_lexer_multi_t;
>>
>> @@ -539,10 +539,28 @@
>>  {
>>      u_char  c, *p;
>>      double  num, frac, scale;
>> +    char *endptr;
>>
>>      /* TODO: "1e2" */
>>
>>      p = lexer->start;
>> +
>> +    /* Hexadecimal literal values */
>> +    if ( (lexer->end - lexer->start) > 2
>> +            && (*p == 'x' || *p == 'X')
>> +            && (lexer->prev_token > 0
>> +                || ((lexer->start - 1) == lexer->text.start)
>> +            )
>> +            && (*(p-1) == '0')) {
>> +
>> +        lexer->number = strtod((const char *) p-1, &endptr);
>> +        if ((u_char *) endptr <= lexer->end) {
>> +            lexer->start = (u_char *) endptr;
>> +            return NJS_TOKEN_NUMBER;
>> +        }
>> +        lexer->number = 0;
>> +    }
>> +
>>      c = p[-1];
>>
>>      /* Values below '0' become >= 208. */
>> diff -r 96fda9957427 -r 22db6b6a3a0e njs/test/njs_unit_test.c
>> --- a/njs/test/njs_unit_test.c    Wed Apr 19 17:48:56 2017 +0300
>> +++ b/njs/test/njs_unit_test.c    Sun May 21 17:36:46 2017 +0000
>> @@ -112,6 +112,18 @@
>>      { nxt_string("+1"),
>>        nxt_string("1") },
>>
>> +    { nxt_string("var a = 0x01; a"),
>> +      nxt_string("1") },
>> +
>> +    { nxt_string("var x = 0xffff; x"),
>> +      nxt_string("65535") },
>> +
>> +    { nxt_string("0x01"),
>> +      nxt_string("1") },
>> +
>> +    { nxt_string("0xffff"),
>> +      nxt_string("65535") },
>> +
>>      { nxt_string("+1\n"),
>>        nxt_string("1") },
>>
>>
>> ---------------------------------- CUT HERE
>> --------------------------------------
>> Paulo Pacheco | Паулу Пашеку
>>
>>
>>
>>
>> _______________________________________________
>> nginx-devel mailing list
>> nginx-devel at nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20170531/0584288e/attachment.html>


More information about the nginx-devel mailing list