stores a 1-based column number into *COLUMN if successful,
otherwise emits an error message and returns false. */
static bool
-parse_column (struct lexer *lexer, int base, int *column)
+parse_column (int value, int base, int *column)
{
assert (base == 0 || base == 1);
- if (!lex_force_int (lexer))
- return false;
- *column = lex_integer (lexer) - base + 1;
+ *column = value - base + 1;
if (*column < 1)
{
if (base == 1)
msg (SE, _("Column positions for fields must not be negative."));
return false;
}
- lex_get (lexer);
return true;
}
bool *range_specified)
{
/* First column. */
- if (!parse_column (lexer, base, first_column))
+ if (!lex_force_int (lexer)
+ || !parse_column (lex_integer (lexer), base, first_column))
return false;
+ lex_get (lexer);
/* Last column. */
- lex_negative_to_dash (lexer);
- if (lex_match (lexer, T_DASH))
+ if (lex_is_integer (lexer) && lex_integer (lexer) < 0)
{
- if (!parse_column (lexer, base, last_column))
+ if (!parse_column (-lex_integer (lexer), base, last_column))
return false;
+ lex_get (lexer);
+
if (*last_column < *first_column)
{
msg (SE, _("The ending column for a field must be "
const struct operator *op;
for (op = ops; op < ops + op_cnt; op++)
- {
- if (op->token == T_DASH)
- lex_negative_to_dash (lexer);
- if (lex_match (lexer, op->token))
- {
- if (operator != NULL)
- *operator = op;
- return true;
- }
- }
+ if (lex_token (lexer) == op->token)
+ {
+ if (op->token != T_NEG_NUM)
+ lex_get (lexer);
+ if (operator != NULL)
+ *operator = op;
+ return true;
+ }
if (operator != NULL)
*operator = NULL;
return false;
{
{ T_PLUS, OP_ADD, "addition (`+')" },
{ T_DASH, OP_SUB, "subtraction (`-')" },
+ { T_NEG_NUM, OP_ADD, "subtraction (`-')" },
};
return parse_binary_operators (lexer, e, parse_mul (lexer, e),
"That is, `a**b**c' equals `(a**b)**c', not as `a**(b**c)'. "
"To disable this warning, insert parentheses.");
- return parse_binary_operators (lexer, e, parse_primary (lexer, e), &op, 1,
- parse_primary, chain_warning);
+ union any_node *lhs, *node;
+ bool negative = false;
+
+ if (lex_token (lexer) == T_NEG_NUM)
+ {
+ lhs = expr_allocate_number (e, -lex_tokval (lexer));
+ negative = true;
+ lex_get (lexer);
+ }
+ else
+ lhs = parse_primary (lexer, e);
+
+ node = parse_binary_operators (lexer, e, lhs, &op, 1,
+ parse_primary, chain_warning);
+ return negative ? expr_allocate_unary (e, OP_NEG, node) : node;
}
/* Parses system variables. */
{
char *tail;
- /* `-' can introduce a negative number, or it can be a
- token by itself. If it is not followed by a digit or a
- decimal point, it is definitely not a number.
- Otherwise, it might be either, but most of the time we
- want it as a number. When the syntax calls for a `-'
- token, lex_negative_to_dash() must be used to break
- negative numbers into two tokens. */
+ /* `-' can introduce a negative number, or it can be a token by
+ itself. */
if (*lexer->prog == '-')
{
ds_put_byte (&lexer->tokstr, *lexer->prog++);
\f
/* Really weird functions. */
-/* Most of the time, a `-' is a lead-in to a negative number. But
- sometimes it's actually part of the syntax. If a dash can be part
- of syntax then this function is called to rip it off of a
- number. */
-void
-lex_negative_to_dash (struct lexer *lexer)
-{
- if (lexer->token == T_NEG_NUM)
- {
- lexer->token = T_POS_NUM;
- lexer->tokval = -lexer->tokval;
- ds_assign_substring (&lexer->tokstr, ds_substr (&lexer->tokstr, 1, SIZE_MAX));
- save_token (lexer);
- lexer->token = T_DASH;
- }
-}
-
/* Skip a COMMENT command. */
void
lex_skip_comment (struct lexer *lexer)
const struct string *lex_tokstr (const struct lexer *);
/* Really weird functions. */
-void lex_negative_to_dash (struct lexer *);
void lex_skip_comment (struct lexer *);
#endif /* !lexer_h */