src/NFun/SyntaxParsing/SyntaxNodeReader.cs
/// <summary>
/// Read array index or array slice node
/// </summary>
Read array index or array slice node
Read array index or array slice node
private static ISyntaxNode ReadArraySliceNode(TokFlow flow, ISyntaxNode arrayNode) {
        var openBraket = flow.Current;
        flow.MoveNext();
        var index = ReadNodeOrNull(flow);
        if (!flow.MoveIf(TokType.Colon, out var colon))
        {
            if (index == null)
            {
                if (flow.MoveIf(TokType.ArrCBr, out var closeBracket))
                    throw ErrorFactory.ArrayIndexExpected(openBraket, closeBracket);
                else
                    throw ErrorFactory.ArrayIndexOrSliceExpected(openBraket);
            }
            if (!flow.MoveIf(TokType.ArrCBr))
                throw ErrorFactory.ArrayIndexCbrMissed(openBraket, flow.Current);
            return SyntaxNodeFactory.OperatorFun(
                CoreFunNames.GetElementName,
                new[] { arrayNode, index }, openBraket.Start,
                flow.Position);
        }
        index ??= SyntaxNodeFactory.Constant(0, FunnyType.Int32, new Interval(openBraket.Start, colon.Finish));
        var end = ReadNodeOrNull(flow) ??
                  SyntaxNodeFactory.Constant(int.MaxValue, FunnyType.Int32, new Interval(colon.Finish, flow.Position));
        if (!flow.MoveIf(TokType.Colon, out _))
        {
            if (!flow.MoveIf(TokType.ArrCBr))
                throw ErrorFactory.ArraySliceCbrMissed(openBraket, flow.Current, false);
            return SyntaxNodeFactory.OperatorFun(
                CoreFunNames.SliceName, new[] {
                    arrayNode,
                    index,
                    end
                }, openBraket.Start, flow.Position);
        }
        var step = ReadNodeOrNull(flow);
        if (!flow.MoveIf(TokType.ArrCBr))
            throw ErrorFactory.ArraySliceCbrMissed(openBraket, flow.Current, true);
        if (step == null)
            return SyntaxNodeFactory.OperatorFun(
                CoreFunNames.SliceName, new[] {
                    arrayNode, index, end
                }, openBraket.Start, flow.Position);
        return SyntaxNodeFactory.OperatorFun(
            CoreFunNames.SliceName, new[] {
                arrayNode, index, end, step
            }, openBraket.Start, flow.Position);
    }
private static ISyntaxNode ReadArraySliceNode ( TokFlow flow , ISyntaxNode arrayNode ) { var openBraket = flow . Current ; flow . MoveNext ( ) ; var index = ReadNodeOrNull ( flow ) ; if ( ! flow . MoveIf ( TokType . Colon , out var colon ) ) { if ( index == null ) { if ( flow . MoveIf ( TokType . ArrCBr , out var closeBracket ) ) throw ErrorFactory . ArrayIndexExpected ( openBraket , closeBracket ) ; else throw ErrorFactory . ArrayIndexOrSliceExpected ( openBraket ) ; } if ( ! flow . MoveIf ( TokType . ArrCBr ) ) throw ErrorFactory . ArrayIndexCbrMissed ( openBraket , flow . Current ) ; return SyntaxNodeFactory . OperatorFun ( CoreFunNames . GetElementName , new [ ] { arrayNode , index } , openBraket . Start , flow . Position ) ; } index ??= SyntaxNodeFactory . Constant ( 0 , FunnyType . Int32 , new Interval ( openBraket . Start , colon . Finish ) ) ; var end = ReadNodeOrNull ( flow ) ?? SyntaxNodeFactory . Constant ( int . MaxValue , FunnyType . Int32 , new Interval ( colon . Finish , flow . Position ) ) ; if ( ! flow . MoveIf ( TokType . Colon , out _ ) ) { if ( ! flow . MoveIf ( TokType . ArrCBr ) ) throw ErrorFactory . ArraySliceCbrMissed ( openBraket , flow . Current , false ) ; return SyntaxNodeFactory . OperatorFun ( CoreFunNames . SliceName , new [ ] { arrayNode , index , end } , openBraket . Start , flow . Position ) ; } var step = ReadNodeOrNull ( flow ) ; if ( ! flow . MoveIf ( TokType . ArrCBr ) ) throw ErrorFactory . ArraySliceCbrMissed ( openBraket , flow . Current , true ) ; if ( step == null ) return SyntaxNodeFactory . OperatorFun ( CoreFunNames . SliceName , new [ ] { arrayNode , index , end } , openBraket . Start , flow . Position ) ; return SyntaxNodeFactory . OperatorFun ( CoreFunNames . SliceName , new [ ] { arrayNode , index , end , step } , openBraket . Start , flow . Position ) ; }
Read array index or array slice node
Read array index or array slice node
flow
TokFlow
arrayNode
ISyntaxNode