public void AddFile(LuaFile file) { var index = Files.IndexOf(file); if (index != -1) Files[index] = file; else { Files.Add(file); } }
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); }
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); }
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."); }
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); } } } } }
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); } }
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); } }
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); } }
public LuaFunction(LuaFile file, string name, int line, params string[] args) : base(file, name, line, 0) { this.Args = args; this.Members = new List <LuaMember>(); }
public LuaFunction(LuaFile file, string name, int line, params string[] args) : this(name, line, args) { this.File = file; }
public LuaMember(LuaFile file, Token token) : this(file, token.ValueString, token.Location.Line, token.Location.Column) { }
public LuaTable(LuaFile file, string basetable, string name, int line) : this(file, name, line) { Father = basetable; }
public LuaTable(LuaFile file, string name, int line) : base(file, name, line, 0) { Members = new List <LuaMember>(); }
public LuaTable(LuaFile file, string name, int line) : this(name, line) { this.File = file; }