Эх сурвалжийг харах

Finalizing fixes for akumamaid

Bepsi 6 жил өмнө
parent
commit
61b442b3e9

+ 43 - 19
NTERA.Interpreter/Compiler/Parser.cs

@@ -191,7 +191,7 @@ namespace NTERA.Interpreter.Compiler
 
 						return node;
 					}
-					else if (Lexer.Identifier == "CASE")
+					else if (Lexer.Identifier.Equals("CASE", StringComparison.OrdinalIgnoreCase))
 					{
 						var node = new ExecutionNode
 						{
@@ -199,15 +199,14 @@ namespace NTERA.Interpreter.Compiler
 							Symbol = CurrentPosition
 						};
 
-						if (SelfDefinition.Filename == "EVENT_K15_LIBRARY.ERB" && CurrentPosition.Line == 131)
-						{
-							var f = 3;
-						}
-
 						List<ExecutionNode> subNodes = new List<ExecutionNode>();
 
 						do
 						{
+							if (GetNextToken(true) == Token.NewLine
+								|| GetNextToken(true) == Token.EOF)
+								break;
+
 							var value = Expression(out error);
 							if (error != null)
 								return null;
@@ -244,8 +243,8 @@ namespace NTERA.Interpreter.Compiler
 						node.SubNodes = subNodes.ToArray();
 						return node;
 					}
-					else if (Lexer.Identifier == "CALL"
-							 || Lexer.Identifier == "TRYCALL")
+					else if (Lexer.Identifier.Equals("CALL", StringComparison.OrdinalIgnoreCase)
+							 || Lexer.Identifier.Equals("TRYCALL", StringComparison.OrdinalIgnoreCase))
 					{
 						Enumerator.MoveNext();
 
@@ -301,9 +300,10 @@ namespace NTERA.Interpreter.Compiler
 
 						return CallMethod(target, symbolMarker, parameters.ToArray());
 					}
-					else if (Lexer.Identifier == "CALLFORM"
-							 || Lexer.Identifier == "TRYCALLFORM"
-							 || Lexer.Identifier == "TRYJUMPFORM")
+					else if (Lexer.Identifier.Equals("CALLFORM", StringComparison.OrdinalIgnoreCase)
+							 || Lexer.Identifier.Equals("TRYCALLFORM", StringComparison.OrdinalIgnoreCase)
+							 || Lexer.Identifier.Equals("TRYJUMPFORM", StringComparison.OrdinalIgnoreCase))
+
 					{
 						string statementName = Lexer.Identifier;
 
@@ -336,6 +336,10 @@ namespace NTERA.Interpreter.Compiler
 								if (error != null)
 									return null;
 							}
+							else if (Enumerator.Current == Token.LParen)
+							{
+								break;
+							}
 							else
 							{
 								error = new ParserError($"Unexpected token: {Enumerator.Current}", CurrentPosition);
@@ -353,7 +357,8 @@ namespace NTERA.Interpreter.Compiler
 
 
 						while (Enumerator.Current != Token.NewLine
-							   && Enumerator.Current != Token.EOF)
+							   && Enumerator.Current != Token.EOF
+							   && Enumerator.Current != Token.RParen)
 						{
 							parameters.Add(Expression(out error));
 							if (error != null)
@@ -364,7 +369,8 @@ namespace NTERA.Interpreter.Compiler
 
 							if (Enumerator.Current != Token.Comma
 								&& Enumerator.Current != Token.NewLine
-								&& Enumerator.Current != Token.EOF)
+								&& Enumerator.Current != Token.EOF
+								&& Enumerator.Current != Token.RParen)
 							{
 								error = new ParserError($"Unexpected token: {Enumerator.Current}", CurrentPosition);
 								return null;
@@ -387,7 +393,7 @@ namespace NTERA.Interpreter.Compiler
 
 						return node;
 					}
-					else if (Lexer.Identifier == "BEGIN")
+					else if (Lexer.Identifier.Equals("BEGIN", StringComparison.OrdinalIgnoreCase))
 					{
 						var node = new ExecutionNode
 						{
@@ -611,6 +617,19 @@ namespace NTERA.Interpreter.Compiler
 				if (GetNextToken(true) == Token.RParen)
 					break;
 
+				if (GetNextToken(true) == Token.Comma)
+				{
+					var defaultValue = new ExecutionNode
+					{
+						Type = "defaultvalue",
+						Symbol = CurrentPosition
+					};
+
+					parameters.Add(defaultValue);
+					GetNextToken();
+					continue;
+				}
+
 				parameters.Add(Expression(out error));
 				if (error != null)
 					return null;
@@ -734,7 +753,7 @@ namespace NTERA.Interpreter.Compiler
 				   && token != Token.RParen
 				   && token != Token.QuestionMark
 				   && token != Token.Sharp
-				   && token != Token.TernaryEscape
+				   && (!ternaryString || token != Token.TernaryEscape)
 				   && (useModulo || token != Token.Modulo))
 			{
 				if (token == Token.Value)
@@ -772,6 +791,12 @@ namespace NTERA.Interpreter.Compiler
 						break;
 					}
 				}
+				else if (token == Token.TernaryEscape)
+				{
+					operands.Push(Expression(out error, useModulo, true));
+					if (error != null)
+						return null;
+				}
 				else if (token.IsArithmetic())
 				{
 					if (token.IsUnary())
@@ -833,11 +858,11 @@ namespace NTERA.Interpreter.Compiler
 			if (token != Token.QuestionMark)
 				return result;
 
-			var resultTrue = ternaryString ? ParseString(out error, useModulo, true, true) : Expression(out error);
+			var resultTrue = ternaryString ? ParseString(out error, useModulo, true, true) : Expression(out error, useModulo);
 			if (error != null)
 				return null;
 
-			var resultFalse = ternaryString ? ParseString(out error, useModulo, true, true) : Expression(out error);
+			var resultFalse = ternaryString ? ParseString(out error, useModulo, true, true) : Expression(out error, useModulo);
 			if (error != null)
 				return null;
 
@@ -864,9 +889,8 @@ namespace NTERA.Interpreter.Compiler
 				Lexer.GetNextChar();
 			}
 
-			if (Lexer.CurrentChar == '"')
+			if (!implicitString && Lexer.CurrentChar == '"')
 			{
-				implicitString = false;
 				Lexer.GetNextChar();
 			}