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 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 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 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); }