Esempio n. 1
0
        /// <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)));
        }
Esempio n. 2
0
        /// <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"));
        }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
        /// <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));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        /// <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"));
        }
Esempio n. 9
0
 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);
     }
 }
Esempio n. 10
0
 /// <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"));
 }
Esempio n. 11
0
 //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));
 }
Esempio n. 12
0
 /// <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()));
 }
Esempio n. 13
0
 internal static Pattern getModifiersPattern()
 {
     return(Patterns.IsChar(CharPredicates.IsAlpha()).Many());
 }
Esempio n. 14
0
 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));
 }
Esempio n. 15
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));
 }
Esempio n. 16
0
 /// <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));
 }
Esempio n. 17
0
 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));
 }
Esempio n. 18
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"));
 }