/// <summary> /// Represents BNF operator of "*". /// </summary> /// <param name="charset">Character set to be accepted.</param> /// <returns>Always true.</returns> protected bool Repeat(CharsetValidator charset) { while (charset(Text, P)) { P++; } return(true); }
/// <summary> /// Represents BNF operator "?". /// </summary> /// <param name="charset">Character set to be accepted.</param> /// <returns>Always true.</returns> protected bool Optional(CharsetValidator charset) // ? { if (!charset(Text, P)) { return(true); } P++; return(true); }
/// <summary> /// Represents <code>n</code> times repetition of characters. /// </summary> /// <param name="charset">Character set to be accepted.</param> /// <param name="n">Repetition count.</param> /// <returns>true if the rule matches; otherwise false.</returns> protected bool Repeat(CharsetValidator charset, int n) { for (int i = 0; i < n; i++) { if (!charset(Text, P + i)) { return(false); } } P += n; return(true); }
/// <summary> /// Represents BNF operator of "+". /// </summary> /// <param name="charset">Character set to be accepted.</param> /// <returns>true if the rule matches; otherwise false.</returns> protected bool OneAndRepeat(CharsetValidator charset) { if (!charset(Text, P)) { return(false); } while (charset(Text, ++P)) { ; } return(true); }
/// <summary> /// Represents at least <code>min</code> times, at most <code>max</code> times /// repetition of characters. /// </summary> /// <param name="charset">Character set to be accepted.</param> /// <param name="min">Minimum repetition count. Negative value is treated as 0.</param> /// <param name="max">Maximum repetition count. Negative value is treated as positive infinity.</param> /// <returns>true if the rule matches; otherwise false.</returns> protected bool Repeat(CharsetValidator charset, int min, int max) { for (int i = 0; i < min; i++) { if (!charset(Text, P + i)) { return(false); } } for (int i = 0; i < max; i++) { if (!charset(Text, P + min + i)) { P += min + i; return(true); } } P += min + max; return(true); }