public static DynLanCodeLine PrevLineWithLessDepth( #if !NET20 this #endif DynLanCodeLines Lines, DynLanCodeLine StartLine, Func <DynLanCodeLine, Boolean> Predicate) { Int32 depth = (StartLine == null ? 0 : StartLine.Depth); Int32 index = (StartLine == null ? 0 : Lines.IndexOf(StartLine)); if (index < 0) { return(null); } for (var i = index - 1; i >= 0; i--) { DynLanCodeLine line = Lines[i]; if (!line.IsLineEmpty && line.Depth < depth) { if (Predicate == null || Predicate(line)) { return(line); } } } return(null); }
public static DynLanCodeLine NextOnSameOrHigher( #if !NET20 this #endif DynLanCodeLines Lines, DynLanCodeLine StartLine) { Int32 depth = (StartLine == null ? 0 : StartLine.Depth); Int32 index = (StartLine == null ? 0 : Lines.IndexOf(StartLine)); if (index < 0) { return(null); } for (var i = index + 1; i < Lines.Count; i++) { DynLanCodeLine line = Lines[i]; if (!line.IsLineEmpty) { if (line.Depth > depth) { return(line); } else if (line.Depth == depth) { return(line); } } } return(null); }
public static DynLanCodeLine NextOnSameOrLower( #if !NET20 this #endif DynLanCodeLines Lines, DynLanCodeLine StartLine, Func <DynLanCodeLine, Boolean> Predicate) { Int32 depth = (StartLine == null ? 0 : StartLine.Depth); Int32 index = (StartLine == null ? 0 : Lines.IndexOf(StartLine)); if (index < 0) { return(null); } for (var i = index + 1; i < Lines.Count; i++) { DynLanCodeLine line = Lines[i]; if (!line.IsLineEmpty && line.Depth <= depth) { if (Predicate == null || Predicate(line)) { return(line); } } } return(null); }
public static DynLanCodeLine NextOnSameOrLower( #if !NET20 this #endif DynLanCodeLines Lines, DynLanCodeLine StartLine) { return(NextOnSameOrLower(Lines, StartLine, null)); }
private static Boolean?CheckIfFinishedOrEmptyLine( DynContext DynLanContext, DynLanState currentState) { if (currentState == null || DynLanContext.IsFinished) { DynLanContext.IsFinished = true; return(true); } if (DynLanContext.ExceptionToThrow != null) { Exception ex = DynLanContext.ExceptionToThrow; DynLanContext.ExceptionToThrow = null; throw ex; } DynLanCodeLines lines = currentState.GetCurrentLines(); DynLanCodeLine currentLine = currentState.GetCurrentLine(); if (currentLine == null) { return(ExitCurrentContext( DynLanContext, null)); } // jeśli linia jest pusta to przechodzimy do nastepnej if (currentLine.IsLineEmpty) { DynLanCodeLine nextLine = DynLanCodeLinesExtender.NextLine(lines, currentLine); if (nextLine == null) { return(ExitCurrentContext( DynLanContext, null)); } else { currentState.CurrentLineID = nextLine.ID; } return(true); } return(null); }
private static Boolean?ExecuteCalculations( DynContext DynLanContext, DynLanState currentState, out Object Result) { Result = null; DynLanCodeLines lines = currentState.GetCurrentLines(); DynLanCodeLine currentLine = currentState.GetCurrentLine(); // wykonanie kalkulacji if (currentLine.ContainsAnyExpressions() && currentLine.OperatorType != EOperatorType.ELSE && currentLine.OperatorType != EOperatorType.PASS && currentLine.OperatorType != EOperatorType.CATCH) { if (DynLanContext.CurrentState.ExpressionContext == null) { DynLanContext.CurrentState.ExpressionContext = new ExpressionContext(currentLine.ExpressionGroup); } if (DynLanContext.CurrentState.ExpressionContext != null && DynLanContext.CurrentState.ExpressionContext.IsFinished) { Result = DynLanContext.CurrentState.ExpressionContext.Result; DynLanContext.CurrentState.ExpressionContext = null; } else { try { Boolean result = ExpressionEvaluator.NextStep( DynLanContext); return(result); } catch { throw; } } } return(null); }
public static DynLanCodeLine ExitParentIf( #if !NET20 this #endif DynLanCodeLines Lines, DynLanCodeLine StartLine) { Int32 depth = (StartLine == null ? 0 : StartLine.Depth); Int32 index = (StartLine == null ? 0 : Lines.IndexOf(StartLine)); if (index < 0) { return(null); } DynLanCodeLine line = StartLine; while (true) { line = NextLine( Lines, line); if (line == null) { break; } if (line.Depth < StartLine.Depth) { return(line); } if (line.Depth == StartLine.Depth && line.OperatorType != EOperatorType.ELIF && line.OperatorType != EOperatorType.ELSE) { return(line); } } return(null); }
private static Boolean GotoCatch( DynContext DynLanContext, Exception exception) { while (true) { DynLanState currentState = DynLanContext. CurrentState; // reset dla kontekstu obliczeń, ponieważ przechodzimy do catch'a currentState.ExpressionContext = null; DynLanCodeLines lines = currentState.GetCurrentLines(); DynLanCodeLine currentLine = currentState.GetCurrentLine(); // poszukanie poprzedniego catch'a DynLanCodeLine prevCatch = DynLanCodeLinesExtender. PrevLineWithLessDepth(lines, currentLine, l => l.OperatorType == EOperatorType.CATCH); // poszukanie poprzedniego try'a DynLanCodeLine prevTry = DynLanCodeLinesExtender. PrevLineWithLessDepth(lines, currentLine, l => l.OperatorType == EOperatorType.TRY); if (exception is DynLanAbortException) { ExitCurrentContext( DynLanContext, exception); if (DynLanContext.IsFinished) { break; } } else if (prevTry == null) { ExitCurrentContext( DynLanContext, exception); if (DynLanContext.IsFinished) { break; } } // jeśli znalazł try'a i nie jesteśmy w catch'u else if (prevTry.Depth < currentLine.Depth && (prevCatch == null || lines.IndexOf(prevCatch) < lines.IndexOf(prevTry))) { DynLanCodeLine nextCatch = DynLanCodeLinesExtender.NextOnSameOrLower( lines, prevTry, i => i.OperatorType == EOperatorType.CATCH); if (nextCatch != null) { ExpressionToken variableForException = null; if (nextCatch.ExpressionGroup != null && nextCatch.ExpressionGroup.MainExpression != null && nextCatch.ExpressionGroup.MainExpression.Tokens != null && nextCatch.ExpressionGroup.MainExpression.Tokens.Count > 0) { #if !NET20 variableForException = nextCatch. ExpressionGroup.MainExpression.Tokens. FirstOrDefault(i => i.TokenType != TokenType.BRACKET_BEGIN); #else variableForException = Linq2.FirstOrDefault(nextCatch. ExpressionGroup.MainExpression.Tokens, i => i.TokenType != TokenType.BRACKET_BEGIN); #endif } currentState.CurrentLineID = nextCatch.ID; if (variableForException != null && !String.IsNullOrEmpty(variableForException.TokenName)) { currentState.Object[variableForException.TokenName] = exception; } break; } else { ExitCurrentContext( DynLanContext, exception); if (DynLanContext.IsFinished) { break; } } } else { ExitCurrentContext( DynLanContext, exception); if (DynLanContext.IsFinished) { break; } } } return(false); }
////////////////////////////////////////////// private static Boolean GotoNextLine( DynContext DynLanContext, DynLanState currentState, Object currentValue) { try { DynLanCodeLines lines = currentState.GetCurrentLines(); DynLanCodeLine currentLine = currentState.GetCurrentLine(); // jesli return to konczymy if (currentLine.OperatorType == EOperatorType.RETURN) { return(ExitCurrentContext( DynLanContext, currentValue, null)); } // throw błędu else if (currentLine.OperatorType == EOperatorType.THROW) { if (currentValue is Exception) { throw (Exception)currentValue; } else { String message = UniConvert.ToString(currentValue ?? ""); throw String.IsNullOrEmpty(message) ? new Exception() : new Exception(message); } /*return ExitCurrentContext( * DynLanContext, * new Exception(message));*/ } // jesli return to konczymy else if (currentLine.OperatorType == EOperatorType.BREAK) { return(ExitCurrentLoop( DynLanContext, currentValue, null)); } if (currentLine.OperatorType == EOperatorType.WHILE || currentLine.OperatorType == EOperatorType.IF || currentLine.OperatorType == EOperatorType.ELIF) { Boolean conditionResult = BooleanHelper.IfTrue(currentValue); if (conditionResult) { DynLanCodeLine nextLine = DynLanCodeLinesExtender. NextOnSameOrHigher(lines, currentLine); if (nextLine != null) { currentState.CurrentLineID = nextLine.ID; } else { throw new NotImplementedException(); } } else { DynLanCodeLine nextLine = DynLanCodeLinesExtender. NextOnSameOrLower(lines, currentLine); if (nextLine == null) { return(ExitCurrentContext( DynLanContext, null)); } else { if (nextLine.Depth < currentLine.Depth) { while ( nextLine != null & (nextLine.OperatorType == EOperatorType.ELSE || nextLine.OperatorType == EOperatorType.ELIF /*|| * nextLine.OperatorType == EOperatorType.FINALLY*/)) { nextLine = DynLanCodeLinesExtender.ExitParentIf(lines, nextLine); if (nextLine == null) { break; } } if (nextLine == null) { return(ExitCurrentContext( DynLanContext, null)); } if (nextLine.Depth < currentLine.Depth) { //DynLanCodeLine prevIf = lines. // PrevLineWithLessDepth(currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF); while (true) { DynLanCodeLine prevConditionLine = DynLanCodeLinesExtender.PrevLineWithLessDepth( lines, currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF || l.OperatorType == EOperatorType.ELSE || l.OperatorType == EOperatorType.WHILE); if (prevConditionLine != null && prevConditionLine.Depth >= nextLine.Depth && prevConditionLine.OperatorType == EOperatorType.WHILE) { currentState.CurrentLineID = prevConditionLine.ID; break; } else if (prevConditionLine != null) { currentLine = prevConditionLine; } else { currentState.CurrentLineID = nextLine.ID; break; } } } else { currentState.CurrentLineID = nextLine.ID; } } else { currentState.CurrentLineID = nextLine.ID; } } } } else if ( currentLine.OperatorType == EOperatorType.TRY || currentLine.OperatorType == EOperatorType.ELSE) { DynLanCodeLine nextLine = DynLanCodeLinesExtender. NextOnSameOrHigher(lines, currentLine); if (nextLine != null) { currentState.CurrentLineID = nextLine.ID; } else { throw new NotImplementedException(); } } else if ( (currentLine.OperatorType == EOperatorType.FINALLY)) { throw new NotImplementedException("FINALLY"); } else if ( (currentLine.OperatorType == EOperatorType.CATCH)) { if (DynLanContext.Error != null) { DynLanContext.Error = null; DynLanCodeLine nextLine = DynLanCodeLinesExtender. NextOnSameOrHigher(lines, currentLine); if (nextLine != null) { currentState.CurrentLineID = nextLine.ID; } else { throw new NotImplementedException(); } } else { DynLanCodeLine nextLine = DynLanCodeLinesExtender.NextOnSameOrLower( lines, currentLine); if (nextLine != null) { currentState.CurrentLineID = nextLine.ID; } else { return(ExitCurrentContext( DynLanContext, null)); } } } else if (currentLine.OperatorType == EOperatorType.NONE || currentLine.OperatorType == EOperatorType.PASS) { DynLanCodeLine nextLine = DynLanCodeLinesExtender.NextLine(lines, currentLine); if (nextLine != null) { while ( nextLine != null & (nextLine.OperatorType == EOperatorType.ELSE || nextLine.OperatorType == EOperatorType.ELIF /*|| * nextLine.OperatorType == EOperatorType.FINALLY*/)) { nextLine = DynLanCodeLinesExtender.ExitParentIf(lines, nextLine); if (nextLine == null) { return(ExitCurrentContext( DynLanContext, null)); } } if (nextLine == null) { return(ExitCurrentContext( DynLanContext, null)); } if (nextLine.Depth < currentLine.Depth) { //DynLanCodeLine prevIf = lines. // PrevLineWithLessDepth(currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF); while (true) { DynLanCodeLine prevConditionLine = DynLanCodeLinesExtender. PrevLineWithLessDepth( lines, currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF || l.OperatorType == EOperatorType.ELSE || l.OperatorType == EOperatorType.WHILE); if (prevConditionLine != null && prevConditionLine.Depth >= nextLine.Depth && prevConditionLine.OperatorType == EOperatorType.WHILE) { currentState.CurrentLineID = prevConditionLine.ID; break; } else if (prevConditionLine != null) { currentLine = prevConditionLine; } else { currentState.CurrentLineID = nextLine.ID; break; } } } else { currentState.CurrentLineID = nextLine.ID; } } // jeśli ostatnia linia i jesteśmy w while'u else { //DynLanCodeLine prevIf = lines. // PrevLineWithLessDepth(currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF); while (true) { DynLanCodeLine prevConditionLine = DynLanCodeLinesExtender. PrevLineWithLessDepth( lines, currentLine, l => l.OperatorType == EOperatorType.IF || l.OperatorType == EOperatorType.ELIF || l.OperatorType == EOperatorType.ELSE || l.OperatorType == EOperatorType.WHILE); if (prevConditionLine != null && prevConditionLine.OperatorType == EOperatorType.WHILE) { currentState.CurrentLineID = prevConditionLine.ID; break; } else if (prevConditionLine != null) { currentLine = prevConditionLine; } else { return(ExitCurrentContext( DynLanContext, null)); } } } } return(false); } catch (Exception ex) { throw; } }
//////////////////////////////////////////// private DynLanProgram Compile(IList <Char> Code) { CodeLines lines = GetLines(Code); DynLanProgram mainProgram = new DynLanProgram() { ForceDecimals = ForceDecimals }; List <DynLanProgram> methodStack = new List <DynLanProgram>(); methodStack.Add(mainProgram); Int32 lineNr = 0; Int32 depth = 0; //foreach (CodeLine line in lines) for (var i = 0; i < lines.Count; i++) { CodeLine line = lines[i]; CodeLine nextLine = i < lines.Count - 1 ? lines[i + 1] : null; lineNr++; try { Int32 currentDepth = -1; #if !SPACES_FOR_DEPTH if (StringHelper.SequenceEqualInsensitive(line, DynLanuageSymbols.DepthBegin)) { depth++; continue; } else if (StringHelper.SequenceEqualInsensitive(line, DynLanuageSymbols.DepthEnd)) { depth--; continue; } currentDepth = depth; #endif DynLanMethod method = null; method = GetMethodDefinition(line, currentDepth); #if SPACES_FOR_DEPTH if (method != null) { currentDepth = method.Depth; } #else if (method != null) { if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("Method body should begin with bracket { !"); } else { depth++; currentDepth++; i++; } } #endif DynLanClass classDefinition = null; if (method == null) { classDefinition = GetClassDefinition(line, currentDepth); #if SPACES_FOR_DEPTH if (classDefinition != null) { currentDepth = classDefinition.Depth; } #else if (classDefinition != null) { if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("Class body should begin with bracket { !"); } else { depth++; currentDepth++; i++; } } #endif } DynLanCodeLine codeLine = null; if (method == null && classDefinition == null) { codeLine = SetCodeLine(null, line, nextLine, ref currentDepth, ref i); depth = currentDepth; #if SPACES_FOR_DEPTH if (codeLine != null) { currentDepth = codeLine.Depth; } #endif } DynLanProgram currentMethod = MyCollectionsExtenders.Peek(methodStack); if (codeLine == null || !codeLine.IsLineEmpty) { while (currentDepth < currentMethod.Depth || (currentDepth == currentMethod.Depth && classDefinition != null && classDefinition != currentMethod) || (currentDepth == currentMethod.Depth && method != null && method != currentMethod)) { MyCollectionsExtenders.Pop(methodStack); currentMethod = MyCollectionsExtenders.Peek(methodStack); } } if (method != null) { currentMethod.Methods.Remove_by_Name(method.Name); currentMethod.Methods.Add(method); methodStack.Add(method); continue; } if (classDefinition != null) { currentMethod.Classes.Remove_by_Name(classDefinition.Name); currentMethod.Classes.Add(classDefinition); methodStack.Add(classDefinition); continue; } if (codeLine != null) { if (codeLine.IsLineEmpty == false) { currentMethod.Lines.Add(codeLine); } } } catch (Exception ex) { throw new DynLanCompileException( "Line index: " + line.LineIndex + " (" + new string(line.ToArray()) + ")" + "; " + ex.Message, ex); } } for (var i = mainProgram.Lines.Count - 1; i >= 0; i--) { var line = mainProgram.Lines[i]; if (line.Depth > 0) { continue; } else if (line.OperatorType == EOperatorType.PASS) { continue; } else if (line.OperatorType == EOperatorType.RETURN) { break; } else if (line.OperatorType == EOperatorType.NONE) { line.OperatorType = EOperatorType.RETURN; break; } else { break; } } if (depth != 0) { throw new DynLanCompileException( "Incorect number of brackets. " + (depth > 0 ? ("Missing } x " + depth) : ("Too many } x " + Math.Abs(depth)))); } return(mainProgram); }
/*public DynLanCodeLine GetCodeLine(Int32 Depth, CodeLine line, CodeLine nextLine) * { * return SetCodeLine(null, Depth, line, nextLine); * }*/ /*public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, Int32 Depth, String line) * { * return SetCodeLine(compiledLine, Depth, new CodeLine(line)); * }*/ public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, CodeLine line, CodeLine nextLine, ref Int32 Depth, ref int CharIndex) { Int32 orgDepth = Depth; IList <Char> lineTrimmed = Linq2.ToArray( StringHelper.TrimStart( StringHelper.TrimEnd(line))); IList <Char> lineBody = line; EOperatorType operatorType = EOperatorType.NONE; // IF: wykrycie definicji IF'a if (//lineTrimmed.Count > str_if.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_if, true, true) /* && * Char.IsWhiteSpace(lineTrimmed[str_if.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.IF; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_if.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count == 0) { throw new Exception("IF body cannot be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("IF body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // WHILE: wykrycie definicji WHILE'a else if (//lineTrimmed.Count > str_while.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_while, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_while.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.WHILE; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_while.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count == 0) { throw new Exception("WHILE body cannot be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("WHILE body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // ELSE: wykrycie definicji ELSE'a else if (// lineTrimmed.Count >= str_else.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_else, true, true)) { Int32 depth = GetDepth(line); operatorType = EOperatorType.ELSE; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_else.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count > 0) { throw new Exception("ELSE body must be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("ELSE body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // ELIF: wykrycie definicji ELIF'a else if (// lineTrimmed.Count > str_elif.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_elif, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_elif.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.ELIF; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_elif.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count == 0) { throw new Exception("ELIF body cannot be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("ELIF body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // RETURN: wykrycie definicji RETURN'a else if (// lineTrimmed.Count > str_return.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_return, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_return.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.RETURN; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_return.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } // RETURN: wykrycie definicji RETURN'a /*else if (// lineTrimmed.Count >= str_return.Length && * StringHelper.StartsWith(lineTrimmed.TrimStart().ToArray(), str_return, true, true)) * { * Int32 depth = GetDepth(line); * operatorType = EOperatorType.RETURN; * * lineBody = lineTrimmed. * Substring2(str_return.Length). * TrimStart(). * ToList(); * #if SPACES_FOR_DEPTH * for (int i = 0; i < depth; i++) * lineBody.Insert(0, ' '); * // lineBody.TrimEnd(':'); #endif * }*/ // RETURN: wykrycie definicji PASS'a else if (//(lineTrimmed.Count == str_pass.Length || (lineTrimmed.Count > str_pass.Length && Char.IsWhiteSpace(lineTrimmed[str_pass.Length]))) StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_pass, true, true)) { Int32 depth = GetDepth(line); operatorType = EOperatorType.PASS; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_pass.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } // TRY: wykrycie definicji TRY'a else if (// lineTrimmed.Count > str_try.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_try, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_try.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.TRY; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_try.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("TRY body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // CATCH: wykrycie definicji CATCH'a else if (// lineTrimmed.Count > str_catch.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_catch, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_catch.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.CATCH; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_catch.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("CATCH body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // FINALLY: wykrycie definicji FINALLY'a else if (// lineTrimmed.Count > str_finally.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_finally, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_finally.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.FINALLY; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_finally.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("FINALLY body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // THROW: wykrycie definicji THROW'a else if (lineTrimmed.Count > str_throw.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_throw, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_THROW.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.THROW; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_throw.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } // BREAK: wykrycie definicji BREAK'a else if (// lineTrimmed.Count > str_break.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_break, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_break.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.BREAK; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_break.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } ExpressionGroup expressionGroup = TokenizerInvariant.I. Compile(lineBody); if (compiledLine == null) { compiledLine = new DynLanCodeLine(); } compiledLine.Code = StringHelper.ToString2(line); compiledLine.ExpressionGroup = expressionGroup; compiledLine.OperatorType = operatorType; compiledLine.IsLineEmpty = lineTrimmed.Count == 0; #if !SPACES_FOR_DEPTH compiledLine.Depth = orgDepth; #else compiledLine.Depth += GetDepth(lineBody); #endif return(compiledLine); }