protected Boolean ZeroOrMore(IsMatchPredicate expression, String grammarExpression) { Int32 savePosition = iterator.Index; while (expression()) { if (savePosition == iterator.Index) { Exception ex = new InfiniteLoopDetectedException(); ex.Data.Add("Iterator Index", iterator.Index); ex.Data.Add("Grammar Expression", grammarExpression); throw ex; } savePosition = iterator.Index; } iterator.Index = savePosition; return(true); }
protected Boolean LimitingRepetition(IsMatchPredicate expression, Int32?min, Int32?max, String grammarExpression) { Int32 cnt = 0; Int32 savePosition = iterator.Index; Boolean result = false; if (min != null) { if (max == null) { // has a minimum but no max cap savePosition = iterator.Index; while (expression()) { if (savePosition == iterator.Index) { Exception ex = new InfiniteLoopDetectedException(); ex.Data.Add("Iterator Index", iterator.Index); ex.Data.Add("Grammar Expression", grammarExpression); throw ex; } cnt++; savePosition = iterator.Index; } iterator.Index = savePosition; result = (cnt >= min); } else { // has a minimum and a max specified if (max < min) { throw new ArgumentException("A Max property must be larger than Min when using LimitingRepetition."); } savePosition = iterator.Index; while (expression()) { cnt++; savePosition = iterator.Index; if (cnt >= max) { break; } } iterator.Index = savePosition; result = (cnt <= max && cnt >= min); } } else { if (max == null) { throw new ArgumentException("A Min and/or Max must be specified when using LimitingRepetition."); } else { // zero or up to a max matches of e. savePosition = iterator.Index; while (expression()) { cnt++; savePosition = iterator.Index; if (cnt >= max) { break; } } iterator.Index = savePosition; result = (cnt <= max); } } return(result); }
protected Boolean LimitingRepetition(IsMatchPredicate expression, Int32? min, Int32? max, String grammarExpression) { Int32 cnt = 0; Int32 savePosition = iterator.Index; Boolean result = false; if (min != null) { if (max == null) { // has a minimum but no max cap savePosition = iterator.Index; while (expression()) { if (savePosition == iterator.Index) { Exception ex = new InfiniteLoopDetectedException(); ex.Data.Add("Iterator Index", iterator.Index); ex.Data.Add("Grammar Expression", grammarExpression); throw ex; } cnt++; savePosition = iterator.Index; } iterator.Index = savePosition; result = (cnt >= min); } else { // has a minimum and a max specified if (max < min) { throw new ArgumentException("A Max property must be larger than Min when using LimitingRepetition."); } savePosition = iterator.Index; while (expression()) { cnt++; savePosition = iterator.Index; if (cnt >= max) { break; } } iterator.Index = savePosition; result = (cnt <= max && cnt >= min); } } else { if (max == null) { throw new ArgumentException("A Min and/or Max must be specified when using LimitingRepetition."); } else { // zero or up to a max matches of e. savePosition = iterator.Index; while (expression()) { cnt++; savePosition = iterator.Index; if (cnt >= max) { break; } } iterator.Index = savePosition; result = (cnt <= max); } } return result; }
protected Boolean OneOrMore(IsMatchPredicate expression, String grammarExpression) { Int32 cnt = 0; Int32 savePosition = iterator.Index; while (expression()) { if (savePosition == iterator.Index) { Exception ex = new InfiniteLoopDetectedException(); ex.Data.Add("Iterator Index", iterator.Index); ex.Data.Add("Grammar Expression", grammarExpression); throw ex; } savePosition = iterator.Index; cnt++; } iterator.Index = savePosition; return (cnt > 0); }