Esempio n. 1
0
        private void intellua_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
        {
            //ShowCalltip();
            const string brackets = "()[]{}";
            const string newline  = "\r\n";

            if (newline.Contains(e.Ch))
            {
                if (e.Ch == '\n')
                {
                    InsertText(string.Concat(Enumerable.Repeat("\t", Lines.Current.Previous.Indentation / Indentation.TabWidth)));

                    if (Lines.Current.FoldParent != null && Lines.Current.FoldParent.StartPosition == Lines.Current.Previous.StartPosition)
                    {
                        InsertText("\t");
                    }
                }

                return;
            }

            if (!Parse)
            {
                return;
            }
            if (brackets.Contains(e.Ch))
            {
                return;
            }

            MemberChain chain = MemberChain.ParseBackward(m_source);

            if (chain.Elements.Count == 1)
            {
                string word = chain.Elements[0].Name;
                if (char.IsLetterOrDigit(e.Ch) && word.Length >= 3)
                {
                    List <IAutoCompleteItem> list = m_autoCompleteData.Variables.getList(word, CurrentPos);
                    m_autoCompleteData.Types.appendList(list, word);
                    m_autoCompleteData.Keywords.appendList(list, word);

                    list.Sort();
                    if (list.Count > 0)
                    {
                        ShowAutoComplete(word.Length, list);
                    }
                }
            }
            else
            {
                Type t = chain.getType(m_autoCompleteData);
                if (t != null)
                {
                    List <IAutoCompleteItem> list = t.getList(chain.IsNamespace);
                    if (list.Count > 0)
                    {
                        ShowAutoComplete(chain.getLastElement().Length, list);
                    }
                }
            }

            if (!AutoComplete.IsActive)
            {
                m_tooltip.Hide();
            }
        }
Esempio n. 2
0
        // Public Methods (2) 

        public static FunctionCall Parse(IntelluaSource source, AutoCompleteData data, int pos)
        {
            VariableManager variables    = data.Variables;
            const string    luaOperators = "+-*/^%<>=~";
            int             paramIndex   = 0;

            Byte[] str     = source.RawText;
            bool   running = true;

            while (pos > 0)
            {
                char c = Convert.ToChar(str[pos]);
                if (c == 0 || char.IsWhiteSpace(Convert.ToChar(str[pos])) || !Parser.isCode(source, pos))
                {
                    pos--;
                    continue;
                }
                if (c == ',')
                {
                    paramIndex++;
                    pos--;
                    break;
                }
                if (c == '(')
                {
                    running = false;
                    break;
                }
                break;
            }

            MemberChain chain = MemberChain.ParseBackward(source, pos);

            while (chain.Elements.Count != 0 && running)
            {
                pos = chain.StartPos;

                while (pos > 0 && pos < str.Length)
                {
                    if (char.IsWhiteSpace(Convert.ToChar(str[pos])) || !Parser.isCode(source, pos))
                    {
                        pos--;
                        continue;
                    }
                    if (str[pos] == ',')
                    {
                        paramIndex++;
                        pos--;
                        break;
                    }
                    if (luaOperators.Contains(Convert.ToChar(str[pos])))
                    {
                        pos--;
                        break;
                    }
                    if (str[pos] == '(')
                    {
                        running = false;
                        break;
                    }
                    return(null);
                }
                if (pos <= 0)
                {
                    return(null);
                }
                chain = MemberChain.ParseBackward(source, pos);
                if (chain.StartPos == -1)
                {
                    break;
                }
            }

            while (pos > 0 && pos < str.Length)
            {
                if (char.IsWhiteSpace(Convert.ToChar(str[pos])) || !Parser.isCode(source, pos))
                {
                    pos--;
                    continue;
                }

                if (str[pos] == '(')
                {
                    chain = MemberChain.ParseBackward(source, pos - 1);
                    chain.getType(data, true);

                    if (chain.LastFunction == null)
                    {
                        return(null);
                    }
                    FunctionCall fc = new FunctionCall();
                    fc.m_func     = chain.LastFunction;
                    fc.ParamIndex = paramIndex;

                    fc.update();
                    return(fc);
                }
                break;
            }

            return(null);
        }
