summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/parse.c b/parse.c
index e7385cd..379d032 100644
--- a/parse.c
+++ b/parse.c
@@ -5376,7 +5376,7 @@ retry:
for (i = 0; i < len; i++) {
c = nextc();
if (c == '\n') {
- ruby_sourceline++;
+ pushback(c);
break;
}
}
@@ -5689,23 +5689,44 @@ retry:
c = nextc();
if (c == 'x' || c == 'X') {
/* hexadecimal */
- while (c = nextc()) {
+ c = nextc();
+ if (!ISXDIGIT(c)) {
+ yyerror("hexadecimal number without hex-digits");
+ }
+ do {
if (c == '_') continue;
if (!ISXDIGIT(c)) break;
tokadd(c);
- }
+ } while (c = nextc());
pushback(c);
tokfix();
yylval.val = rb_str2inum(tok(), 16);
return tINTEGER;
}
- else if (c >= '0' && c <= '7') {
- /* octal */
+ if (c == 'b' || c == 'B') {
+ /* binary */
+ c = nextc();
+ if (c != '0' && c != '1') {
+ yyerror("numeric constant with no digits");
+ }
do {
+ if (c == '_') continue;
+ if (c != '0'&& c != '1') break;
+ tokadd(c);
+ } while (c = nextc());
+ pushback(c);
+ tokfix();
+ yylval.val = rb_str2inum(tok(), 2);
+ return tINTEGER;
+ }
+ else if (c >= '0' && c <= '7' || c == '_') {
+ /* octal */
+ tokadd(c);
+ do {
+ if (c == '_') continue;
+ if (c < '0' || c > '7') break;
tokadd(c);
- while ((c = nextc()) == '_')
- ;
- } while (c >= '0' && c <= '9');
+ } while (c = nextc());
pushback(c);
tokfix();
yylval.val = rb_str2inum(tok(), 8);