Beispiel #1
0
        static void LogError(string errorText, ErrorPosition position = default(ErrorPosition))
        {
            string prefix = "";

            if (!position.Equals(default(ErrorPosition)))
            {
                if (MSBuildErrors)
                {
                    prefix = position.Filename + "(" +
                             position.LineNumber + "," +
                             position.ColumnNumber + (position.Length > 0 ? "," + position.LineNumber + "," + (position.ColumnNumber + position.Length) : "") +
                             ") : error CERROR : ";
                }
                else
                {
                    prefix = position.Filename + " (Line " +
                             position.LineNumber + ", Column " +
                             position.ColumnNumber +
                             "): ";
                }
            }

            if (string.IsNullOrEmpty(prefix) && MSBuildErrors)
            {
                prefix = "JoopCompiler : error CERROR : ";
            }

            Console.WriteLine(prefix + errorText);
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new instance of ParserException
 /// </summary>
 /// <param name="message">Error message</param>
 /// <param name="severity">Error severity</param>
 /// <param name="group">Error group</param>
 /// <param name="path">File name where error ocuured</param>
 /// <param name="pos">Error position</param>
 public ParserException(string message, ErrorSeverity severity, int group, string path, ErrorPosition pos)
     : base(message)
 {
     FullPath = path;
     Severity = severity;
     Group    = group;
     Position = pos;
 }
        public void SmokeTest()
        {
            var start = new ErrorPosition(2, 2);
            var end   = new ErrorPosition(2, 3);
            var range = new ErrorRange(start, end);
            var error = new CompilationError(ErrorSeverity.Warning, "message", range);

            Assert.Equal("message", error.Message);
            Assert.Equal(ErrorSeverity.Warning, error.Severity);
            Assert.Equal(new ErrorPosition(2, 2), error.Location.Start);
            Assert.Equal(new ErrorPosition(2, 3), error.Location.End);

            Assert.Throws <ArgumentException>(() => new CompilationError(ErrorSeverity.Error, "message", new ErrorRange(end, start)));
        }
Beispiel #4
0
        /// <summary>
        /// Log Errors/Warnings/Messages when the compiler reports them.
        /// </summary>
        /// <param name="path">Path to the file where the error was found (null/empty if N/A)</param>
        /// <param name="message">Text of the error/warning/message</param>
        /// <param name="startLine">First line of the block containing the error (0 if N/A)</param>
        /// <param name="startColumn">First column of the block containing the error (0 if N/A)</param>
        /// <param name="endLine">Last line of the block containing the error (0 if N/A)</param>
        /// <param name="endColumn">Last column of the block containing the error (0 if N/A)</param>
        /// <param name="errorCode">Code corresponding to the error</param>
        /// <param name="severity">Error/Warning/Message</param>
        protected override bool Add(int id, string /*!*/ message, ErrorSeverity severity, int group, string fullPath,
                                    ErrorPosition pos)
        {
            string code = ErrorIdToCode(id);

            switch (severity.Value)
            {
            case ErrorSeverity.Values.FatalError:
            case ErrorSeverity.Values.Error:
            case ErrorSeverity.Values.WarningAsError:
                logger.LogError(severity.Value.ToString(), code, "", fullPath, pos.FirstLine, Math.Max(0, pos.FirstColumn - 1), pos.LastLine, pos.LastColumn, message);
                break;

            case ErrorSeverity.Values.Warning:
                logger.LogWarning(severity.Value.ToString(), code, "", fullPath, pos.FirstLine, Math.Max(0, pos.FirstColumn - 1), pos.LastLine, pos.LastColumn, message);
                break;
            }
            return(true);
        }
Beispiel #5
0
        public void TestEquals()
        {
            var pos1 = new ErrorPosition(1, 1);
            var pos2 = new ErrorPosition(1, 2);
            var pos3 = new ErrorPosition(2, 1);
            var pos4 = new ErrorPosition(1, 1);

            Assert.Equal(pos1, pos4);
            Assert.NotEqual(pos1, pos2);
            Assert.NotEqual(pos1, pos3);

            // ReSharper disable once EqualExpressionComparison
            Assert.True(pos1.Equals(pos1));
            Assert.True(pos1.Equals(pos4));
            Assert.False(pos1.Equals(null));
            Assert.False(pos1.Equals(new object()));

            Assert.Equal(pos1.GetHashCode(), pos4.GetHashCode());
            Assert.NotEqual(pos1.GetHashCode(), pos2.GetHashCode());
        }
Beispiel #6
0
        public void TestCompareTo()
        {
            var pos1 = new ErrorPosition(1, 1);
            var pos2 = new ErrorPosition(1, 2);
            var pos3 = new ErrorPosition(2, 1);
            var pos4 = new ErrorPosition(1, 1);

            Assert.True(pos1 < pos2);
            Assert.False(pos1 < pos4);
            Assert.True(pos1 <= pos2);
            Assert.True(pos1 <= pos4);
            Assert.True(pos2 > pos1);
            Assert.False(pos1 > pos4);
            Assert.True(pos2 >= pos1);
            Assert.True(pos1 >= pos4);
            Assert.True(pos1 == pos4);
            Assert.True(pos1 != pos2);

            Assert.True(pos3 > pos1);
            Assert.True(pos3 > pos2);
        }
Beispiel #7
0
			/// <summary>
			/// Called when an error/warning should be reported.
			/// </summary>
			protected override bool Add(int id, string message, ErrorSeverity severity, int group, string fullPath, ErrorPosition pos)
			{
				if (id >= 0)
				{
					CompilerError error = new CompilerError();

					error.FileName = fullPath;
					error.Line = pos.FirstLine;
					error.Column = pos.FirstColumn;
					error.ErrorNumber = String.Format("PHP{0:d4}", id);
					error.ErrorText = message;
					error.IsWarning = (severity.Value == ErrorSeverity.Values.Warning);

					results.Errors.Add(error);
				}

				// build the output line
				StringBuilder sb = new StringBuilder(128);
				if (fullPath != null)
				{
					sb.AppendFormat("{0}({1},{2}): ",
						fullPath,
						pos.FirstLine,
						pos.FirstColumn);
				}

				if (id >= 0)
				{
					sb.AppendFormat("{0} PHP{1:d4}: {2}",
						severity.ToCmdString(),
						id,
						message);
				}
				else sb.Append(message);

				results.Output.Add(sb.ToString());

				return true;
			}
Beispiel #8
0
        void Error(IToken offendingSymbol, string message)
        {
            // A couple things to note about the start and end column range:
            //     1. line and column numbers are zero based from the lexer but one based for our API
            //     2. error ranges are start inclusive but end exclusive [start, end).
            string input = offendingSymbol.InputStream.ToString();

            string[] lines = input.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);

            int line        = offendingSymbol.Line;
            int column      = offendingSymbol.Column + 1;
            int tokenLength = offendingSymbol.Text.Length;
            int lineLength  = lines[line - 1].Length;

            var start = new ErrorPosition(line, column);

            // Set the end column to the minimum of column + token length or line length + 2 (one based and exclusive end column, see note above)
            int endColumn = Math.Min(column + tokenLength, lineLength + 2);
            var end       = new ErrorPosition(line, endColumn);
            var error     = new CompilationError(ErrorSeverity.Error, message, new ErrorRange(start, end));

            this.errors.Add(error);
        }
