
{
{ CLP$SCAN_BAL_PAREN_LEXICAL_UNIT is called after encountering a left
{ parenthesis and updates its PARSE parameter to designate the balancing right
{ parentheses lexical unit.
{ This procedure requires that the UNITS_ARRAY field of the PARSE parameter be
{ non-NIL.
{

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

?? PUSH (LISTEXT := ON) ??

    VAR
      nesting_level: clt$string_size;


    IF parse.unit_index < parse.index_limit THEN
      nesting_level := 1;
      REPEAT
        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_left_parenthesis =
          nesting_level := nesting_level + 1;
        = clc$lex_right_parenthesis =
          nesting_level := nesting_level - 1;
        ELSE
          ;
        CASEND;

      UNTIL (nesting_level <= 0) OR (parse.unit_index >= parse.index_limit);
    IFEND;

  PROCEND clp$scan_bal_paren_lexical_unit;

*copyc clt$parse_state
*copyc clt$string_size
?? POP ??
