//public override ElementBase ReturnParseTreeFromExistingElement(ElementBase ExisitngElement) //{ // //for now I am the top element inthe chain so add it to me and return myself // AddContainedElement(ExisitngElement); // return this; //} internal override MatchResult SubBeginProcessMatch(Tracker tracker, IEventStream eventenum, CaptureList CapturedList) { //first lets check the statebag to see if we are in there yet var sbag = GetQuantifierState(tracker); if (!sbag.MatchCount.HasValue) { sbag.MatchCount = new Nullable <int>(0); tracker.SetMyStateBag(this, sbag); } //Pass the event along to the contained element and get its result var subRes = ContainedElement.BeginProcessMatch(tracker, eventenum, sbag.CaptureList); MatchResult tres = IsMatchResult.IsNotMatch; if (QuantifierSymbol == '+') { tres = HandlePlus(sbag.MatchCount, subRes); } if (QuantifierSymbol == '*') { tres = HandleStar(sbag.MatchCount, subRes); } if (QuantifierSymbol == '?') { tres = HandleQuestionMark(sbag.MatchCount, subRes); } //if its the end (either a match or not) , then remove our bag state if (!tres.Is_Continue()) { if (tres.Is_Match()) { //specEventStream.EndApplyAll(); if (CapturedList != null) { CapturedList.AddRange(sbag.CaptureList.Items); } } tracker.RemoveMyStateBag(this); } else { //if its a continue then increment the bagstate sbag.MatchCount = sbag.MatchCount.Value + 1; tracker.SetMyStateBag(this, sbag); } //return to the tracker the result if (subRes.Is_Forward()) { tres = tres | MatchResult.Forward; } return(tres); }
internal override MatchResult BeginProcessMatch(Tracker tracker, IEventStream eventenum, CaptureList CapturedList) { tracker.DebugStart(this); //we don't want to capture so send in a null var r = ContainedElement.BeginProcessMatch(tracker, eventenum, null); if (tracker.DebugEnabled) { tracker.SaveDBGResult(this, r); } return(r); }
internal override MatchResult BeginProcessMatch(Tracker tracker, IEventStream eventenum, CaptureList CapturedList) { //can't neagte a null - if null event then return no match if (eventenum.Current == null) { return(IsMatchResult.IsNotMatch); } var a = ContainedElement.BeginProcessMatch(tracker, eventenum, null); if (a.Is_Match()) { a = IsMatchResult.IsNotMatch; } else { CapturedList.Add(eventenum.Current); a = IsMatchResult.IsMatch; } return(a); }
internal override MatchResult SubBeginProcessMatch(Tracker tracker, IEventStream eventenum, CaptureList CapturedList) { if (eventenum.Current == null) { return(MatchResult.None); } MatchResult tres = MatchResult.None; var sbag = GetQuantifierState(tracker); if (!sbag.MatchCount.HasValue) { sbag.MatchCount = new Nullable <int>(0); tracker.SetMyStateBag(this, sbag); } var specEventStream = eventenum;//eventenum.CreateSpeculator(); do { MatchResult subRes = MatchResult.None; subRes = ContainedElement.BeginProcessMatch(tracker, eventenum, sbag.CaptureList); if (!subRes.Is_Match()) { //if we matched our minimun we can make a final decisison if it did not match if (sbag.MatchCount.Value >= MinOccours) { tres = MatchResult.Match | MatchResult.Forward; } else//if we have not yet matched our minimun then we just need to continue { tres = MatchResult.Continue | MatchResult.Capture; } } //if we did match if (subRes.Is_Match()) { //if we reached the max then return a match if (sbag.MatchCount.Value + 1 == MaxOccours) { tres = IsMatchResult.IsMatch; } else { //if we matched at least min then mark as match and contineu if (sbag.MatchCount.Value + 1 >= MinOccours) { tres = MatchResult.Match | MatchResult.Continue | MatchResult.Capture; } else { //just continue matching //if the subres has a forward , then don't capture , just relay the forward if (subRes.Is_Forward()) { tres = MatchResult.Continue | MatchResult.Forward; } else { tres = MatchResult.Continue | MatchResult.Capture; } } } } //if its the end (either a match or not) , then remove our bag state if (!tres.Is_Continue()) { tracker.RemoveMyStateBag(this); } else { //if its a continue then increment the bagstate sbag.MatchCount++; tracker.SetMyStateBag(this, sbag); } if (subRes.Is_Forward()) { tres = tres | MatchResult.Forward; } //if this is a match without a continue then grab the commmit the speculator //and add the spculative captures to the tracker captures if (tres.Is_Match() && !tres.Is_Continue()) { //specEventStream.EndApplyAll(); if (CapturedList != null) { CapturedList.AddRange(sbag.CaptureList.Items); } return(tres); } //if this is not a match and not a continue then rollback the speculator and return the result if (!tres.Is_Match() && !tres.Is_Continue()) { //specEventStream.EndDiscardAll(); return(tres); } //its a continue so allow the loop to continue }while ( specEventStream.MoveNextIfNotForward(tres)); //if we are here it means that we ran out of events so we got to deal with that if (tres.Is_Match()) { if (CapturedList != null) { CapturedList.AddRange(sbag.CaptureList.Items); } } //remove the continue if its there if (tres.Is_Continue()) { var mask = ~MatchResult.Continue; tres = tres & mask; } return(tres); }