/// <summary> /// Compare arguments by compare mark. /// </summary> /// <param name="mark">Compare mark.</param> /// <param name="arg1">Argument 1.</param> /// <param name="arg2">Argument 2.</param> /// <param name="dex">Index of line.</param> internal bool CompareArguments(MochaScriptComparisonMark mark, object arg1, object arg2, int dex) { try { if (mark == MochaScriptComparisonMark.Undefined) { throw Throw(dex + 1, "|| ComparisonMark failed, no such ComparisonMark!"); } if (mark == MochaScriptComparisonMark.Equal) { return(arg1.Equals(arg2)); } if (mark == MochaScriptComparisonMark.NotEqual) { return(!arg1.Equals(arg2)); } var a1 = (decimal)MochaData.GetDataFromString(MochaDataType.Decimal, arg1.ToString()); var a2 = (decimal)MochaData.GetDataFromString(MochaDataType.Decimal, arg2.ToString()); if (mark == MochaScriptComparisonMark.EqualBigger) { return(a1 >= a2); } if (mark == MochaScriptComparisonMark.EqualSmaller) { return(a1 <= a2); } if (mark == MochaScriptComparisonMark.Bigger) { return(a1 > a2); } else { return(a1 < a2); } } catch { return(false); } }
/// <summary> /// Process if. /// </summary> /// <param name="startIndex">Process start index.</param> internal int Process_if(int startIndex) { bool ok = false; int closeIndex; for (int index = startIndex; index < MochaScriptArray.Length; index++) { string line = MochaScriptArray[index].Trim(); if (index == startIndex && line.StartsWith("if ")) { //Check argument. string[] elifArg = MochaScriptArray[index].Trim().Split(' '); if (elifArg.Length != 4) { throw Throw(index + 1, "|| The if comparison was wrong! There are too many or missing parameters!"); } //Get compare mark. MochaScriptComparisonMark elifMark = GetCompareMark(elifArg[2]); if (elifMark == MochaScriptComparisonMark.Undefined) { throw Throw(index + 1, "|| The comparison parameter is not recognized!"); } //Get Value Arguments. object ElifArg1 = GetArgumentValue("Undefined", elifArg[1], index); object ElifArg2 = GetArgumentValue("Undefined", elifArg[3], index); //Check arguments. if (ElifArg1 == null || ElifArg2 == null) { throw Throw(index + 1, "|| One of his arguments could not be processed!"); } closeIndex = codeProcessor.GetCloseBracketIndex(index + 2, '{', '}'); if (!ok && CompareArguments(elifMark, ElifArg1, ElifArg2, index)) { ok = true; ProcessRange(index + 2, closeIndex); index = closeIndex; continue; } else { index = closeIndex; continue; } } else if (line.StartsWith("elif ")) { //Check argument. string[] ElifArg = MochaScriptArray[index].Trim().Split(' '); if (ElifArg.Length != 4) { throw Throw(index + 1, "|| The if comparison was wrong! There are too many or missing parameters!"); } //Get compare mark. MochaScriptComparisonMark ElifMark = GetCompareMark(ElifArg[2]); if (ElifMark == MochaScriptComparisonMark.Undefined) { throw Throw(index + 1, "The comparison parameter is not recognized!"); } //Get Value Arguments. object ElifArg1 = GetArgumentValue("Undefined", ElifArg[1], index); object ElifArg2 = GetArgumentValue("Undefined", ElifArg[3], index); //Check arguments. if (ElifArg1 == null || ElifArg2 == null) { throw Throw(index + 1, "|| One of his arguments could not be processed!"); } closeIndex = codeProcessor.GetCloseBracketIndex(index + 2, '{', '}'); if (!ok && CompareArguments(ElifMark, ElifArg1, ElifArg2, index)) { ok = true; ProcessRange(index + 2, closeIndex); index = closeIndex; continue; } else { index = closeIndex; continue; } } else if (line == "else") { closeIndex = codeProcessor.GetCloseBracketIndex(index + 2, '{', '}'); if (!ok) { ProcessRange(index + 2, closeIndex); } return(closeIndex); } else { return(index - 1); } } throw Throw(startIndex + 1, "|| Could not process if-elif-else structures."); }