Welcome! Log In Create A New Profile

Advanced

Re: [njs] Lexer support for hexadecimal literal values.

Paulo Pacheco
May 31, 2017 09:20AM
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@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@gmail.com <mailto:fooinha@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@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>>
>>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Lexer support for hexadecimal literal values.

Paulo Pacheco 473 May 21, 2017 01:54PM

Re: [njs] Lexer support for hexadecimal literal values.

Igor Sysoev 488 May 25, 2017 05:00AM

Re: [njs] Lexer support for hexadecimal literal values.

Dmitry Volyntsev 307 May 31, 2017 07:58AM

Re: [njs] Lexer support for hexadecimal literal values.

Paulo Pacheco 306 May 31, 2017 09:20AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 127
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready