예제 #1
0
        private static FileParser getFile(string filename, Intellua parent, Dictionary <string, int> required)
        {
            if (s_files.ContainsKey(filename))
            {
                FileParser afp = s_files[filename];
                if (!afp.modified())
                {
                    return(afp);
                }
                else
                {
                    System.Diagnostics.Debug.Print("modified");
                }
            }
            System.Diagnostics.Debug.Print("parse file " + filename);
            IntelluaSource source = new IntelluaSource(filename, parent);
            FileParser     fp     = new FileParser(source);

            foreach (var kv in required)
            {
                fp.m_required[kv.Key] = kv.Value;
            }

            fp.parse(true);
            s_files[filename] = fp;
            return(fp);
        }
예제 #2
0
        private void parseFile()
        {
            IntelluaSource source = new IntelluaSource(this, true);

            m_worker = new System.ComponentModel.BackgroundWorker();
            FileParser fp = new FileParser(source);

            /*fp.doWork(this,new System.ComponentModel.DoWorkEventArgs(0));
             * m_autoCompleteData = fp.result;*/
            m_worker.DoWork             += new System.ComponentModel.DoWorkEventHandler(fp.doWork);
            m_worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(parseFileDone);
            m_worker.RunWorkerAsync();
        }
예제 #3
0
        public FileParser(IntelluaSource source)
        {
            m_source = source;
            result   = new AutoCompleteData();
            result.setParent(source.m_intellua.AutoCompleteData.getParent());
            //result.Variables.scope = source.m_intellua.parseScope(0, source.m_intellua.Lines.Count - 1);

            m_lastCheckTime = System.DateTime.Now;
            if (source.FilePath.Length != 0)
            {
                m_lastWriteTime = System.IO.File.GetLastWriteTime(m_source.FilePath);
            }
            m_required[source.FilePath] = 0;
        }
예제 #4
0
        public FileParser(IntelluaSource source)
        {
            m_source = source;
            result = new AutoCompleteData();
            result.setParent(source.m_intellua.AutoCompleteData.getParent());
            //result.Variables.scope = source.m_intellua.parseScope(0, source.m_intellua.Lines.Count - 1);

            m_lastCheckTime = System.DateTime.Now;
            if (source.FilePath.Length != 0)
            {
                m_lastWriteTime = System.IO.File.GetLastWriteTime(m_source.FilePath);
            }
            m_required[source.FilePath] = 0;
        }
예제 #5
0
        public Intellua()
        {
            this.CallTipClick     += new System.EventHandler <ScintillaNET.CallTipClickEventArgs>(this.intellua_CallTipClick);
            this.CharAdded        += new System.EventHandler <ScintillaNET.CharAddedEventArgs>(this.intellua_CharAdded);
            this.TextDeleted      += new System.EventHandler <ScintillaNET.TextModifiedEventArgs>(this.intellua_TextDeleted);
            this.TextInserted     += new System.EventHandler <ScintillaNET.TextModifiedEventArgs>(this.intellua_TextInserted);
            this.SelectionChanged += new EventHandler(this.Intellua_SelectionChanged);

            m_tooltip          = new ToolTip(this);
            m_autoCompleteData = new AutoCompleteData();

            ScintillaNET.Configuration.Configuration config =
                new ScintillaNET.Configuration.Configuration(Assembly.GetExecutingAssembly().GetManifestResourceStream("Intellua.ScintillaNET.xml"),
                                                             "lua", true);
            ConfigurationManager.Language = "lua";
            ConfigurationManager.Configure(config);
            Folding.IsEnabled = true;

            /*Margins[0].Width = 20;
            *  Margins[1].Width = 20;
            *  Margins[2].Width = 20;*/
            AutoComplete.IsCaseSensitive = false;
            AutoComplete.AutoHide        = false;
            //Indentation.ShowGuides = true;

            List <Bitmap> list = new List <Bitmap>();
            Assembly      asm  = Assembly.GetExecutingAssembly();
            Stream        str;

            str = asm.GetManifestResourceStream("Intellua.member.png");
            list.Add(new Bitmap(str));
            str = asm.GetManifestResourceStream("Intellua.method.png");
            list.Add(new Bitmap(str));
            str = asm.GetManifestResourceStream("Intellua.function.png");
            list.Add(new Bitmap(str));
            str = asm.GetManifestResourceStream("Intellua.type.png");
            list.Add(new Bitmap(str));
            AutoComplete.RegisterImages(list);

            m_source = new IntelluaSource(this);
        }
