Ejemplo n.º 1
0
        /// <summary>
        /// Build a new token and add it to the list of tokens known by TokenDictionary.
        /// Tokens must be added from the longest text value to the shortest otherwise
        /// an exception will be raised.
        /// </summary>
        /// <param name="value">
        /// The token's text value. It must not be null nor empty. It must not be already
        /// defined neither. If there are tokens already defined, value's length must not
        /// be longer than the previous added token.
        /// </param>
        /// <param name="tag">The token's tag value.</param>
        public void Add(string value, LexerTag tag)
        {
            InternalLexToken newToken;

            UiExceptionHelper.CheckNotNull(value, "value");
            UiExceptionHelper.CheckFalse(value == "",
                                         "Token value must not be empty.", "value");
            UiExceptionHelper.CheckFalse(
                Contains(value),
                String.Format("Token '{0}' is already defined.", value),
                "value");
            if (Count > 0)
            {
                UiExceptionHelper.CheckTrue(
                    _list[Count - 1].Text.Length >= value.Length,
                    "Tokens must be inserted from the longest to the shortest value.",
                    "value");
            }

            newToken = new InternalLexToken(value, tag);

            // loop through each item to populate
            // newToken.StartingWith list.

            foreach (InternalLexToken item in _list)
            {
                if (item.Text.StartsWith(value))
                {
                    newToken.StartingWith.Add(item);
                }
            }

            _list.Add(newToken);

            return;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Build a new token and add it to the list of tokens known by TokenDictionary.
        /// Tokens must be added from the longest text value to the shortest otherwise
        /// an exception will be raised.
        /// </summary>
        /// <param name="value">
        /// The token's text value. It must not be null nor empty. It must not be already
        /// defined neither. If there are tokens already defined, value's length must not
        /// be longer than the previous added token.
        /// </param>
        /// <param name="tag">The token's tag value.</param>
        public void Add(string value, LexerTag tag)
        {
            InternalLexToken newToken;

            UiExceptionHelper.CheckNotNull(value, "value");
            UiExceptionHelper.CheckFalse(value == "",
                "Token value must not be empty.", "value");
            UiExceptionHelper.CheckFalse(
                Contains(value),
                String.Format("Token '{0}' is already defined.", value),
                "value");
            if (Count > 0)
                UiExceptionHelper.CheckTrue(
                    _list[Count - 1].Text.Length >= value.Length,
                    "Tokens must be inserted from the longest to the shortest value.",
                    "value");

            newToken = new InternalLexToken(value, tag);

            // loop through each item to populate
            // newToken.StartingWith list.

            foreach (InternalLexToken item in _list)
                if (item.Text.StartsWith(value))
                    newToken.StartingWith.Add(item);

            _list.Add(newToken);

            return;
        }