private Expression ParseComparisonOperationExpression( List <IToken> expression, ParsingContext context, TokenDetailTypes detailType, Func <Expression, Expression, BinaryExpression> comparisonExpression, ParseOperation parseOperation, out Type dataType) { List <List <IToken> > expressions = SplitIntoExpressions( expression, true, detailType); if (expressions.Count > 2) { throw new ParseException(expression, "Invalid comparison expression"); } else if (expressions.Count == 2) { var leftPart = parseOperation(expressions[0], context, out var leftSubType); var rightPart = parseOperation(expressions[1], context, out var rightSubType); if (leftSubType != rightSubType) { throw new ParseException(expression, "Data types on both sides of the equation do not align."); } dataType = typeof(bool); return(comparisonExpression(leftPart, rightPart)); } else { return(parseOperation(expression, context, out dataType)); } }
private Expression ParseMathOperationExpression( List <List <IToken> > expressions, ParsingContext context, Func <Expression, Expression, BinaryExpression> expressionDefinition, ParseOperation parseOperation, out Type dataType) { var expression = parseOperation(expressions.First(), context, out dataType); if (dataType != typeof(double)) { throw new ParseException(expressions.First(), "Expression is not a valid numerical expression."); } for (int i = 1; i < expressions.Count; i++) { var otherExpression = parseOperation(expressions[i], context, out var subDataType); if (subDataType != typeof(double)) { throw new ParseException(expressions.First(), "Expression is not a valid numerical expression."); } expression = expressionDefinition(expression, otherExpression); } return(expression); }
ParseOperation CreateParseOperation(ITextSnapshot2 snapshot) { var tokenSource = new CancellationTokenSource(); var task = StartParseAsync(snapshot, tokenSource.Token); var operation = new ParseOperation(this, task, snapshot, tokenSource); #pragma warning disable VSTHRD110, VSTHRD105 // Observe result of async calls, Avoid method overloads that assume TaskScheduler.Current //capture successful parses task.ContinueWith((t, state) => { var op = ((ParseOperation)state); op.Parser.lastSuccessfulOperation = op; try { op.Parser.OnParseCompleted(op.Result, op.Snapshot); } catch (Exception ex) { op.Parser.OnUnhandledParseError(ex); } }, operation, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); //handle errors task.ContinueWith((t, state) => { var op = ((ParseOperation)state); op.Parser.HandleUnhandledParseError(t.Exception); }, operation, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default); #pragma warning restore VSTHRD110, VSTHRD105 return(operation); }
private static BackgroundOperationResult OnInitializing(ParseOperation @this, Action <IBackgroundOperation> subOperationScheduler) { if (@this._owner._configParseHandlers.Count == 0) { return(BackgroundOperationResult.Completed); } @this._handlerIndex = 0; @this._state = OperationState.Starting; return(BackgroundOperationResult.NotCompleted); }
private static BackgroundOperationResult OnCompleting(ParseOperation @this, Action <IBackgroundOperation> subOperationScheduler) { @this._owner._configParseHandlers[@this._handlerIndex].OnCompleted(); if (++@this._handlerIndex < @this._owner._configParseHandlers.Count) { return(BackgroundOperationResult.NotCompleted); } @this._lines = null; return(BackgroundOperationResult.Completed); }
/// <summary> /// Get an existing completed or running parse task for the provided snapshot if available, or creates a new parse task. /// </summary> public Task <T> GetOrParseAsync(ITextSnapshot2 snapshot, CancellationToken token) { var current = currentOperation; if (current != null && current.Snapshot == snapshot && current.RegisterAdditionalCancellationOwner(token)) { return(current.Task); } currentOperation = current = CreateParseOperation(snapshot); return(current.Task); }
private static BackgroundOperationResult OnParsing(ParseOperation @this, Action <IBackgroundOperation> subOperationScheduler) { var parseLineOperation = @this._owner._parseLineOperationPool.Get(); parseLineOperation.Line = @this._lines[@this._lineIndex]; subOperationScheduler.Invoke(parseLineOperation); if (++@this._lineIndex >= @this._lines.Length) { @this._state = OperationState.Completing; } return(BackgroundOperationResult.NotCompleted); }
private static BackgroundOperationResult OnStarting(ParseOperation @this, Action <IBackgroundOperation> subOperationScheduler) { @this._owner._configParseHandlers[@this._handlerIndex].OnStarting(); if (++@this._handlerIndex >= @this._owner._configParseHandlers.Count) { @this._lines = @this._owner._programmableBlock.CustomData.Split(_lineSeparators, StringSplitOptions.RemoveEmptyEntries); @this._lineIndex = 0; @this._handlerIndex = 0; @this._state = (@this._lines.Length == 0) ? OperationState.Completing : OperationState.Parsing; } return(BackgroundOperationResult.NotCompleted); }
public IEnumerator LoadFromText(TextAsset text) { ParseOperation parseOp = new ParseOperation(text.text, saveSchema); loadScreen.BeginFileLoad(); yield return(new WaitUntil(() => parseOp.IsDone)); if (parseOp.data != null) { GameController.Instance.Load(parseOp.data); loadScreen.FinishFileLoad(); } else { loadScreen.LoadFailed(); } }