public List<SplitPoint> GetSplitPoints(Scope root, int newScopeStartIndex, int newScopeLength) { List<SplitPoint> splitPoints = new List<SplitPoint>(); if(root.IsFlat) { return splitPoints; } int requestedEndPos = newScopeStartIndex + newScopeLength - 1; Scope innerLeft = root.FindInnerScope(newScopeStartIndex, 1); Scope innerRight = root.FindInnerScope(requestedEndPos, 1); bool isSpillingLeft = (innerLeft.StartPosInRootScope < newScopeStartIndex); bool isSpillingRight = (innerRight.EndPosInRootScope > requestedEndPos); if (isSpillingLeft) { int splitLength = (innerLeft.EndPosInRootScope-newScopeStartIndex)+1; splitPoints.Add(new SplitPoint(newScopeStartIndex, splitLength)); } if (isSpillingRight) { int splitLength = (requestedEndPos-innerRight.StartPosInRootScope)+1; splitPoints.Add(new SplitPoint(innerRight.StartPosInRootScope, splitLength)); // splitPoints.Add(new SplitPoint(requestedEndPos, splitLength)); } return splitPoints; }
public List <SplitPoint> GetSplitPoints(Scope root, int newScopeStartIndex, int newScopeLength) { List <SplitPoint> splitPoints = new List <SplitPoint>(); if (root.IsFlat) { return(splitPoints); } int requestedEndPos = newScopeStartIndex + newScopeLength - 1; Scope innerLeft = root.FindInnerScope(newScopeStartIndex, 1); Scope innerRight = root.FindInnerScope(requestedEndPos, 1); bool isSpillingLeft = (innerLeft.StartPosInRootScope < newScopeStartIndex); bool isSpillingRight = (innerRight.EndPosInRootScope > requestedEndPos); if (isSpillingLeft) { int splitLength = (innerLeft.EndPosInRootScope - newScopeStartIndex) + 1; splitPoints.Add(new SplitPoint(newScopeStartIndex, splitLength)); } if (isSpillingRight) { int splitLength = (requestedEndPos - innerRight.StartPosInRootScope) + 1; splitPoints.Add(new SplitPoint(innerRight.StartPosInRootScope, splitLength)); // splitPoints.Add(new SplitPoint(requestedEndPos, splitLength)); } return(splitPoints); }
public bool IsMultipleSplittingNeededFor(Scope root, int newScopeStartIndex, int newScopeLength) { int requestedEndPos = newScopeStartIndex + newScopeLength - 1; Scope innerLeft = root.FindInnerScope(newScopeStartIndex, 1); Scope innerRight = root.FindInnerScope(requestedEndPos, 1); bool isSpillingLeft = (innerLeft.StartPosInRootScope < newScopeStartIndex); bool isSpillingRight = (innerRight.EndPosInRootScope > requestedEndPos); return(isSpillingRight && isSpillingLeft); }
public Scope FindInnerScope(int startPos, int length) { int requestedEndPos = startPos + length - 1; if (EndPosInRootScope < requestedEndPos || startPos < startPosInRootScope) { throw new InvalidOperationException("Invalid start position requested"); } if (IsFlat) { return(this); } if (innerMiddleScope != null && innerMiddleScope.EncapsulatesTextPart(startPos, length)) { return(innerMiddleScope.FindInnerScope(startPos, length)); } if (innerRightScope.EncapsulatesTextPart(startPos, length)) { return(innerRightScope.FindInnerScope(startPos, length)); } if (innerLeftScope.EncapsulatesTextPart(startPos, length)) { return(innerLeftScope.FindInnerScope(startPos, length)); } return(null); }
public void AutoScope(Scope root) { if (autoAdvisor == null) { return; } foreach (Suggestion possibility in autoAdvisor.possibleMatches) { Match match = Regex.Match(root.Text, possibility.RegexText); if (match.Success) { Scope innerScope = root.FindInnerScope(match.Index, match.Length); if (innerScope == null || innerScope.Length != match.Length) { List <SplitPoint> points = new ScopeSplitter().GetSplitPoints(root, match.Index, match.Length); bool willNewScopeBeInsdeAScopeWithSuggestions = false; if (points.Count > 0) { foreach (SplitPoint point in points) { Scope target = root.FindInnerScope(point.StartIndex, point.Length); if (target != null && target.Suggestions.Count > 0) { willNewScopeBeInsdeAScopeWithSuggestions = true; break; } } } if (!willNewScopeBeInsdeAScopeWithSuggestions) { innerScope = root.DefineInnerScope(match.Index, match.Length); } } if (innerScope != null) { innerScope.Suggestions.Add(possibility); innerScope.IsExplicit = true; } } } }
public void AutoScope(Scope root) { if(autoAdvisor==null) { return; } foreach (Suggestion possibility in autoAdvisor.possibleMatches) { Match match = Regex.Match(root.Text, possibility.RegexText); if (match.Success) { Scope innerScope = root.FindInnerScope(match.Index, match.Length); if (innerScope == null || innerScope.Length!=match.Length) { List<SplitPoint> points = new ScopeSplitter().GetSplitPoints(root, match.Index, match.Length); bool willNewScopeBeInsdeAScopeWithSuggestions = false; if (points.Count>0) { foreach (SplitPoint point in points) { Scope target = root.FindInnerScope(point.StartIndex, point.Length); if(target!=null && target.Suggestions.Count>0) { willNewScopeBeInsdeAScopeWithSuggestions = true; break; } } } if(!willNewScopeBeInsdeAScopeWithSuggestions) innerScope = root.DefineInnerScope(match.Index, match.Length); } if (innerScope!=null) { innerScope.Suggestions.Add(possibility); innerScope.IsExplicit = true; } } } }
public Scope Split(Scope root, SplitPoint splitPoint, bool isImplicit) { Scope inner = root.FindInnerScope(splitPoint.StartIndex, 1); int requiredLength = splitPoint.Length; if (requiredLength == inner.Length) { requiredLength -= 1; } Scope newScope = inner.DefineInnerScope(splitPoint.StartIndex, requiredLength); newScope.IsImplicit = isImplicit; return(newScope); }
public void GetInnerScope_InMiddleInnerScope_GetsCorrectScope() { scope = new Scope("abcde"); Scope inner = scope.DefineInnerScope(1, 3);//'bcd' Scope deepInner = inner.DefineInnerScope(2, 1);//'c' Assert.AreSame(deepInner, scope.FindInnerScope(2, 1));//c }
public void GetInnerScope_InLeftInnerScope_GetsCorrectScope() { scope = new Scope("012345"); Scope inner = scope.DefineInnerScope(0, 3);//'012' Scope deepInner = inner.DefineInnerScope(2, 1);//'2' Assert.AreSame(deepInner, scope.FindInnerScope(2, 1));//2 }
public void GetInnerScope_GetsCorrectScopeWithInnerLeftLongerThanLength() { scope = new Scope("a bcdefgehi"); scope.DefineInnerScope(5, 2);//'fg' Assert.AreSame(scope.InnerMiddleScope, scope.FindInnerScope(5, 2));//fg' }
public void GetInnerScope_ForWholeRootScope_ReturnsRoot() { scope = new Scope("defge"); Assert.AreSame(scope, scope.FindInnerScope(0, scope.Length)); }
public void GetInnerScope_overflowingLengthFromMiddle_THrowsException() { scope = new Scope("defge");//flat scope.FindInnerScope(3, 3);//one char overflow }
public void GetInnerScope_MiddleIsNullByCharPos_GetsCorrectScope() { scope = new Scope("defge"); scope.DefineInnerScope(0, 2);//'de' Assert.AreSame(scope.InnerLeftScope, scope.FindInnerScope(1, 1));//g }
public bool IsMultipleSplittingNeededFor(Scope root, int newScopeStartIndex, int newScopeLength) { int requestedEndPos = newScopeStartIndex + newScopeLength - 1; Scope innerLeft = root.FindInnerScope(newScopeStartIndex, 1); Scope innerRight = root.FindInnerScope(requestedEndPos, 1); bool isSpillingLeft = (innerLeft.StartPosInRootScope < newScopeStartIndex); bool isSpillingRight = (innerRight.EndPosInRootScope > requestedEndPos); return (isSpillingRight && isSpillingLeft); }
public Scope Split(Scope root, SplitPoint splitPoint, bool isImplicit) { Scope inner = root.FindInnerScope(splitPoint.StartIndex, 1); int requiredLength = splitPoint.Length; if(requiredLength==inner.Length) { requiredLength -= 1; } Scope newScope = inner.DefineInnerScope(splitPoint.StartIndex, requiredLength); newScope.IsImplicit= isImplicit; return newScope; }
public void GetInnerScope_InRightInnerScope_GetsCorrectScope() { scope = new Scope("012345"); Scope inner = scope.DefineInnerScope(3, 3);//'345' Scope deepInner = inner.DefineInnerScope(3, 1);//'3' Assert.AreSame(deepInner, scope.FindInnerScope(3, 1));//3 }
public void GetInnerScope_IsFlat_ReturnsThis() { scope = new Scope("defge");//flat Assert.AreSame(scope, scope.FindInnerScope(2, 1)); }
public void GetInnerScope_ByCharPos_GetsCorrectScope2() { scope = new Scope("defge"); scope.DefineInnerScope(2, 2);//'fg' Assert.AreSame(scope.InnerRightScope, scope.FindInnerScope(4, 1));//e }
public void GetInnerScope_NegativeStartPos_ThrowsException() { scope = new Scope("defge");//flat scope.FindInnerScope(-1, 1); }
public void GetInnerScope_ByCharPos_GetsCorrectScope5() { scope = new Scope("defge"); scope.DefineInnerScope(1, 1);//'e' Scope found = scope.FindInnerScope(4, 1);//'fge' Assert.AreSame(scope.InnerRightScope, found);//e }
public void GetInnerScope_overflowingLength_THrowsException() { scope = new Scope("defge");//flat scope.FindInnerScope(0, scope.Length + 1); }
public void GetInnerScope_ByCharPos_GetsCorrectScope6() { scope = new Scope("defge"); scope.DefineInnerScope(2, 2);//'fg' Assert.AreSame(scope.InnerMiddleScope, scope.FindInnerScope(3, 1));//g }