/// <summary> pattern for a decimal integer. /// It starts with a non-zero digit and followed by 0 or more digits. /// </summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsDecInteger() { return(InRange('1', '9').Seq(Many(CharPredicates.IsDigit()))); }
/// <summary> pattern for a hex integer. /// It starts with a 0x or 0X, followed by 1 or more hex digits. /// </summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsHexInteger() { return(Or(IsString("0x"), IsString("0X")).Seq(Many(1, CharPredicates.IsHexDigit()))); }
/// <summary> pattern for an integer. ([0-9]+) </summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsInteger() { return(Many(1, CharPredicates.IsDigit())); }
/// <summary> pattern for a octal integer that starts with a 0 and followed by 0 or more [0-7] characters.</summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsOctInteger() { return(IsChar('0').Seq(Many(CharPredicates.InRange('0', '7')))); }
/// <summary> a decimal number that has at least one number before the decimal point. /// the decimal point and the numbers to the right are optional. /// 0, 11., 2.3 are all good candidates. While .1, . are not. /// </summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsDecimalL() { CharPredicate cp = CharPredicates.IsDigit(); return(Many(1, cp).Seq(IsChar('.').Seq(Many(cp)).Optional())); }
/// <summary> Recognizes a decimal point and 1 or more digits after it.</summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsDecimalR() { return(IsChar('.').Seq(Many(1, CharPredicates.IsDigit()))); }
/// <summary> Matches a line comment that starts with a string /// and end with EOF or Line Feed character. /// </summary> /// <param name="open">the line comment starting string. /// </param> /// <returns> the Pattern object. /// </returns> public static Pattern IsLineComment(string open) { return(IsString(open).Seq(Many(CharPredicates.NotChar('\n')))); }
internal static Pattern getModifiersPattern() { return(Patterns.IsChar(CharPredicates.IsAlpha()).Many()); }
/// <summary> If a string is not followed by a alphanumeric character, it is well-delimited. /// delimited() make sure the CharPattern represented by scanner s is delimited. /// </summary> /// <param name="s">the scanner for the to-be-delimited pattern. /// </param> /// <param name="expected_name">the error message if it is not delimited. /// </param> /// <returns> the new scanner. /// </returns> public static Scanner Delimited(Scanner s, string expected_name) { return(s.FollowedBy(IsChar(CharPredicates.IsAlphaNumeric(), expected_name).Not()) .Rename("delimited")); }
/// <summary> Succeed with match length 1 /// if the current character in the input is not among the given characters. /// </summary> /// <param name="cs">the characters to compare with. /// </param> /// <returns> the Pattern object. /// </returns> public static Pattern NotAmong(params char[] cs) { return(IsChar(CharPredicates.NotAmong(cs))); }
/// <summary> scans a quoted string that is opened by c1 and closed by c2. </summary> /// <param name="c1">the opening character. /// </param> /// <param name="c2">the closing character. /// </param> /// <returns> the scanner. /// </returns> public static Scanner IsQuotedBy(char c1, char c2) { return(IsPattern("open quote and quoted", Patterns.IsChar(c1).Seq(Patterns.Many(CharPredicates.NotChar(c2))), "" + c1) .Seq(IsChar(c2)).Rename("quoted")); }
static Scanner _notAmong(char[] chars, string expected_name) { return(IsChar(CharPredicates.NotAmong(chars), expected_name).Rename("not among")); }
/// <summary> succeed and consume the current character if it is equal to ch.</summary> /// <param name="ch">the expected character. /// </param> /// <param name="expected_name">the error message. /// </param> /// <returns> the scanner. /// </returns> public static Scanner NotChar(char ch, string expected_name) { return(IsChar(CharPredicates.NotChar(ch), expected_name).Rename("not char")); }
/// <summary> succeed and consume the current character if it is equal to ch.</summary> /// <param name="ch">the expected character. /// </param> /// <param name="expected_name">the error message. /// </param> /// <returns> the scanner. /// </returns> public static Scanner IsChar(char ch, string expected_name) { return(IsChar(CharPredicates.IsChar(ch), expected_name)); }
/// <summary> Scans greedily for 1 or more whitespace characters.</summary> /// <param name="expected_name">the expected message when fails. /// </param> /// <returns> the Scanner object. /// </returns> public static Scanner IsWhitespaces(string expected_name) { return(IsPattern("isWhitespaces", Patterns.Many(1, CharPredicates.IsWhitespace()), expected_name)); }