public string GetFirstValue(int patternIndex) { StateItem item = States[0]; int index = GetFirstMatchedIndex(patternIndex); string value = item.GetEntityValue(index - StartIndex); if (value == null) { value = Entities[index].Value; } return(value); }
/// <summary> /// Adds passed indexes to StateItem. /// </summary> /// <param name="patternIndex">Index of passed pattern.</param> /// <param name="subStateItem">Passed indexes in sub pattern.</param> /// <param name="passedIndex">Only this index will be added to passed.</param> public void AddPassed(int patternIndex, StateItem subStateItem, int passedIndex, string value) { for (int i = 0; i < subStateItem.CountOfPassedEntities; i++) { if (subStateItem.Passed[i] == passedIndex) { if (value != null) { SetEntityValue(NextEntityIndex, value); } Passed.Add(patternIndex); } else { Passed.Add(-1); } } }
public List <IEntity>[] GetMatch() { List <IEntity>[] result = new List <IEntity> [ParentRegex.AllRegex.Length]; StateItem item = States[0]; for (int entityIndex = 0; entityIndex < item.Passed.Count; entityIndex++) { int patternIndex = item.Passed[entityIndex]; if (patternIndex == -1) { continue; } if (result[patternIndex] == null) { result[patternIndex] = new List <IEntity>(); } result[patternIndex].Add(Entities[StartIndex + entityIndex]); } return(result); }
public override EntityRegexMatchState Interpret(EntityRegexMatchInfo info, EntityRegexMatchState state) { if (state == null || state.Count == 0) { return(null); } EntityRegexMatchState result = new EntityRegexMatchState(); //foeach Regex (ClauseHolder item) in ClauseHolder foreach (ClauseHolder.ClauseItem clauseHolderItem in Holder.Items) { //foreach stateItem in original state foreach (StateItem stateItem in state) { if (info.StartIndex + stateItem.NextEntityIndex < info.Entities.Length) { //evaluate regex EntityRegexMatchInfo temp = clauseHolderItem.Regex.Interpret(info.Entities, info.StartIndex + stateItem.NextEntityIndex); if (temp.States != null) { //foreach stateItem in evaluated result foreach (StateItem subStateItem in temp.States) { //new state item StateItem tempStateItem = new StateItem(stateItem); //item passed for current pattern index, subStateItem only clauseHolderItem.Index indexes. tempStateItem.AddPassed(info.CurrentPatternIndex, subStateItem, clauseHolderItem.Index, clauseHolderItem.Value); result.Add(tempStateItem); } } } } } return(result); }
public StateItem(StateItem item) { Passed = new List <int>(item.Passed); }
/// <summary> /// Adds passed indexes to StateItem. /// </summary> /// <param name="patternIndex">Index of passed pattern.</param> /// <param name="subStateItem">Passed indexes in sub pattern.</param> /// <param name="passedIndex">Only this index will be added to passed.</param> public void AddPassed(int patternIndex, StateItem subStateItem, int passedIndex) { AddPassed(patternIndex, subStateItem, patternIndex, null); }
public bool NextEntityExists(StateItem stateItem) { return(StartIndex + stateItem.NextEntityIndex < Entities.Length); }
public IEntity GetNextEntity(StateItem stateItem) { return(Entities[StartIndex + stateItem.NextEntityIndex]); }