
{
{ CLP$SCAN_UNNESTED_CMND_LEX_UNIT updates its PARSE parameter to designate the
{ next lexical unit that is a command separator (semicolon) not nested within
{ parentheses.
{ This procedure requires that the UNITS_ARRAY field of the PARSE parameter be
{ non-NIL.
{

  PROCEDURE [INLINE] clp$scan_unnested_cmnd_lex_unit
    (VAR parse {input, output} : clt$parse_state);

?? PUSH (LISTEXT := ON) ??

    VAR
      done: boolean,
      nesting_level: integer;


    nesting_level := 0;
    done := parse.unit.kind = clc$lex_semicolon;

    WHILE (NOT done) AND (parse.unit_index < parse.index_limit) DO
      IF NOT parse.unit_is_space THEN
        parse.previous_non_space_unit := parse.unit;
        parse.previous_non_space_unit_index := parse.unit_index;
      IFEND;

      parse.previous_unit_is_space := parse.unit_is_space;
      parse.unit_index := parse.index;
      parse.units_array_index := parse.units_array_index + 1;
      parse.unit := parse.units_array^ [parse.units_array_index];
      parse.index := parse.index + parse.unit.size;

      parse.unit_is_space := FALSE;
      CASE parse.unit.kind OF
      = clc$lex_space, clc$lex_comment, clc$lex_unterminated_comment =
        parse.unit_is_space := TRUE;
      = clc$lex_semicolon =
        done := nesting_level <= 0;
      = clc$lex_left_parenthesis =
        nesting_level := nesting_level + $INTEGER (nesting_level >= 0);
      = clc$lex_right_parenthesis =
        nesting_level := nesting_level - 1;
      ELSE
        ;
      CASEND;
    WHILEND;

    IF parse.unit.kind = clc$lex_beginning_of_line THEN
      parse.units_array_index := 2;
      parse.unit.kind := clc$lex_end_of_line;
    IFEND;

  PROCEND clp$scan_unnested_cmnd_lex_unit;

*copyc clt$parse_state
?? POP ??
