Beispiel #1
0
		public void AddFile(LuaFile file)
		{
			var index = Files.IndexOf(file);
			if (index != -1) Files[index] = file;
			else
			{
				Files.Add(file);
			}
		}
Beispiel #2
0
        public List <LuaMember> SearchInFile(LuaFile file, string keyword, bool CaseSensitive)
        {
            List <LuaMember> members = new List <LuaMember>();

            if (file != null)
            {
                try
                {
                    var options = System.Text.RegularExpressions.RegexOptions.None;
                    if (!CaseSensitive)
                    {
                        options = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
                    }
                    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(System.Text.RegularExpressions.Regex.Escape(keyword), options);

                    List <string> lines = new List <string>();
                    using (StreamReader sr = new StreamReader(file.Path))
                    {
                        while (sr.Peek() >= 0)
                        {
                            lines.Add(sr.ReadLine());
                        }
                    }

                    for (int i = 0; i < lines.Count; i++)
                    {
                        var match = reg.Match(lines[i]);
                        while (match.Success)
                        {
                            var lm = new LuaMember(file, keyword, i, match.Index);
                            lm.Preview = lines[i];
                            members.Add(lm);
                            match = match.NextMatch();
                        }
                    }

                    //int index = -1;
                    //for(int i = 0;i<lines.Count;i++)
                    //{
                    //	index = lines[i].IndexOf(keyword);
                    //	while (index != -1)
                    //	{
                    //		var lm = new LuaMember(keyword, i, index);
                    //		lm.Preview = lines[i];
                    //		lm.File = file.File;
                    //		members.Add(lm);
                    //		index = lines[i].IndexOf(keyword, index + keyword.Length);
                    //	}
                    //}
                }
                catch { }
            }

            return(members);
        }
Beispiel #3
0
 bool TryFindDefinition(LuaFile file, string[] keyword, out LuaMember result)
 {
     result = null;
     foreach (var lm in file.Members)
     {
         if (TryMatch(lm, keyword, 0, out result))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #4
0
        public void Refresh(ParseTree tree)
        {
            File = new LuaFile(FileManager.Instance.CurrentFile.Path, tree.Tokens);
            var root = tree.Root;

            if (root != null)
            {
                UpdateData(root);
            }
            FileManager.Instance.CurrentFile = File;

            System.Diagnostics.Debug.Print("file refreshed.");
        }
Beispiel #5
0
        public IEnumerable <LuaMember> FindReferencesInFile(LuaFile file, string keyword)
        {
            if (file != null)
            {
                List <string> lines = new List <string>();
                try
                {
                    using (StreamReader sr = new StreamReader(file.Path))
                    {
                        while (sr.Peek() >= 0)
                        {
                            lines.Add(sr.ReadLine());
                        }
                    }
                }
                catch
                {
                    yield break;
                }

                foreach (var token in file.Tokens)
                {
                    if (token.EditorInfo == null || token.EditorInfo.Type != Irony.Parsing.TokenType.String)
                    {
                        if (token.ValueString.Equals(keyword) && lines[token.Location.Line].Contains(keyword))
                        {
                            var lmp = new LuaMember(file, token);
                            lmp.Preview = lines[lmp.Line];
                            yield return(lmp);
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(token.ValueString))
                        {
                            continue;
                        }
                        int index = token.ValueString.IndexOf(keyword);
                        if (index != -1)
                        {
                            var lmp = new LuaMember(file, keyword, token.Location.Line, token.Location.Column + 1 + index);
                            lmp.Preview = lines[lmp.Line];
                            yield return(lmp);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public void HandleFile(string file)
        {
            if (!System.IO.File.Exists(file))
            {
                return;
            }

            try
            {
                FileStream fileStream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                using (StreamReader reader = new StreamReader(fileStream))
                {
                    var parser = new Parser(LuaGrammar.Instance);
                    var tree   = parser.Parse(reader.ReadToEnd());

                    File = new LuaFile(file, tree.Tokens);

                    if ((tree.HasErrors() && tree.Root != null) || (!tree.HasErrors() && tree.Root == null))
                    {
                        System.Diagnostics.Debugger.Break();
                    }

                    var root = tree.Root;
                    if (root != null)
                    {
                        UpdateData(root);
                    }
                    else
                    {
                        //System.Diagnostics.Debug.Print("***********error***********" + file);
                        //BabePackage.DTEHelper.OutputWindowWriteLine(file + "  has syntax error(s).");
                    }

                    FileManager.Instance.AddFile(File);
                }
            }
            catch (Exception e)
            {
                //Logger.LogMessage("HandleFile Failed:" + e.GetType().FullName + ",Method:" + e.TargetSite);
            }
        }
Beispiel #7
0
        public void HandleFile(string file)
        {
            if (!System.IO.File.Exists(file))
            {
                return;
            }

            try
            {
                FileStream fileStream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                using (StreamReader reader = new StreamReader(fileStream))
                {
                    var parser = new Parser(LuaGrammar.Instance);
                    var tree   = parser.Parse(reader.ReadToEnd());

                    File = new LuaFile(file, tree.Tokens);

                    var root = tree.Root;
                    if (root != null)
                    {
                        Test(root);
                        File.Members.AddRange(UpdateData(root));
                    }
                    else
                    {
                        System.Diagnostics.Debug.Print("***********error***********" + file);
                    }

                    FileManager.Instance.AddFile(File);
                }
            }
            catch (Exception e)
            {
                Logger.LogMessage("HandleFile Failed:" + e.GetType().FullName + ",Method:" + e.TargetSite);
            }
        }
Beispiel #8
0
        public LuaFile ParseFile(string file)
        {
            if (!System.IO.File.Exists(file))
            {
                return(null);
            }

            try
            {
                FileStream fileStream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                using (StreamReader reader = new StreamReader(fileStream))
                {
                    var parser = new Parser(LuaGrammar.Instance);
                    var tree   = parser.Parse(reader.ReadToEnd());

                    File = new LuaFile(file, tree.Tokens);

                    var root = tree.Root;
                    if (root != null)
                    {
                        UpdateData(root);
                    }
                    else
                    {
                        System.Diagnostics.Debug.Print("***********error***********" + file);
                    }
                }

                return(File);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Beispiel #9
0
 public LuaFunction(LuaFile file, string name, int line, params string[] args)
     : base(file, name, line, 0)
 {
     this.Args    = args;
     this.Members = new List <LuaMember>();
 }
Beispiel #10
0
 public LuaFunction(LuaFile file, string name, int line, params string[] args)
     : this(name, line, args)
 {
     this.File = file;
 }
Beispiel #11
0
 public LuaMember(LuaFile file, Token token) :
     this(file, token.ValueString, token.Location.Line, token.Location.Column)
 {
 }
Beispiel #12
0
 public LuaTable(LuaFile file, string basetable, string name, int line)
     : this(file, name, line)
 {
     Father = basetable;
 }
Beispiel #13
0
 public LuaTable(LuaFile file, string name, int line) : base(file, name, line, 0)
 {
     Members = new List <LuaMember>();
 }
Beispiel #14
0
 public LuaTable(LuaFile file, string name, int line) : this(name, line)
 {
     this.File = file;
 }