public IMatch Match(string text) { var elem = new OneOrMore(element); var sep = new OneOrMore(separator); var matchElem = elem.Match(text); var matchSep = sep.Match(matchElem.RemainingText()); while (matchElem.Success()) { var previous = matchElem; text = matchSep.RemainingText(); matchElem = elem.Match(text); matchSep = sep.Match(matchElem.RemainingText()); if (!matchElem.Success()) { return(new SuccessMatch(previous.RemainingText())); } } return(new SuccessMatch(matchElem.RemainingText())); //string textCopy = text; //var elem = element.Match(text); //var sep = separator.Match(elem.RemainingText()); //while (elem.Success()) //{ // if (!sep.Success()) return new SuccessMatch(elem.RemainingText()); // var previous = elem; // elem = element.Match(sep.RemainingText()); // if (!elem.Success()) return new SuccessMatch(previous.RemainingText()); // sep = separator.Match(elem.RemainingText()); //// return new SuccessMatch(sep.RemainingText()); //} //return new SuccessMatch(textCopy); }
public Numb() { var allDigits = new OneOrMore(new Ranges('0', '9')); var dot = new Charact('.'); var minus = new Charact('-'); var zero = new Charact('0'); var digits = new OneOrMore(new Ranges('1', '9')); var naturalNumbers = new Choices(zero, allDigits); var integerNumbers = new Sequance(new Optionals(minus), naturalNumbers); var fractionalPart = new Sequance( dot, allDigits); var exponentialOption = new Any("eE"); var optionalSign = new Any("+-"); var exponentialPart = new Sequance( exponentialOption, optionalSign, allDigits); pattern = new Sequance( integerNumbers, new Optionals(fractionalPart), new Optionals(exponentialPart)); }