Пример #1
0
        /// <summary> returns the lexer that's gonna parse any word.
        /// and convert the string to a TokenWord.
        /// A word starts with an alphametic character, followed by 0 or more alphanumeric characters.
        /// </summary>
        /// <returns> the lexer.
        /// </returns>
        public static Lexer LexWord()
        {
            string name = "word";

            return(Lex(Scanners.Delimited(Scanners.IsPattern(name, Patterns.IsWord(), name)),
                       Tokenizers.ForWord).Rename(name));
        }
Пример #2
0
        /// <summary> returns the lexer that's gonna parse a octal integer number (valid patterns are: 0, 07, 017, 0371 jfun.yan.etc.),
        /// and convert the string to a Long token.
        /// an octal number has to start with 0.
        /// </summary>
        /// <returns> the lexer.
        /// </returns>
        public static Lexer LexOctLong()
        {
            string name = "oct integer literal";

            return(Lex(Scanners.Delimited(Scanners.IsPattern(name, Patterns.IsOctInteger(), "octInteger")),
                       Tokenizers.ForOctLong).Rename(name));
        }
Пример #3
0
        /// <summary> returns the lexer that's gonna parse a hex integer number (valid patterns are: 0x1, 0Xff, 0xFe1 jfun.yan.etc.),
        /// and convert the string to a Long token.
        /// an hex number has to start with either 0x or 0X.
        /// </summary>
        /// <returns> the lexer.
        /// </returns>
        public static Lexer LexHexLong()
        {
            string name = "hex integer literal";

            return(Lex(Scanners.Delimited(Scanners.IsPattern(name, Patterns.IsHexInteger(), "hexInteger")),
                       Tokenizers.ForHexLong).Rename(name));
        }
Пример #4
0
        /// <summary> returns the lexer that's gonna parse a integer number (valid patterns are: 0, 00, 1, 10),
        /// and convert the string to a Long token.
        /// The difference between integer() and decInteger() is that decInteger does not allow a number starting with 0.
        /// </summary>
        /// <returns> the lexer.
        /// </returns>
        public static Lexer LexInteger()
        {
            string name = "integer literal";

            return(Lex(Scanners.Delimited(Scanners.IsPattern("integer literal", Patterns.IsInteger(), "integer")),
                       Tokenizers.ForInteger).Rename(name));
        }
Пример #5
0
        /// <summary> returns the lexer that's gonna parse a decimal integer number (valid patterns are: 1, 10, 123),
        /// and convert the string to a Long token.
        /// The difference between integer() and decInteger() is that decInteger does not allow a number starting with 0.
        /// </summary>
        /// <returns> the lexer.
        /// </returns>
        public static Lexer LexDecimalLong()
        {
            string name = "decimal integer literal";

            return(Lex(Scanners.Delimited(Scanners.IsPattern(name, Patterns.IsDecInteger(), "decInteger")),
                       Tokenizers.ForLong));
        }
Пример #6
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));
        }
Пример #7
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     if (ctxt.isEof())
     {
         return(Scanners.setErrorExpecting(out err, expected_name, ctxt));
     }
     ctxt.next();
     return(true);
 }
Пример #8
0
        /// <summary> a scanner with a CharPattern for double quoted string literal.
        /// backslash '\' is used as escape character.
        /// </summary>
        /// <returns> the scanner.
        /// </returns>
        public static Scanner IsQuotedString()
        {
            /*
             * final CharPattern q = Patterns.IsChar('"');
             * final CharPattern open = q.Seq(quoted().Many());
             * return isPattern(open, "\"").Seq(name, isPattern(q, "\""));
             */
            Scanner q  = Scanners.IsChar('"');
            Scanner qc = IsPattern("string quoted", quoted_str, "quoted string");

            return(qc.Between(q, q).Rename("quoted string"));
        }
Пример #9
0
            internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
            {
                int    at   = ctxt.getAt();
                string src  = ctxt.getSource();
                int    mlen = pp.Match(src, at, src.Length);

                if (mlen < 0)
                {
                    return(Scanners.setErrorExpecting(out err, expected_name, ctxt));
                }
                ctxt.next(mlen);
                return(true);
            }
Пример #10
0
        internal static WordsData instance(string[] names)
        {
            Hashtable operators = new Hashtable();

            string[] ops = sort(names);
            Lexer[]  lxs = new Lexer[ops.Length];
            for (int i = 0; i < ops.Length; i++)
            {
                string  s       = ops[i];
                Scanner scanner = s.Length == 1 ? Scanners.IsChar(s[0]) : Scanners.IsString(s);
                object  tok     = Tokens.CreateReservedWordToken(s);
                operators[s] = tok;
                Lexer lx = Lexers.Lex(scanner, Tokenizers.ForValue(tok));
                lxs[i] = lx;
            }
            return(new WordsData(Functors.AsMap <string, object>(operators), lxs));
        }
Пример #11
0
        /// <summary> scanner for a c/c++/java style character literal. such as 'a' or '\\'.</summary>
        /// <returns> the scanner.
        /// </returns>
        public static Scanner IsQuotedChar()
        {
            //final Scanner q = isChar('\'');

            /*
             * final CharPattern q = Patterns.IsChar('\'');
             * final CharPattern qc = Patterns.or(
             * Patterns.IsString("\\'"),
             * Patterns.NotChar('\'')
             * );
             * return isPattern(q.Seq(qc), "'").Seq(name, isPattern(q, "'"));
             */
            Scanner q  = Scanners.IsChar('\'');
            Scanner qc = IsPattern("char quoted", quoted_char, "quoted char");

            return(qc.Between(q, q).Rename("quoted char"));
        }
Пример #12
0
 /// <summary> returns the lexer that's gonna parse double quoted string literal (escaped by '\'),
 /// and convert the string to a String token.
 /// </summary>
 /// <returns> the lexer.
 /// </returns>
 public static Lexer LexSimpleStringLiteral()
 {
     return(Lex(Scanners.IsQuotedString(), Tokenizers.ForSimpleStringLiteral)
            .Rename("double quoted string literal"));
 }
Пример #13
0
 /// <summary> returns the lexer that's gonna parse single quoted character literal (escaped by '\'),
 /// and then converts the character to a Character.
 /// </summary>
 /// <returns> the lexer.
 /// </returns>
 public static Lexer LexCharLiteral()
 {
     return(Lex(Scanners.IsQuotedChar(), Tokenizers.ForChar).Rename("char literal"));
 }
Пример #14
0
 /// <summary> Create a lexer that parsers a string literal quoted by open and close,
 /// and then converts it to a String token instance.
 /// </summary>
 /// <param name="open">the opening character.
 /// </param>
 /// <param name="close">the closing character.
 /// </param>
 /// <returns> the lexer.
 /// </returns>
 public static Lexer LexQuotedString(char open, char close)
 {
     return(Lex(Scanners.IsQuotedBy(open, close),
                Tokenizers.ForQuotedString(open, close)).Rename("quoted string literal"));
 }
Пример #15
0
 /// <summary> returns the lexer that's gonna parse single quoted string literal (single quote is escaped with another single quote),
 /// and convert the string to a String token.
 /// </summary>
 /// <returns> the lexer.
 /// </returns>
 public static Lexer LexSqlStringLiteral()
 {
     return(Lex(Scanners.IsSqlString(), Tokenizers.ForSqlStringLiteral)
            .Rename("sql style string literal"));
 }