Esempio n. 3
0
        public static MemberChain ParseBackward(IntelluaSource source, int pos = -1)
        {
            const string seperator = ".:";
            const string lbracket  = "([{";
            const string rbracket  = ")]}";
            const string operators = "=+-*/;";

            Byte[] str = source.RawText;
            if (pos < 0)
            {
                pos = source.getRawPos() - 1;
            }
            PaserState state = PaserState.searchWordEnd;

            MemberChain rst       = new MemberChain();
            int         wordStart = pos;
            int         wordEnd   = pos;

            int bracketLevel = 0;

            bool isFuncion = false;

            while (pos >= 0 && pos < str.Length)
            {
                if (str[pos] > 127)
                {
                    pos--;
                    continue;
                }
                char c         = Convert.ToChar(str[pos]);
                bool isComment = Parser.isComment(source, pos);
                bool isString  = Parser.isString(source, pos);

                switch (state)
                {
                case PaserState.searchWordStart:
                    if (isString)
                    {
                        return(rst);
                    }
                    if (!char.IsLetterOrDigit(c) || isComment || pos == 0)
                    {
                        wordStart = pos + 1;
                        if (pos == 0 && char.IsLetterOrDigit(c))
                        {
                            wordStart = 0;
                        }
                        Byte[] bword = SubArray(str, wordStart, wordEnd - wordStart + 1);
                        string word  = Encoding.UTF8.GetString(bword);   //str.Substring(wordStart, wordEnd - wordStart + 1);
                        //word.Trim();
                        {
                            //int p = source.getRawPos(wordStart);
                            rst.Elements.Insert(0, new Word(word, isFuncion, wordStart));
                            isFuncion    = false;
                            rst.StartPos = pos;
                        }
                        state = PaserState.searchSeperator;
                    }
                    else
                    {
                        pos--;
                    }

                    break;

                case PaserState.searchWordEnd:
                    if (isComment)
                    {
                        pos--;
                        break;
                    }
                    if (isString)
                    {
                        return(rst);
                    }
                    if (operators.Contains(c))
                    {
                        return(rst);
                    }

                    if (seperator.Contains(c))
                    {
                        if (rst.Elements.Count == 0)
                        {
                            //int p = source.getRawPos(pos);
                            rst.Elements.Add(new Word("", false, pos));
                        }
                    }

                    if (rbracket.Contains(c))
                    {
                        if (rst.Elements.Count == 0)
                        {
                            //int p = source.getRawPos(pos);
                            rst.Elements.Add(new Word("", false, pos));
                        }
                        state = PaserState.searchBracket;
                        break;
                    }
                    if (char.IsLetterOrDigit(c))
                    {
                        wordEnd = pos;
                        if (rst.EndPos < 0)
                        {
                            rst.EndPos = pos;
                        }
                        state = PaserState.searchWordStart;
                    }
                    else
                    {
                        pos--;
                    }
                    break;

                case PaserState.searchSeperator:
                    if (isString)
                    {
                        return(rst);
                    }

                    if (char.IsWhiteSpace(c) || isComment)
                    {
                        pos--;
                    }
                    else if (seperator.Contains(c))
                    {
                        state = PaserState.searchWordEnd;
                        pos--;
                    }
                    else
                    {
                        //end
                        return(rst);
                    }
                    break;

                case PaserState.searchBracket:
                    if (!isComment && !isString)
                    {
                        if (rbracket.Contains(c))
                        {
                            bracketLevel++;
                        }
                        else if (lbracket.Contains(c))
                        {
                            bracketLevel--;
                            if (bracketLevel == 0)
                            {
                                if (c == '(')
                                {
                                    isFuncion = true;
                                }
                                state = PaserState.searchWordEnd;
                            }
                        }
                    }
                    pos--;
                    break;
                }
            }

            return(rst);
        }
Esempio n. 4
0
        public static MemberChain ParseBackward(IntelluaSource source, int pos = -1)
        {
            const string seperator = ".:";
            const string lbracket = "([{";
            const string rbracket = ")]}";
            const string operators = "=+-*/;";
            Byte[] str = source.RawText;
            if (pos < 0)
            {
                pos = source.getRawPos() - 1;
            }
            PaserState state = PaserState.searchWordEnd;

            MemberChain rst = new MemberChain();
            int wordStart = pos;
            int wordEnd = pos;

            int bracketLevel = 0;

            bool isFuncion = false;

            while (pos >= 0 && pos < str.Length)
            {
                if (str[pos] > 127)
                {
                    pos--;
                    continue;
                }
                char c = Convert.ToChar(str[pos]);
                bool isComment = Parser.isComment(source, pos);
                bool isString = Parser.isString(source, pos);

                switch (state)
                {
                    case PaserState.searchWordStart:
                        if (isString) return rst;
                        if (!Parser.isIndentifierChar(c) || isComment || pos == 0)
                        {
                            wordStart = pos + 1;
                            if (pos == 0 && Parser.isIndentifierChar(c)) wordStart = 0;
                            Byte[] bword = SubArray(str, wordStart, wordEnd - wordStart + 1);
                            string word = Encoding.UTF8.GetString(bword);//str.Substring(wordStart, wordEnd - wordStart + 1);
                            //word.Trim();
                            {
                                //int p = source.getRawPos(wordStart);
                                rst.Elements.Insert(0, new Word(word, isFuncion, wordStart));
                                isFuncion = false;
                                rst.StartPos = pos;
                            }
                            state = PaserState.searchSeperator;
                        }
                        else
                        {
                            pos--;
                        }

                        break;

                    case PaserState.searchWordEnd:
                        if (isComment)
                        {
                            pos--;
                            break;
                        }
                        if (isString) return rst;
                        if (operators.Contains(c)) return rst;

                        if (seperator.Contains(c))
                        {
                            if (rst.Elements.Count == 0)
                            {
                                //int p = source.getRawPos(pos);
                                rst.Elements.Add(new Word("", false, pos));
                            }
                        }

                        if (rbracket.Contains(c))
                        {
                            if (rst.Elements.Count == 0)
                            {
                                //int p = source.getRawPos(pos);
                                rst.Elements.Add(new Word("", false, pos));
                            }
                            state = PaserState.searchBracket;
                            break;
                        }
                        if (Parser.isIndentifierChar(c))
                        {
                            wordEnd = pos;
                            if (rst.EndPos < 0) rst.EndPos = pos;
                            state = PaserState.searchWordStart;
                        }
                        else
                        {
                            pos--;
                        }
                        break;

                    case PaserState.searchSeperator:
                        if (isString) return rst;

                        if (char.IsWhiteSpace(c) || isComment)
                        {
                            pos--;
                        }
                        else if (seperator.Contains(c))
                        {
                            state = PaserState.searchWordEnd;
                            pos--;
                        }
                        else
                        {
                            //end
                            return rst;
                        }
                        break;

                    case PaserState.searchBracket:
                        if (!isComment && !isString)
                        {
                            if (rbracket.Contains(c)) bracketLevel++;
                            else if (lbracket.Contains(c))
                            {
                                bracketLevel--;
                                if (bracketLevel == 0)
                                {
                                    if (c == '(') isFuncion = true;
                                    state = PaserState.searchWordEnd;
                                }
                            }
                        }
                        pos--;
                        break;
                }
            }

            return rst;
        }