예제 #6
0
        public Intellua()
        {
            

            this.CallTipClick += new System.EventHandler<ScintillaNET.CallTipClickEventArgs>(this.intellua_CallTipClick);
            this.CharAdded += new System.EventHandler<ScintillaNET.CharAddedEventArgs>(this.intellua_CharAdded);
            this.TextDeleted += new System.EventHandler<ScintillaNET.TextModifiedEventArgs>(this.intellua_TextDeleted);
            this.TextInserted += new System.EventHandler<ScintillaNET.TextModifiedEventArgs>(this.intellua_TextInserted);
            this.SelectionChanged += new EventHandler(this.Intellua_SelectionChanged);

            m_tooltip = new ToolTip(this);
            m_autoCompleteData = new AutoCompleteData();

            ScintillaNET.Configuration.Configuration config =
                new ScintillaNET.Configuration.Configuration(Assembly.GetExecutingAssembly().GetManifestResourceStream("Intellua.ScintillaNET.xml"),
                    "lua", true);
            ConfigurationManager.Language = "lua";
            ConfigurationManager.Configure(config);
            Folding.IsEnabled = true;
            /*Margins[0].Width = 20;
            Margins[1].Width = 20;
            Margins[2].Width = 20;*/
            AutoComplete.IsCaseSensitive = false;
            AutoComplete.AutoHide = false;
            //Indentation.ShowGuides = true;

            List<Bitmap> list = new List<Bitmap>();
            Assembly asm = Assembly.GetExecutingAssembly();
            Stream str;
            str = asm.GetManifestResourceStream("Intellua.member.png");
            list.Add(new Bitmap(str));
            str = asm.GetManifestResourceStream("Intellua.method.png");
            list.Add(new Bitmap(str));
            str = asm.GetManifestResourceStream("Intellua.function.png");
            list.Add(new Bitmap(str));
            str = asm.GetManifestResourceStream("Intellua.type.png");
            list.Add(new Bitmap(str));
            AutoComplete.RegisterImages(list);

            m_source = new IntelluaSource(this);
        }
예제 #7
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);
        }
예제 #8
0
 private void parseFile()
 {
     IntelluaSource source = new IntelluaSource(this, true);
     m_worker = new System.ComponentModel.BackgroundWorker();
     FileParser fp = new FileParser(source);
     /*fp.doWork(this,new System.ComponentModel.DoWorkEventArgs(0));
     m_autoCompleteData = fp.result;*/
     m_worker.DoWork += new System.ComponentModel.DoWorkEventHandler(fp.doWork);
     m_worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(parseFileDone);
     m_worker.RunWorkerAsync();
     
     
 }
예제 #9
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;
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
0
        private static FileParser getFile(string filename, Intellua parent, Dictionary<string, int> required)
        {
            if (s_files.ContainsKey(filename))
            {
                FileParser afp = s_files[filename];
                if (!afp.modified())
                {
                    return afp;
                }
                else
                {
                    System.Diagnostics.Debug.Print("modified");
                }
            }
            System.Diagnostics.Debug.Print("parse file " + filename);
            IntelluaSource source = new IntelluaSource(filename, parent);
            FileParser fp = new FileParser(source);
            foreach (var kv in required)
            {
                fp.m_required[kv.Key] = kv.Value;
            }

            fp.parse(true);
            s_files[filename] = fp;
            return fp;
        }
예제 #13
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;
        }