Esempio n. 1
0
            public State(int initialState, TransitionData[] transitions)
            {
                int i;
                int j;

                UiExceptionHelper.CheckNotNull(transitions, "transitions");
                UiExceptionHelper.CheckTrue(
                    transitions.Length == 8,
                    "expecting transitions.Length to be 8",
                    "transitions");

                for (i = 0; i < transitions.Length; ++i)
                {
                    for (j = 0; j < transitions.Length; ++j)
                    {
                        if (j == i)
                        {
                            continue;
                        }

                        if (transitions[j].Transition == transitions[i].Transition)
                        {
                            UiExceptionHelper.CheckTrue(false,
                                                        String.Format("transition '{0}' already present", transitions[j].Transition),
                                                        "transitions");
                        }
                    }
                }


                InitialState = initialState;
                Transitions  = transitions;

                return;
            }
        public ErrorItem ToErrorItem()
        {
            UiExceptionHelper.CheckTrue(
                _function != null,
                "Cannot create instance of ErrorItem without a valid value in Function",
                "Function");

            return(new ErrorItem(_path, _function, _line));
        }
Esempio n. 3
0
        /// <summary>
        /// Registers an ICodeFormatter for the given language. The system
        /// is not case sensitive.
        /// </summary>
        /// <param name="formatter">
        /// A non null formatter.
        /// </param>
        /// <param name="language">
        /// A non null file language.
        /// The value must not be empty nor contain '.' and
        /// must not have been already registered.
        /// </param>
        public void Register(ICodeFormatter formatter, string extension)
        {
            UiExceptionHelper.CheckNotNull(formatter, "formatter");
            UiExceptionHelper.CheckNotNull(extension, "language");

            extension = extension.ToLower();

            UiExceptionHelper.CheckTrue(extension.Length > 0,
                                        "language cannot be empty", "language");
            UiExceptionHelper.CheckTrue(extension.LastIndexOf('.') == -1,
                                        "language cannot contain '.'", "language");
            UiExceptionHelper.CheckFalse(_toFormatter.ContainsKey(extension),
                                         "language '" + extension + "' has already an handler. Remove handler first.",
                                         "language");

            _toFormatter.Add(extension, formatter);

            return;
        }
        /// <summary>
        /// Converts the given value into the matching ClassificationTag.
        /// </summary>
        private ClassificationTag _getTagFromByteValue(byte value)
        {
            switch (value)
            {
            case 0: return(ClassificationTag.Code);

            case 1: return(ClassificationTag.Keyword);

            case 2: return(ClassificationTag.Comment);

            case 3: return(ClassificationTag.String);

            default:
                UiExceptionHelper.CheckTrue(false, "should not reach this code", "value");
                break;
            }

            return(ClassificationTag.Code);
        }
Esempio n. 5
0
        /// <summary>
        /// An utility method that check data consistency. The operation
        /// raises an exception if an error is found.
        /// </summary>
        public static void CheckData(FormattedCode data)
        {
            List <int> lines;
            int        line;
            int        bound;
            int        i;

            UiExceptionHelper.CheckNotNull(data, "data");

            UiExceptionHelper.CheckTrue(
                data._codeInfo.IndexArray.Count == data._codeInfo.TagArray.Count,
                "IndexArray.Count and TagArray.Count must match.",
                "data");

            bound = data._codeInfo.IndexArray.Count;
            lines = data._codeInfo.LineArray;
            for (i = 0; i < lines.Count; ++i)
            {
                line = lines[i];

                UiExceptionHelper.CheckTrue(
                    line >= 0 && line < bound,
                    "Bad LineArray value at index " + i + ", value was: " + line + ", expected to be in: [0-" + bound + "[.",
                    "data");

                if (i == 0)
                {
                    continue;
                }

                UiExceptionHelper.CheckTrue(
                    lines[i] > lines[i - 1],
                    "Bad LineArray[" + i + "], value was: " + line + ", expected to be > than LineArray[" + (i - 1) + "]=" + lines[i - 1] + ".",
                    "data");
            }

            return;
        }
Esempio n. 6
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;
        }