Exemple #1
0
 internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
 {
     SliceStart?.AppendCodeString(res, ast, format);
     if (!this.IsIncompleteNode(ast))
     {
         format.Append(res, format.SpaceBeforeSliceColon, " ", string.Empty, this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? "");
         res.Append(':');
         if (SliceStop != null)
         {
             string ws = null;
             if (format.SpaceAfterSliceColon.HasValue)
             {
                 ws = string.Empty;
                 format.Append(res, format.SpaceAfterSliceColon, " ", string.Empty, string.Empty);
             }
             SliceStop.AppendCodeString(res, ast, format, ws);
         }
         if (StepProvided)
         {
             format.Append(res, format.SpaceBeforeSliceColon, " ", string.Empty, this.GetSecondWhiteSpaceDefaultNull(ast) ?? "");
             res.Append(':');
             if (SliceStep != null)
             {
                 string ws = null;
                 if (format.SpaceAfterSliceColon.HasValue)
                 {
                     ws = string.Empty;
                     format.Append(res, format.SpaceAfterSliceColon, " ", string.Empty, string.Empty);
                 }
                 SliceStep.AppendCodeString(res, ast, format, ws);
             }
         }
     }
 }
Exemple #2
0
 public override void Walk(PythonWalker walker)
 {
     if (walker.Walk(this))
     {
         SliceStart?.Walk(walker);
         SliceStop?.Walk(walker);
         SliceStep?.Walk(walker);
     }
     walker.PostWalk(this);
 }
Exemple #3
0
 public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace)
 {
     if (SliceStart != null)
     {
         SliceStart.SetLeadingWhiteSpace(ast, whiteSpace);
     }
     else
     {
         base.SetLeadingWhiteSpace(ast, whiteSpace);
     }
 }
Exemple #4
0
 public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default)
 {
     if (await walker.WalkAsync(this, cancellationToken))
     {
         if (SliceStart != null)
         {
             await SliceStart.WalkAsync(walker, cancellationToken);
         }
         if (SliceStop != null)
         {
             await SliceStop.WalkAsync(walker, cancellationToken);
         }
         if (SliceStep != null)
         {
             await SliceStep.WalkAsync(walker, cancellationToken);
         }
     }
     await walker.PostWalkAsync(this, cancellationToken);
 }
Exemple #5
0
        private void ParseStartLength(out bool startOk, out long sliceStart,
                                      out bool lengthOk, out long sliceLength)
        {
            startOk = lengthOk = true;

            if (string.IsNullOrEmpty(SliceStart))
            {
                sliceStart = 0;
            }
            else if (Number.TryParseLong(SliceStart.Trim(), out sliceStart, out int unused1))
            {
                if (sliceStart < 0 || sliceStart >= mFileLength)
                {
                    startOk = false;
                }
            }
            else
            {
                startOk = false;
            }

            if (string.IsNullOrEmpty(SliceLength))
            {
                sliceLength = mFileLength - sliceStart;
                if (sliceLength < 0)
                {
                    sliceLength = 0;
                }
            }
            else if (Number.TryParseLong(SliceLength.Trim(), out sliceLength, out int unused2))
            {
                if (sliceLength <= 0 || sliceLength > mFileLength ||
                    sliceStart + sliceLength > mFileLength)
                {
                    lengthOk = false;
                }
            }
            else
            {
                lengthOk = false;
            }
        }
Exemple #6
0
 public override string GetLeadingWhiteSpace(PythonAst ast)
 => SliceStart != null?SliceStart.GetLeadingWhiteSpace(ast) : this.GetPreceedingWhiteSpace(ast);