Esempio n. 5
0
        public static MemberChain ParseFoward(IntelluaSource source, int pos)
        {
            const string seperator = ".:";
            const string lbracket  = "([{";
            const string rbracket  = ")]}";
            const string operators = "=+-*/;";

            Byte[] str = source.RawText;

            PaserState state = PaserState.searchWordStart;

            MemberChain rst       = new MemberChain();
            int         wordStart = pos;
            int         wordEnd   = pos;

            int bracketLevel = 0;

            while (pos < str.Length)
            {
                if (str[pos] > 127)
                {
                    pos++;
                    continue;
                }
                char c = Convert.ToChar(str[pos]);

                bool isComment = Parser.isComment(source, pos);
                bool isString  = Parser.isString(source, pos);

                switch (state)
                {
                case PaserState.searchWordEnd:
                    if (isString)
                    {
                        return(rst);
                    }
                    if (!Parser.isIndentifierChar(c) || isComment || pos == str.Length - 1)
                    {
                        wordEnd = pos;
                        string word;
                        if (pos == str.Length - 1)
                        {
                            Byte[] bword = SubArray(str, wordStart, wordEnd - wordStart + 1);
                            word = Encoding.UTF8.GetString(bword);
                        }
                        else
                        {
                            Byte[] bword = SubArray(str, wordStart, wordEnd - wordStart);
                            word = Encoding.UTF8.GetString(bword);
                            //word = str.Substring(wordStart, wordEnd - wordStart);
                        }
                        word.Trim();
                        {
                            //int p = wordStart;//source.getRawPos(wordStart);
                            rst.Elements.Add(new Word(word, false, wordStart));

                            rst.EndPos = pos;
                        }
                        state = PaserState.searchSeperator;
                    }
                    else
                    {
                        pos++;
                    }

                    break;

                case PaserState.searchWordStart:
                    if (isString)
                    {
                        return(rst);
                    }
                    if (operators.Contains(c))
                    {
                        return(rst);
                    }
                    if (isComment)
                    {
                        pos++;
                        break;
                    }

                    if (Parser.isIndentifierChar(c))
                    {
                        wordStart = pos;
                        if (rst.StartPos < 0)
                        {
                            rst.StartPos = pos;
                        }
                        state = PaserState.searchWordEnd;
                    }
                    else
                    {
                        pos++;
                    }
                    break;

                case PaserState.searchSeperator:
                    if (isString)
                    {
                        return(rst);
                    }
                    if (lbracket.Contains(c))
                    {
                        if (c == '(')
                        {
                            if (rst.Elements.Count > 0)
                            {
                                rst.Elements[rst.Elements.Count - 1].IsFunction = true;
                            }
                        }
                        state = PaserState.searchBracket;
                        break;
                    }
                    if (seperator.Contains(c))
                    {
                        state = PaserState.searchWordStart;
                        pos++;
                    }
                    else if (char.IsWhiteSpace(c) || isComment)
                    {
                        pos++;
                    }
                    else
                    {
                        //end
                        return(rst);
                    }
                    break;

                case PaserState.searchBracket:
                    if (!isComment && !isString)
                    {
                        if (lbracket.Contains(c))
                        {
                            bracketLevel++;
                        }
                        else if (rbracket.Contains(c))
                        {
                            bracketLevel--;
                            if (bracketLevel == 0)
                            {
                                state = PaserState.searchSeperator;
                            }
                        }
                    }
                    pos++;
                    break;
                }
            }

            return(rst);
        }