ext/yylex.re in cast-0.2.1 vs ext/yylex.re in cast-0.3.0

- old
+ new

@@ -1,10 +1,11 @@ /* -*- mode: c -*- */ /* Given to re2c to generate the lexer `yylex'. * * Based on c.re in the exmaples distributed with re2c. */ +#include <stdio.h> #include <string.h> #include "cast.h" /* * ------------------------------------------------------------------- @@ -29,10 +30,11 @@ set_func(IntLiteral, suffix); new_func(FloatLiteral); set_func(FloatLiteral, format); set_func(FloatLiteral, val); +set_func(FloatLiteral, exponent); set_func(FloatLiteral, suffix); new_func(CharLiteral); set_func(CharLiteral, prefix); set_func(CharLiteral, val); @@ -73,11 +75,11 @@ /* `token' is assumed to be a two element array, which is filled in. */ void yylex(VALUE self, cast_Parser *p) { char *cursor = p->cur; - char *cp; + char *cp, *ep; VALUE value; std: p->tok = cursor; /*!re2c any = [\000-\377]; @@ -175,18 +177,32 @@ ( D+ E | D* "." D+ E? | D+ "." D* E? ) FS? { value = cast_new_FloatLiteral_at(p->lineno); cast_FloatLiteral_set_format(value, ID2SYM(rb_intern("dec"))); cast_FloatLiteral_set_val(value, rb_float_new(strtod(p->tok, (char **)&cp))); if (cp < cursor) - cast_FloatLiteral_set_suffix(value, rb_str_new(cp, cursor - cp)); + cast_FloatLiteral_set_suffix(value, rb_str_new(cp, cursor - cp)); + + ep = (char *)memchr(p->tok, 'e', cp - p->tok); + if (!ep) + ep = (char *)memchr(p->tok, 'E', cp - p->tok); + if (ep) + cast_FloatLiteral_set_exponent(value, LONG2NUM(strtod(ep + 1, NULL))); + RETVALUE(cast_sym_FCON); } - ( "0" [Xx] (H+ P | H* "." H+ P? | H+ "." H* P?) ) FS? { + ( "0" [Xx] (H+ P | H* "." H+ P | H+ "." H* P) ) FS? { value = cast_new_FloatLiteral_at(p->lineno); cast_FloatLiteral_set_format(value, ID2SYM(rb_intern("hex"))); cast_FloatLiteral_set_val(value, rb_float_new(strtod(p->tok, (char **)&cp))); if (cp < cursor) cast_FloatLiteral_set_suffix(value, rb_str_new(cp, cursor - cp)); + + ep = (char *)memchr(p->tok, 'p', cp - p->tok); + if (!ep) + ep = (char *)memchr(p->tok, 'P', cp - p->tok); + if (ep) + cast_FloatLiteral_set_exponent(value, LONG2NUM(strtod(ep + 1, NULL))); + RETVALUE(cast_sym_FCON); } L? ['] (ESC|any\[\\'])+ ['] { value = cast_new_CharLiteral_at(p->lineno);