/// <summary> Scans a non-nestable block comment.</summary> /// <param name="open">the opening string. /// </param> /// <param name="close">the closing string. /// </param> /// <param name="commented">the commented pattern. /// </param> /// <returns> the Scanner for the block comment. /// </returns> public static Scanner IsBlockComment(string open, string close, CharPattern commented) { CharPattern opening = Patterns.IsString(open) .Seq(Patterns.IsString(close).Not().Seq(commented).Many()); return(IsPattern("block comment before the end", opening, open).Seq(IsString(close))); }
/// <summary> scanner for non-nested block comment.</summary> /// <param name="start">the start string of a block comment. /// </param> /// <param name="end">the end string of a block comment. /// </param> /// <returns> the scanner. /// </returns> public static Scanner IsBlockComment(string start, string end) { CharPattern opening = Patterns.IsString(start).Seq(Patterns.NotString(end).Many()); return(IsPattern("block comment before the end", opening, start).Seq(IsString(end)) .Rename("block comment")); }
public override int Match(string underlying_text, int starting_index, int ending_index) { if (ending_index - starting_index < str.Length) { return(MISMATCH); } return(Patterns.matchStringCI(str, underlying_text, starting_index, ending_index)); }
/// <summary> returns the lexer that's gonna parse a decimal number (valid patterns are: 1, 2.3, 000, 0., .23), /// and convert the string to a TokenDecimal. /// </summary> /// <returns> the lexer. /// </returns> public static Lexer LexDecimal() { string name = "decimal literal"; return(Lex(Scanners.Delimited( Scanners.IsPattern(name, Patterns.IsDecimal(), "decimal number")), Tokenizers.ForDecimal).Rename(name)); }
public override int Match(string underlying_text, int starting_index, int ending_index) { int minlen = Patterns.match_repeat(min, pp, underlying_text, starting_index, ending_index, 0); if (MISMATCH == minlen) { return(MISMATCH); } return(Patterns.match_some(max - min, pp, underlying_text, starting_index + minlen, ending_index, minlen)); }
internal static Pattern getRegularExpressionPattern() { Pattern quote = IsChar('/'); Pattern escape = IsChar('\\').Seq(Patterns.HasAtLeast(1)); char[] not_allowed = new char[] { '/', '\n', '\r', '\\' }; Pattern content = Patterns.Or(escape, Patterns.NotAmong(not_allowed)); return(quote.Seq(content.Many()).Seq(quote)); }
public override int Match(string underlying_text, int starting_index, int ending_index) { //UPGRADE_NOTE: Final was removed from the declaration of 'minlen '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" int minlen = Patterns.match_repeat(min, cp, underlying_text, starting_index, ending_index, 0); if (minlen == MISMATCH) { return(MISMATCH); } return(Patterns.match_some(max - min, cp, underlying_text, starting_index + minlen, ending_index, minlen)); }
/// <summary> a scanner with a CharPattern for sql server string literal. /// a sql server string literal is a string quoted by single quote, /// a single quote character is escaped by 2 single quotes. /// </summary> /// <returns> the scanner. /// </returns> public static Scanner IsSqlString() { /* * final CharPattern open = Patterns.IsChar('\'').Seq( * Patterns.or(Patterns.NotChar('\''), Patterns.IsString("''")) * .Many() * ); * return isPattern(open, "'").Seq(name, isChar('\'')); */ Scanner q = IsChar('\''); Scanner qs = IsPattern("sql string quoted", Patterns.Regex("(('')|[^'])*"), "quoted string"); return(qs.Between(q, q).Rename("sql string")); }
public override int Match(string underlying_text, int starting_index, int ending_index) { if (starting_index >= ending_index) { return(MISMATCH); } if (Patterns.matchStringCI(str, underlying_text, starting_index, ending_index) == Pattern.MISMATCH) { return(1); } else { return(MISMATCH); } }
/// <summary> Scans greedily for 0 or more characters /// that satisfies the given CharPredicate. /// </summary> /// <param name="cp">the predicate object. /// </param> /// <returns> the Scanner object. /// </returns> public static Scanner Many(CharPredicate cp) { return(IsPattern("many chars", Patterns.Many(cp), "many")); }
//case insensitive /// <summary> matches the input against the specified string case insensitively.</summary> /// <param name="str">the string to match /// </param> /// <param name="expected_name">the name of the expected pattern. /// </param> /// <returns> the scanner. /// </returns> public static Scanner IsStringCI(string str, string expected_name) { return(IsPattern("isStringCI", Patterns.IsStringCI(str), expected_name)); }
/// <summary> Recognizes a the exponent part of a scientific number notation. /// It can be e12, E-1, jfun.yan.etc. /// </summary> /// <returns> the Pattern object. /// </returns> public static Pattern IsExponential() { return(Patterns.Sequence(Among(new char[] { 'e', 'E' }), IsChar('-').Optional(), IsInteger())); }
internal static Pattern getModifiersPattern() { return(Patterns.IsChar(CharPredicates.IsAlpha()).Many()); }
public override int Match(string underlying_text, int starting_index, int ending_index) { return(Patterns.match_some(max, pp, underlying_text, starting_index, ending_index, 0)); }
/// <summary> if the current input starts with the given string, succeed and consumes all the characters until the end of line '\n character. /// It does not consume the end of line character. /// </summary> /// <param name="start">the start string. /// </param> /// <returns> the scanner. /// </returns> public static Scanner IsLineComment(string start) { return(IsPattern("line comment", Patterns.IsLineComment(start), start)); }
/// <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)); }
public override int Match(string underlying_text, int starting_index, int ending_index) { return(Patterns.match_repeat(n, cp, underlying_text, starting_index, ending_index, 0)); }
/// <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")); }