Browse Source

Implement warnings

Bepsi 6 years ago
parent
commit
d1b1ef3202

+ 16 - 1
NTERA.Compiler/Compiler.cs

@@ -15,6 +15,7 @@ namespace NTERA.Compiler
 		public string InputDirectory { get; }
 
 		public List<Tuple<ParserError, string>> Errors { get; } = new List<Tuple<ParserError, string>>();
+		public List<Tuple<ParserError, string>> Warnings { get; } = new List<Tuple<ParserError, string>>();
 
 		public Dictionary<FunctionDefinition, string> DeclaredFunctions = new Dictionary<FunctionDefinition, string>();
 
@@ -151,6 +152,10 @@ namespace NTERA.Compiler
 
 			var funcs = new List<FunctionDefinition>
 			{
+				new FunctionDefinition("ABS", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("CSVCALLNAME", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("TOFULL", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("TOINT", new[] { new FunctionParameter("a", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("RAND", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("TOSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("b", new string[0], "") }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("STRCOUNT", new[] { new FunctionParameter("input", new string[0]), new FunctionParameter("match", new string[0]) }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
@@ -169,13 +174,19 @@ namespace NTERA.Compiler
 				new FunctionDefinition("CSVNAME", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVTALENT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CSVCSTR", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("CSVEXP", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("CSVABL", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("GETNUM", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("FINDCHARA", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("LIMIT", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("SUBSTRINGU", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("GROUPMATCH", new[] { new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), new FunctionParameter("a", new string[0]), }, new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("GETTIME", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("SAVENOS", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("GETCOLOR", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 				new FunctionDefinition("CURRENTREDRAW", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("GETFONT", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
+				new FunctionDefinition("GETMILLISECOND", new FunctionParameter[0], new FunctionVariable[0], true, "_GLOBAL", new Marker()),
 			};
 
 			var stringStatements = new List<string>
@@ -274,10 +285,13 @@ namespace NTERA.Compiler
 
 					Parser parser = new Parser(kv.Value, kv.Key, funcs, procedures, globals, locals, stringStatements, csvDefinition);
 
-					var nodes = parser.Parse(out var localErrors);
+					var nodes = parser.Parse(out var localErrors, out var localWarnings);
 
 					lock (Errors)
 						Errors.AddRange(localErrors.Select(x => new Tuple<ParserError, string>(x, $"{kv.Key.Filename} - {kv.Key.Name}")));
+
+					lock (Warnings)
+						Warnings.AddRange(localWarnings.Select(x => new Tuple<ParserError, string>(x, $"{kv.Key.Filename} - {kv.Key.Name}")));
 				}
 				catch (Exception ex)
 				{
@@ -303,6 +317,7 @@ namespace NTERA.Compiler
 			var htmlWriter = new HTMLWriter
 			{
 				Errors = Errors.OrderBy(x => x.Item2).ToList(),
+				Warnings = Warnings.OrderBy(x => x.Item2).ToList(),
 				FunctionCount = DeclaredFunctions.Count,
 				TotalFileSize = fileSize,
 				TotalFileCount = fileCount

+ 18 - 2
NTERA.Compiler/HTMLWriter.cs

@@ -27,6 +27,7 @@ namespace NTERA.Compiler
 		public int FunctionCount { get; set; }
 
 		public IList<Tuple<ParserError, string>> Errors { get; set; }
+		public IList<Tuple<ParserError, string>> Warnings { get; set; }
 
 		public void WriteReportToFile(Stream outputStream)
 		{
@@ -50,7 +51,22 @@ namespace NTERA.Compiler
 		<p>Processed {fileSizeStr} MB in {TotalFileCount} files<br />
 			Processed {FunctionCount} functions
 		</p>
-		<p>{Errors.Count} errors</p>
+		<p>{Errors.Count} errors, {Warnings.Count} warnings</p>");
+
+			streamWriter.WriteLine(@"		<h4>Warnings</h4>
+		<table style=""height: 98px;"" width=""100%"">
+			<tbody>");
+
+			foreach (var warning in Warnings)
+			{
+				EmitError(streamWriter, warning.Item1, warning.Item2);
+			}
+
+			streamWriter.WriteLine($@"			</tbody>
+		</table>
+		<br />");
+			
+			streamWriter.WriteLine(@"		<h4>Errors</h4>
 		<table style=""height: 98px;"" width=""100%"">
 			<tbody>");
 
@@ -58,7 +74,7 @@ namespace NTERA.Compiler
 			{
 				EmitError(streamWriter, error.Item1, error.Item2);
 			}
-			
+
 			streamWriter.WriteLine($@"			</tbody>
 		</table>");
 		}

+ 4 - 0
NTERA.Compiler/NTERA.Compiler.csproj

@@ -54,6 +54,10 @@
     <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\NTERA.Core\NTERA.Core.csproj">
+      <Project>{62a2b84e-9207-46b0-8a8d-28b5931fcb6e}</Project>
+      <Name>NTERA.Core</Name>
+    </ProjectReference>
     <ProjectReference Include="..\NTERA.Interpreter\NTERA.Interpreter.csproj">
       <Project>{f3b58ef3-e3ff-4b76-92b8-2ab87663fc4d}</Project>
       <Name>NTERA.Interpreter</Name>

+ 13 - 7
NTERA.Interpreter/Compiler/Parser.cs

@@ -14,6 +14,9 @@ namespace NTERA.Interpreter.Compiler
 		protected ICollection<FunctionDefinition> FunctionDefinitions { get; }
 		protected ICollection<FunctionDefinition> ProcedureDefinitions { get; }
 
+		protected List<ParserError> Errors { get; } = new List<ParserError>();
+		protected List<ParserError> Warnings { get; } = new List<ParserError>();
+
 		protected VariableDictionary GlobalVariables { get; }
 
 		protected VariableDictionary LocalVariables { get; }
@@ -59,9 +62,8 @@ namespace NTERA.Interpreter.Compiler
 			CsvDefinition = csvDefinition;
 		}
 
-		public IEnumerable<ExecutionNode> Parse(out List<ParserError> errors)
+		public IEnumerable<ExecutionNode> Parse(out List<ParserError> errors, out List<ParserError> warnings)
 		{
-			errors = new List<ParserError>();
 			List<ExecutionNode> nodes = new List<ExecutionNode>();
 
 			using (Enumerator)
@@ -72,7 +74,7 @@ namespace NTERA.Interpreter.Compiler
 
 					if (error != null)
 					{
-						errors.Add(error);
+						Errors.Add(error);
 						nodes.Add(new ExecutionNode
 						{
 							Type = "error",
@@ -100,6 +102,9 @@ namespace NTERA.Interpreter.Compiler
 				} while (Enumerator.MoveNext());
 			}
 
+			errors = Errors;
+			warnings = Warnings;
+
 			return nodes;
 		}
 
@@ -735,10 +740,8 @@ namespace NTERA.Interpreter.Compiler
 					}
 					else
 					{
+						Warnings.Add(new ParserError($"Unknown identifier: {Lexer.Identifier}", CurrentPosition));
 						break;
-						//this should be converted into a warning
-						error = new ParserError($"Unknown identifier: {Lexer.Identifier}", CurrentPosition);
-						return null;
 					}
 				}
 				else if (token.IsArithmetic())
@@ -834,10 +837,13 @@ namespace NTERA.Interpreter.Compiler
 			}
 
 			if (Lexer.CurrentChar == '"')
+			{
+				implicitString = false;
 				Lexer.GetNextChar();
+			}
 
 			StringBuilder currentBlock = new StringBuilder();
-			while (Lexer.CurrentChar != '"'
+			while ((Lexer.CurrentChar != '"' || implicitString)
 				   && Lexer.CurrentChar != '\n'
 				   && Lexer.CurrentChar != '\0')
 			{