summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-03-12 06:22:15 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-03-12 06:22:15 -0700
commitd0b35b7d272eaf4fbcf7754e25801739ddb2410d (patch)
treeebb220c8a2d04a93c685dfa0b4c7a707c62525be /parser.l
parent4098bdfbe0406bfacfc8a1b46bfad38964cfd2df (diff)
downloadtxr-d0b35b7d272eaf4fbcf7754e25801739ddb2410d.tar.gz
txr-d0b35b7d272eaf4fbcf7754e25801739ddb2410d.tar.bz2
txr-d0b35b7d272eaf4fbcf7754e25801739ddb2410d.zip
parser: catch out-of-range floats.
* parser.l (out_of_range_float): New static function. (grammar): Check for flo_str returning nil in several places; that value is returned for out of range floats. This is not documented! * txr.1: Document athat flo-str returns nil for out-of-range floats.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l18
1 files changed, 15 insertions, 3 deletions
diff --git a/parser.l b/parser.l
index 7a9d8d8b..c0114b24 100644
--- a/parser.l
+++ b/parser.l
@@ -137,6 +137,12 @@ static void yyerrprepf(scanner_t *scanner, val fmt, ...)
}
}
+static void out_of_range_float(scanner_t *scanner, val tok)
+{
+ yyerrorf(scanner, lit("out-of-range floating-point literal: ~a"),
+ tok, nao);
+}
+
static wchar_t char_esc(int letter)
{
switch (letter) {
@@ -344,7 +350,9 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
|| yy_top_state(yyscanner) == QWLIT)
yy_pop_state(yyscanner);
- yylval->val = flo_str(str);
+ if ((yylval->val = flo_str(str)) == nil)
+ out_of_range_float(yyg, str);
+
return NUMBER;
}
@@ -360,7 +368,9 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
|| yy_top_state(yyscanner) == QWLIT)
yy_pop_state(yyscanner);
- yylval->val = flo_str(str);
+ if ((yylval->val = flo_str(str)) == nil)
+ out_of_range_float(yyg, str);
+
return NUMBER;
}
@@ -372,7 +382,9 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
|| yy_top_state(yyscanner) == QWLIT)
yy_pop_state(yyscanner);
- yylval->val = flo_str(str);
+ if ((yylval->val = flo_str(str)) == nil)
+ out_of_range_float(yyg, str);
+
return NUMBER;
}