[njs] Lexer support for hexadecimal literal values.

Igor Sysoev igor at sysoev.ru
Thu May 25 08:57:56 UTC 2017


Thank you for your patch.
We are currently working on comprehensive hexadecimal support.


-- 
Igor Sysoev
http://nginx.com

On 21 May 2017, at 20:52, Paulo Pacheco <fooinha at gmail.com> wrote:

> # HG changeset patch
> # User Paulo Pacheco <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/20170525/cfe873f8/attachment.html>


More information about the nginx-devel mailing list