goto error;
lex_match (lexer, T_EQUALS);
- if (!lex_force_num_range_halfopen (lexer, "CILEVEL", 0, 100))
+ if (!lex_force_num_range_co (lexer, "CILEVEL", 0, 100))
goto error;
t->cilevel = lex_number (lexer);
lex_get (lexer);
else if (lex_match_id (lexer, "ALPHA"))
{
lex_match (lexer, T_EQUALS);
- if (!lex_force_num_range_halfopen (lexer, "ALPHA", 0, 1))
+ if (!lex_force_num_range_co (lexer, "ALPHA", 0, 1))
goto error;
t->chisq->alpha = lex_number (lexer);
lex_get (lexer);
return false;
}
-/* If the current token is an number in the closed range [MIN,MAX], does
+/* If the current token is a number in the closed range [MIN,MAX], does
nothing and returns true. Otherwise, reports an error and returns false.
If NAME is nonnull, then it is used in the error message. */
bool
return false;
}
-/* If the current token is an number in the half-open range [MIN,MAX), does
+/* If the current token is a number in the half-open range [MIN,MAX), does
nothing and returns true. Otherwise, reports an error and returns false.
If NAME is nonnull, then it is used in the error message. */
bool
-lex_force_num_range_halfopen (struct lexer *lexer, const char *name,
- double min, double max)
+lex_force_num_range_co (struct lexer *lexer, const char *name,
+ double min, double max)
{
bool is_number = lex_is_number (lexer);
bool too_small = is_number && lex_number (lexer) < min;
return false;
}
-/* If the current token is an number in the open range (MIN,MAX), does
+/* If the current token is a number in the half-open range (MIN,MAX], does
+ nothing and returns true. Otherwise, reports an error and returns false.
+ If NAME is nonnull, then it is used in the error message. */
+bool
+lex_force_num_range_oc (struct lexer *lexer, const char *name,
+ double min, double max)
+{
+ bool is_number = lex_is_number (lexer);
+ bool too_small = is_number && lex_number (lexer) <= min;
+ bool too_big = is_number && lex_number (lexer) > max;
+ if (is_number && !too_small && !too_big)
+ return true;
+
+ if (min >= max)
+ {
+ /* Weird, maybe a bug in the caller. Just report that we needed a
+ number. */
+ if (name)
+ lex_error (lexer, _("Syntax error expecting number for %s."), name);
+ else
+ lex_error (lexer, _("Syntax error expecting number."));
+ }
+ else
+ {
+ bool report_lower_bound = min > -DBL_MAX || too_small;
+ bool report_upper_bound = max < DBL_MAX || too_big;
+
+ if (report_lower_bound && report_upper_bound)
+ {
+ if (name)
+ lex_error (lexer, _("Syntax error expecting number "
+ "in (%g,%g] for %s."),
+ min, max, name);
+ else
+ lex_error (lexer, _("Syntax error expecting number in (%g,%g]."),
+ min, max);
+ }
+ else if (report_lower_bound)
+ {
+ if (min == 0)
+ {
+ if (name)
+ lex_error (lexer, _("Syntax error expecting "
+ "positive number for %s."),
+ name);
+ else
+ lex_error (lexer, _("Syntax error expecting positive number."));
+ }
+ else
+ {
+ if (name)
+ lex_error (lexer, _("Syntax error expecting "
+ "number greater than %g for %s."),
+ min, name);
+ else
+ lex_error (lexer, _("Syntax error expecting "
+ "number greater than %g."), min);
+ }
+ }
+ else if (report_upper_bound)
+ {
+ if (name)
+ lex_error (lexer,
+ _("Syntax error expecting number %g or less for %s."),
+ max, name);
+ else
+ lex_error (lexer, _("Syntax error expecting number %g or less."),
+ max);
+ }
+ else
+ {
+ if (name)
+ lex_error (lexer, _("Syntax error expecting number for %s."), name);
+ else
+ lex_error (lexer, _("Syntax error expecting number."));
+ }
+ }
+ return false;
+}
+
+/* If the current token is a number in the open range (MIN,MAX), does
nothing and returns true. Otherwise, reports an error and returns false.
If NAME is nonnull, then it is used in the error message. */
bool
bool lex_force_num (struct lexer *) WARN_UNUSED_RESULT;
bool lex_force_num_range_closed (struct lexer *, const char *name,
double min, double max) WARN_UNUSED_RESULT;
-bool lex_force_num_range_halfopen (struct lexer *, const char *name,
- double min, double max) WARN_UNUSED_RESULT;
+bool lex_force_num_range_co (struct lexer *, const char *name,
+ double min, double max) WARN_UNUSED_RESULT;
+bool lex_force_num_range_oc (struct lexer *, const char *name,
+ double min, double max) WARN_UNUSED_RESULT;
bool lex_force_num_range_open (struct lexer *, const char *name,
double min, double max) WARN_UNUSED_RESULT;
bool lex_force_id (struct lexer *) WARN_UNUSED_RESULT;