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 })); }
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)); }
/// <summary> Creates a Terms object for lexing the operators with names specified in ops. /// Operators are lexed as TokenReserved. /// </summary> /// <param name="ops">the operator names. /// </param> /// <returns> the Terms instance. /// </returns> public static Terms GetOperatorsInstance(params string[] ops) { return(new Terms(Lexers.GetOperators(ops))); }
/// <summary> Creates a Terms object for lexing and parsing the operators with names specified in ops, /// and for lexing and parsing the keywords case sensitively. /// Keywords and operators are lexed as TokenReserved. /// Words that are not among the keywords are lexed as TokenWord. /// </summary> /// <param name="wscanner">the scanner that identifies a word in the language. /// </param> /// <param name="ops">the operator names. /// </param> /// <param name="keywords">the keyword names. /// </param> /// <param name="toWord">the FromString object used to create a token for non-key words recognized by wscanner. /// </param> /// <returns> the Terms instance. /// </returns> public static Terms GetCaseSensitiveInstance(Scanner wscanner, string[] ops, string[] keywords, FromString toWord) { return(new Terms(Lexers.GetCaseSensitive(wscanner, ops, keywords, toWord))); }
/// <summary> Creates a Terms object for lexing and parsing the operators with names specified in ops, /// and for lexing and parsing the keywords case insensitively. /// Keywords and operators are lexed as TokenReserved. /// Words that are not among the keywords are lexed as TokenWord. /// </summary> /// <param name="wscanner">the scanner that identifies a word in the language. /// </param> /// <param name="ops">the operator names. /// </param> /// <param name="keywords">the keyword names. /// </param> /// <returns> the Terms instance. /// </returns> public static Terms GetCaseInsensitiveInstance(Scanner wscanner, string[] ops, string[] keywords) { return(new Terms(Lexers.GetCaseInsensitive(wscanner, ops, keywords))); }
/// <summary> Creates a Terms object for lexing and parsing the operators with names specified in ops, /// and for lexing and parsing the keywords case sensitively. /// Keywords and operators are lexed as TokenReserved. /// Words that are not among the keywords are lexed as TokenWord. /// A word is defined as an alpha numeric string that starts with [_a-zA-Z], /// with 0 or more [0-9_a-zA-Z] following. /// </summary> /// <param name="ops">the operator names. /// </param> /// <param name="keywords">the keyword names. /// </param> /// <returns> the Terms instance. /// </returns> public static Terms GetCaseSensitiveInstance(string[] ops, string[] keywords) { return(new Terms(Lexers.GetCaseSensitive(ops, keywords))); }