# HG changeset patch # User jwe # Date 791148142 0 # Node ID 0cd3ba9c1f61b845eb215bbbbbd20ae1b9cf7741 # Parent cd895d23db6c57cb3ed36a0c36ffa69664ee97c4 [project @ 1995-01-26 19:22:22 by jwe] diff -r cd895d23db6c -r 0cd3ba9c1f61 src/lex.l --- a/src/lex.l Thu Jan 26 04:09:18 1995 +0000 +++ b/src/lex.l Thu Jan 26 19:22:22 1995 +0000 @@ -32,6 +32,7 @@ #endif #include +#include #include #include "input.h" @@ -1668,6 +1669,34 @@ return ']'; } +static void +maybe_unput_comma (int spc_gobbled) +{ + if (user_pref.whitespace_in_literal_matrix != 2 + && ! nesting_level.empty () + && nesting_level.top () == BRACE) + { + int bin_op = next_token_is_bin_op (spc_gobbled, yytext); + + int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled, + yytext); + + int c1 = yyinput (); + int c2 = yyinput (); + unput (c2); + unput (c1); + int sep_op = match_any (c1, ",;\n]"); + int dot_op = (c1 == '.' + && (isalpha (c2) || isspace (c2) || c2 == '_')); + int index_op = (c1 == '(' + && (user_pref.whitespace_in_literal_matrix == 0 + || ! spc_gobbled)); + + if (! (postfix_un_op || bin_op || sep_op || dot_op || index_op)) + unput (','); + } +} + // Figure out exactly what kind of token to return when we have seen // an identifier. Handles keywords. @@ -1680,10 +1709,14 @@ cant_be_identifier = 1; // If we are expecting a structure element, we just want to return -// TEXT_ID, which is a string that is also a valid identifier. +// TEXT_ID, which is a string that is also a valid identifier. But +// first, we have to decide whether to insert a comma. if (looking_at_indirect_ref) - TOK_PUSH_AND_RETURN (tok, TEXT_ID); + { + maybe_unput_comma (spc_gobbled); + TOK_PUSH_AND_RETURN (tok, TEXT_ID); + } // If we have a regular keyword, or a plot STYLE, return it. Keywords // can be followed by identifiers (TOK_RETURN handles that). @@ -1784,27 +1817,7 @@ quote_is_transpose = 1; do_comma_insert_check (); -// Check to see if we should insert a comma. - - if (user_pref.whitespace_in_literal_matrix != 2 - && ! nesting_level.empty () - && nesting_level.top () == BRACE) - { - int bin_op = next_token_is_bin_op (spc_gobbled, yytext); - - int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled, - yytext); - - int c1 = yyinput (); - unput (c1); - int other_op = match_any (c1, ".,;\n]"); - int index_op = (c1 == '(' - && (user_pref.whitespace_in_literal_matrix == 0 - || ! spc_gobbled)); - - if (! (postfix_un_op || bin_op || other_op || index_op)) - unput (','); - } + maybe_unput_comma (spc_gobbled); current_input_column += yyleng; return NAME;