示例#1
0
        internal static WordsData getInstance <T>(string name, Scanner wscanner, string[] names, bool cs,
                                                  FromRange <string, T> for_unknown)
        {
            Keywords.StringCase          scase        = getStringCase(cs);
            string[]                     unique_names = Misc.Dedup(names, scase.Comparator);
            System.Collections.Hashtable map          = new System.Collections.Hashtable();
            foreach (string n in unique_names)
            {
                object tok = Tokens.CreateReservedWordToken(n);
                map[scase.ToKey(n)] = tok;
            }
            Map <string, object> fmap = scase.ToMap(map);

            Tokenizer tn = delegate(string src, int from, int len)
            {
                string text = src.Substring(from, len);
                object r    = fmap(text);
                if (r != null)
                {
                    return(r);
                }
                else
                {
                    return(for_unknown(from, len, src));
                }
            };
            Lexer lx = Lexers.Lex(wscanner, tn);

            return(new WordsData(fmap, new Lexer[] { lx }));
        }
示例#2
0
        private static Words instance <T>(Scanner wscanner, string[] ops, string[] keywords, bool cs,
                                          FromRange <string, T> toWord)
        {
            checkDup(ops, keywords, true);
            WordsData data = combine(Operators.instance(ops), Keywords.getInstance("word", wscanner, keywords, cs, toWord));

            return(toWords(data));
        }
示例#3
0
 /// <summary>
 /// Create a FromToken object that recognizes a token object of any arbitrary type.
 /// </summary>
 /// <typeparam name="T">The token type recognized.</typeparam>
 /// <typeparam name="R">The result type of the FromToken object.</typeparam>
 /// <param name="f">the FromRange object used to translate the recognized range to a certain result.</param>
 /// <returns>The FromToken object.</returns>
 public static FromToken <R> FromSimpleToken <T, R>(FromRange <T, R> f)
 {
     return(delegate(Tok tok, ref R result)
     {
         object obj = tok.Token;
         if (obj is T)
         {
             T t = (T)obj;
             result = f(tok.Index, tok.Length, t);
             return true;
         }
         else
         {
             return false;
         }
     });
 }
示例#4
0
        /// <summary> gets a Parser object to parse TokenQuoted.</summary>
        /// <param name="fc">the mapping to map the quoted string to an object returned by the parser.
        /// </param>
        /// <returns> the parser
        /// </returns>
        public static Parser <T> OnQuotedWord <T>(FromRange <string, string, string, T> fc)
        {
            FromToken <T> recognizer = delegate(Tok tok, ref T result)
            {
                object obj = tok.Token;
                if (obj is TokenQuoted)
                {
                    TokenQuoted quoted = obj as TokenQuoted;
                    result = fc(tok.Index, tok.Length, quoted.Open, quoted.Quoted, quoted.Close);
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            return(Parsers.FromToken(recognizer));
        }
示例#5
0
 /// <summary>
 /// Create a FromToken object that recognizes TypedToken of a certain type.
 /// </summary>
 /// <typeparam name="T">The token type.</typeparam>
 /// <typeparam name="R">The result type of the FromToken</typeparam>
 /// <param name="type">The token type.</param>
 /// <param name="f">The FromRange object used to translate the recognized range to a certain result.</param>
 /// <returns>The FromToken object</returns>
 public static FromToken <R> FromTypedToken <T, R>(T type, FromRange <string, R> f)
 {
     return(delegate(Tok tok, ref R result)
     {
         object t = tok.Token;
         if (t is TypedToken <T> )
         {
             TypedToken <T> tokobj = t as TypedToken <T>;
             if (!tokobj.Type.Equals(type))
             {
                 return false;
             }
             result = f(tok.Index, tok.Length, tokobj.Text);
             return true;
         }
         else
         {
             return false;
         }
     });
 }
示例#6
0
 internal static Words getCaseInsensitive <T>(Scanner wscanner, string[] ops, string[] keywords,
                                              FromRange <string, T> toWord)
 {
     return(instance(wscanner, ops, keywords, false, toWord));
 }
示例#7
0
 public static Parser <R> OnTypedToken <T, R>(T type, FromRange <string, R> f)
 {
     return(Parsers.FromToken(FromTypedToken(type, f)));
 }
示例#8
0
 public static Parser <R> OnToken <T, R>(FromRange <T, R> f)
 {
     return(Parsers.FromToken(FromSimpleToken(f)));
 }
示例#9
0
 /// <summary> gets a Parser object to parse TokenDecimal.</summary>
 /// <param name="fc">the mapping to map the decimal to an object returned by the parser.
 /// </param>
 /// <returns> the parser
 /// </returns>
 public static Parser <T> OnDecimal <T>(FromRange <string, T> fc)
 {
     return(OnTypedToken(TokenType.Decimal, fc).Rename("decimal"));
 }
示例#10
0
 /// <summary> gets a Parser object to parse Long token.</summary>
 /// <param name="fc">the mapping to map the number to an object returned by the parser.
 /// </param>
 /// <returns> the parser
 /// </returns>
 public static Parser <T> OnInteger <T>(FromRange <string, T> fc)
 {
     return(OnTypedToken(TokenType.Integer, fc).Rename("integer"));
 }
示例#11
0
 /// <summary> gets a Parser object to parse TokenWord.</summary>
 /// <param name="fc">the mapping to map the word to an object returned by the parser.
 /// </param>
 /// <returns> the parser
 /// </returns>
 public static Parser <T> OnWord <T>(FromRange <string, T> fc)
 {
     return(OnTypedToken(TokenType.Word, fc).Rename("word"));
 }
示例#12
0
 /// <summary> gets a Parser object to parse String token.</summary>
 /// <param name="fc">the mapping to map String to an object returned by the parser.
 /// </param>
 /// <returns> the parser
 /// </returns>
 public static Parser <T> OnString <T>(FromRange <string, T> fc)
 {
     return(OnToken(fc).Rename("string"));
 }
示例#13
0
 /// <summary> gets a Parser object to parse Character token.</summary>
 /// <param name="fc">the mapping to map char to an object returned by the parser.
 /// </param>
 /// <returns> the parser
 /// </returns>
 public static Parser <T> OnChar <T>(FromRange <char, T> fc)
 {
     return(OnToken(fc).Rename("char"));
 }