function sz = numArgumentsFromSubscript(g,s,context)
%NUMARGUMENTSFROMSUBSCRIPT Number of output arguments for a subscript into graph properties.

% This function is for internal use only and will change in a
% future release.  Do not use this function.

%   Copyright 2023 The MathWorks, Inc.

import matlab.internal.datatypes.isColon

% This is taken and slightly adjusted from table/numArgumentsFromSubscript

if length(s) <= 2 % one level of subscripting on graph/digraph or on table
    sz = 1; % graph returns one output for parens, braces, and dot on its tables.
elseif context == matlab.mixin.util.IndexingContext.Assignment
    sz = 1; % table subsasgn only ever accepts one rhs value, same for graph/digraph
else % multiple subscripting levels
    S1subs = s(1).subs;

    if strcmp(S1subs, 'Edges')
        t = g.Edges;
    elseif strcmp(S1subs, 'Nodes')
        % Special-case for performance: Case where only Nodes.Name cell
        % array is stored, table would be made on-the-fly if needed
        % No other special cases needed, as they would error whenever last
        % subs is '.' or '{}'.
        s2 = s(2);
        if iscell(g.NodeProperties) && s2.type == "." && s2.subs == "Name"
            sz = numArgumentsFromSubscript(g.NodeProperties, s(3:end), context);
            return
        end

        t = g.Nodes;
    else
        % This will error in subsref/subsasgn, sz doesn't matter.
        sz = 1;
        return;
    end
    s(1) = [];
    
    % Pass on remaining subscripts to table's method
    sz = numArgumentsFromSubscript(t, s, context);
end
