bool TryMatch(LuaMember tree, string[] keyword, int index, out LuaMember result) { result = null; LuaMember _cur = tree; if (_cur.Name.Equals(keyword[index])) { if (index == keyword.Length - 1) { result = _cur; return(true); } else if (_cur is LuaTable) { foreach (var lm in (_cur as LuaTable).Members) { if (TryMatch(lm, keyword, index + 1, out result)) { return(true); } } } else { return(false); } } return(false); }
public IEnumerable <LuaMember> FindReferencesInFile(LuaFile file, string keyword) { if (file != null) { List <string> lines = new List <string>(); try { using (StreamReader sr = new StreamReader(file.File)) { while (sr.Peek() >= 0) { lines.Add(sr.ReadLine()); } } } catch { yield break; } //for (int i = 0; i < file.Tokens.Count; i++) //{ // if(file.Tokens[i].Text.Equals(keyword)) // { // var lm = new LuaMember(file.Tokens[i]); // lm.Preview = lines[lm.Line]; // lm.File = file; // yield return lm; // } //} foreach (var token in file.Tokens) { if (token.EditorInfo == null || token.EditorInfo.Type != Irony.Parsing.TokenType.String) { if (token.ValueString.Equals(keyword)) { var lmp = new LuaMember(token); lmp.Preview = lines[lmp.Line]; lmp.File = file; yield return(lmp); } } else { if (string.IsNullOrEmpty(token.ValueString)) { continue; } int index = token.ValueString.IndexOf(keyword); if (index != -1) { var lmp = new LuaMember(keyword, token.Location.Line, token.Location.Column + 1 + index); lmp.Preview = lines[lmp.Line]; lmp.File = file; yield return(lmp); } } } } }
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 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 List<LuaMember> FindDefination(string keyword) //{ // List<LuaMember> members = new List<LuaMember>(); // string[] keywords = keyword.Split(new char[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries); // if (keywords.Length == 0) return null; // for (int i = 0; i < Files.Count; i++) // { // try // { // List<string> lines = new List<string>(); // using (StreamReader sr = new StreamReader(Files[i].File)) // { // while (sr.Peek() >= 0) // { // lines.Add(sr.ReadLine()); // } // } // foreach (LuaMember member in Files[i].Members) // { // if (member.Name.Equals(keyword)) // { // var lmp = member.Copy(); // lmp.Preview = lines[member.Line]; // lmp.File = Files[i]; // members.Add(lmp); // } // } // } // catch { } // } // return members; //} public LuaMember FindDefination(string keyword) { LuaMember result = null; string[] keywords = keyword.Split(new char[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries); if (keywords.Length != 0) { foreach (LuaFile file in Files) { if (TryFindDefinition(file, keywords, out result)) { break; } } } return(result); }