Beispiel #9
0
 protected override bool Add(int id, string message,
     ErrorSeverity severity, int group, string fullPath, ErrorPosition pos) {
     if(severity.IsFatal)
         PhpException.Throw(PhpError.CompileError, "Parsing failed: " + message);
     return true;
 }
Beispiel #10
0
 protected override bool Add(int id, string message,
                             ErrorSeverity severity, int group, string fullPath, ErrorPosition pos)
 {
     if (severity.IsFatal)
     {
         PhpException.Throw(PhpError.CompileError, "Parsing failed: " + message);
     }
     return(true);
 }
Beispiel #11
0
            /// <summary>
            /// Called when an error/warning should be reported.
            /// </summary>
            protected override bool Add(int id, string message, ErrorSeverity severity, int group, string fullPath, ErrorPosition pos)
            {
                if (id >= 0)
                {
                    CompilerError error = new CompilerError();

                    error.FileName    = fullPath;
                    error.Line        = pos.FirstLine;
                    error.Column      = pos.FirstColumn;
                    error.ErrorNumber = String.Format("PHP{0:d4}", id);
                    error.ErrorText   = message;
                    error.IsWarning   = (severity.Value == ErrorSeverity.Values.Warning);

                    results.Errors.Add(error);
                }

                // build the output line
                StringBuilder sb = new StringBuilder(128);

                if (fullPath != null)
                {
                    sb.AppendFormat("{0}({1},{2}): ",
                                    fullPath,
                                    pos.FirstLine,
                                    pos.FirstColumn);
                }

                if (id >= 0)
                {
                    sb.AppendFormat("{0} PHP{1:d4}: {2}",
                                    severity.ToCmdString(),
                                    id,
                                    message);
                }
                else
                {
                    sb.Append(message);
                }

                results.Output.Add(sb.ToString());

                return(true);
            }
Beispiel #12
0
 /// <summary>
 /// Add an error.
 /// </summary>
 /// <param name="id">Id of error</param>
 /// <param name="message">Error message</param>
 /// <param name="severity">Error severity</param>
 /// <param name="group">Error group</param>
 /// <param name="fullPath">Full path of parser file</param>
 /// <param name="pos">Error position</param>
 /// <returns>Doesn't return anything ends with excpetion</returns>
 protected override bool Add(int id, string message, ErrorSeverity severity, int group, string fullPath, ErrorPosition pos)
 {
     //for now every parser error ends with excption. I am not really sure if there are errors or parser warning s that doenst have to end with excpetion
     throw new ParserException(String.Format("Parser {4}: {0} at line {1}, char {2}: {3}", fullPath, pos.FirstLine, pos.FirstColumn, message, severity.Value), severity, group, fullPath, pos);
 }