Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This event is raised when a syntax check needs to be performed on the
        /// current document.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">The event information.</param>
        private void c_CodeEditor_SyntaxCheckRequested(object sender, EventArgs e)
        {
            // Prevent flicker.
            if (this.c_CodeEditor.CanSyntaxCheck)
            {
                // TODO: Implement a refresh call to the Error List tool window.
            }

            // Clear all the indicators.
            this.c_CodeEditor.GetRange(0, this.c_CodeEditor.Text.Length).ClearIndicator(0);

            // Get errors.
            m_Errors = SyntaxChecker.Check(this.c_CodeEditor.Text, this.c_CodeEditor);

            // Apply highlighting to the errors.
            // TODO: Use a class variable to store the current filename.
            if (this.c_CodeEditor.CanSyntaxCheck)
            {
                // TODO: Clear all of the errors from the Error List tool window for
                //       this specific file.
            }
            foreach (LuaError err in m_Errors)
            {
                // Indicators have an offset by one.
                this.c_CodeEditor.GetRange(err.IndicatorIndex, err.Index + err.Length).SetIndicator(0);

                // TODO: Add the error to the error list.
                if (this.c_CodeEditor.CanSyntaxCheck)
                {
                }
            }

            // Prevent flicker.
            if (this.c_CodeEditor.CanSyntaxCheck)
            {
                // TODO: Implement a refresh call to the Error List tool window.
            }
        }
Exemplo n.º 5
0
        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);
        }