private List <LuaError> RunRegex(Regex r, String text, Scintilla editor) { List <LuaError> errorList = new List <LuaError>(); MatchCollection mc = r.Matches(text); foreach (Match m in mc) { // We use the scintilla editor object to determine whether // the match is actually inside a string. Int32 errorIndex = m.Groups["identifier"].Index; Int32 errorLength = m.Groups["identifier"].Length; if (editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_STRING && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_LITERALSTRING && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_STRINGEOL && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_COMMENT && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_COMMENTLINE && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_COMMENTDOC) { KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, errorIndex); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, errorIndex, errorIndex + indexOffset, errorLength, String.Format(this.errorMsg, m.Groups["identifier"].Value.Trim()) )); } } return(errorList); }
override public List <LuaError> GetError(String text, Scintilla editor) { List <LuaError> errorList = new List <LuaError>(); MatchCollection mc = this.rule.Matches(text); foreach (Match m in mc) { // We use the scintilla editor object to determine whether // the match is actually inside a string. Int32 errorIndex = m.Groups["identifier"].Index; Int32 errorLength = m.Groups["identifier"].Length; if (editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_STRING && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_LITERALSTRING && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_STRINGEOL && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_COMMENT && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_COMMENTLINE && editor.Styles.GetStyleAt(errorIndex) != (byte)LexerStyleConstants.SCE_LUA_COMMENTDOC) { // We must do additional checks to make sure the first and second groups are // not Lua keywords. String[] keywords = { "and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "is", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while" }; List <String> keywordsList = keywords.ToList <String>(); if (keywordsList.IndexOf(m.Groups["first"].Value) != -1 || keywordsList.IndexOf(m.Groups["second"].Value) != -1) { // Skip this error because it actually involves a keyword. continue; } KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, errorIndex); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, errorIndex, errorIndex + indexOffset, errorLength, String.Format(this.errorMsg, m.Groups["identifier"].Value.Trim()) )); } } return(errorList); }
override public List <LuaError> GetError(String text, Scintilla editor) { // Search the editor's characters for SCE_LUA_STRINGEOL. Boolean insideInvalidEOL = false; String textBuffer = ""; Int32 errorIndex = 0; List <LuaError> errorList = new List <LuaError>(); for (Int32 currentIndex = 0; currentIndex < text.Length; currentIndex += 1) { Byte characterStyle = editor.Styles.GetStyleAt(currentIndex); if (characterStyle == (byte)LexerStyleConstants.SCE_LUA_STRINGEOL) { if (insideInvalidEOL) { textBuffer += text[currentIndex]; } else { insideInvalidEOL = true; errorIndex = currentIndex; textBuffer = ""; // by not setting this to the character, we omit the leading " which // is normally included in the STRINGEOL section. } } else if (insideInvalidEOL) { KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, errorIndex); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, errorIndex, textBuffer.Length, String.Format(this.errorMsg, textBuffer.Trim()) )); insideInvalidEOL = false; errorIndex = 0; textBuffer = ""; } } return(errorList); }
static public List <LuaError> CheckBlocks(String text, Scintilla editor) { // Temporarily disabling block checking due to // http://code.google.com/p/roket3d/issues/detail?id=3. return(new List <LuaError>()); text += "\r\n"; // add a newline at the end // Define block stack and return list. Stack <LuaBlock> blockStack = new Stack <LuaBlock>(); List <LuaError> errorList = new List <LuaError>(); // Define our block start/end regex. Regex blockStartEnd = new Regex( "(^|[+\\-\\*/%\\^#=><\\(\\)\\{\\}\\[\\];:,\\.\\ \\\r\n\t])(?<underline>(" + "(?<start>function)|" + "(?<start>if)[\\ \\(\r\n](.|[\r\n\\ \t])*?[\\ \\)\r\n]then|" + "(?<start>while)[\\ \\(\r\n](.|[\r\n\\ \t])*?[\\ \\)\r\n]do|" + "(?<start>repeat)|" + "(?<end>until)[\\ \\(\r\n](.|[\r\n\\ \t])*?[\\ \\)\r\n]|" + "(?<end>end)|" + "(?<start>for)[\\ \\(\r\n](.|[\r\n\\ \t])*?[\\ \\)\r\n]do|" + "(?<start>elseif)[\\ \\(\r\n](.|[\r\n\\ \t])*?[\\ \\)\r\n]then" + "))([+\\-\\*/%\\^#=><\\(\\)\\{\\}\\[\\];:,\\.\\ \\\r\n\t]|$)"); MatchCollection linearBlocks = blockStartEnd.Matches(text); foreach (Match block in linearBlocks) { // Get the start or end block. Group start = block.Groups["start"]; Group underline = block.Groups["underline"]; Group end = block.Groups["end"]; if (editor.Styles.GetStyleAt(underline.Index) != (byte)LexerStyleConstants.SCE_LUA_STRING && editor.Styles.GetStyleAt(underline.Index) != (byte)LexerStyleConstants.SCE_LUA_LITERALSTRING && editor.Styles.GetStyleAt(underline.Index) != (byte)LexerStyleConstants.SCE_LUA_STRINGEOL && editor.Styles.GetStyleAt(underline.Index) != (byte)LexerStyleConstants.SCE_LUA_COMMENT && editor.Styles.GetStyleAt(underline.Index) != (byte)LexerStyleConstants.SCE_LUA_COMMENTLINE && editor.Styles.GetStyleAt(underline.Index) != (byte)LexerStyleConstants.SCE_LUA_COMMENTDOC) { if (start.Value != "") { // This is a start block. blockStack.Push(new LuaBlock(underline.Value, underline.Index, underline.Length)); } else if (end.Value != "") { // This is an end block. try { LuaBlock startBlock = blockStack.Pop(); if (end.Value == "until") { // Only valid start block is a repeat. if (startBlock.Name != "repeat") { KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, end.Index); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, end.Index, end.Length, String.Format("Only repeat blocks can be terminated with 'until'.", end.Value) )); } } else { // Make sure the start block is not a repeat. if (startBlock.Name == "repeat") { KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, end.Index); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, end.Index, end.Length, String.Format("Repeat blocks must be terminated with 'until'.", end.Value) )); } } } catch (InvalidOperationException) { KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, end.Index); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, end.Index, end.Length, String.Format("There is no matching start of block to \"{0}\".", end.Value.Replace("\r", " ").Replace("\n", " ")) )); } } } } if (blockStack.Count > 0) { // Go through an mark an error at the start of each block. foreach (LuaBlock block in blockStack) { KeyValuePair <Int32, Int32> lineColumn = SyntaxChecker.LineColumnBeforeIndex(text, block.Index); errorList.Add(new LuaError( lineColumn.Key, lineColumn.Value, block.Index, block.Length, String.Format("There is no matching end of block to \"{0}\".", block.Name.Replace("\r", " ").Replace("\n", " ")) )); } } return(errorList); }