Example #1
0
        /// <summary>
        /// Add a Lex item, and Lex with this order.
        /// </summary>
        /// <param name="name">Name of item</param>
        /// <param name="regExpr">Regular Expression of Lex, and automately add "^" at head</param>
        /// <param name="regexOptions">Regular Expression Options</param>
        /// <param name="formatCapTextDelegate">The delegate of formatting the result of regExpr</param>
        /// <param name="group">LexGroup for advanced usage</param>
        /// <exception cref="GroupNumException">if Lex group number is out of limite or under zero</exception>
        public void AddLexItem(string name, string regExpr, FormatCapTextDelegate formatCapTextDelegate = null, RegexOptions regexOptions = RegexOptions.None, int group = 0)
        {
            if (name.Length == 0)
            {
                return;
            }
            if (regExpr.Length == 0)
            {
                return;
            }
            LexItem LexItem = new LexItem(name, formatCapTextDelegate);

            if (!regExpr.StartsWith('^'))
            {
                regExpr = '^' + regExpr;                          // reg expr must start from head of string
            }
            LexItem.SetRegex(regExpr, regexOptions);
            if (group >= LexGroupCount || group < 0)
            {
                throw new GroupNumException(group, "AddLexItem Error: illeagal Lex group number: " + group);
            }
            LexItems[group].Add(LexItem);
        }