From a681628bd4faf9135f0764b3f1f1fdcafc491de6 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 10 Feb 2012 09:50:16 +0100 Subject: [PATCH] Output meaningful lexer error when no digits given for number Closes #1802 --- src/comp/syntax/parse/lexer.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index 053a828f07a..42cc5400b0c 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -220,6 +220,9 @@ fn scan_number(c: char, rdr: reader) -> token::token { tp = if signed { either::left(ast::ty_i64) } else { either::right(ast::ty_u64) }; } + if str::byte_len(num_str) == 0u { + rdr.fatal("no valid digits found for number"); + } let parsed = u64::from_str(num_str, base as u64); alt tp { either::left(t) { ret token::LIT_INT(parsed as i64, t); } @@ -264,6 +267,9 @@ fn scan_number(c: char, rdr: reader) -> token::token { ret token::LIT_FLOAT(interner::intern(*rdr.interner, num_str), ast::ty_f); } else { + if str::byte_len(num_str) == 0u { + rdr.fatal("no valid digits found for number"); + } let parsed = u64::from_str(num_str, base as u64); ret token::LIT_INT(parsed as i64, ast::ty_i); }