public Symbol Reduce(ReductionContext context, Symbol s) { if (!(s is Identifier i)) { return(s); } if (_identifier != null && (i.Name != _identifier.Name || i.Tail.Count < _expectedArgsLength)) { return(s); } Symbol primarySymbol = ReduceImplementation(context, i); if (primarySymbol is null) { return(s); } return(_action switch { RestArgumentsAction.Ignore => primarySymbol, RestArgumentsAction.Reduce => primarySymbol.ReduceTail(i.Tail.Skip(_expectedArgsLength)), _ => throw new NotImplementedException() });
public Symbol Reduce(ReductionContext context, Symbol s) { if (!(s is Lambda lambda) || lambda.Tail.Count == 0) { return(s); } lambda.Body.Scope = new Scope(lambda.Scope, new[] { (lambda.ArgumentName, lambda.Tail[0]) });
protected override Symbol ReduceImplementation(ReductionContext context, Identifier identifier) { Symbol operandA = context.Reduce(identifier.Tail[0]), operandB = context.Reduce(identifier.Tail[1]); return(new Literal <bool>(operandA.Equals(operandB))); }
public Symbol Reduce(ReductionContext context, Symbol s) { if (!_hash.ContainsKey(s)) { _hash[s] = _reducer.Reduce(context, s); } return(_hash[s]); }
protected override Symbol ReduceImplementation(ReductionContext context, Identifier identifier) { Symbol reducedFirstSymbol = context.Reduce(identifier.Tail[0]); bool boolean = context.BooleanConverter.Convert(reducedFirstSymbol); return(boolean ? reducedFirstSymbol : identifier.Tail[1]); }
public Symbol Reduce(ReductionContext context, Symbol s) { if (!(s is Identifier i)) { return(s); } return(context.Scope[i.Name]?.ReduceTail(i.Tail) ?? s); }
protected override Symbol ReduceImplementation(ReductionContext context, Identifier identifier) { Symbol result = null; foreach (Symbol symbol in identifier.Tail) { result = context.Reduce(symbol); } return(result); }
public Symbol Reduce(ReductionContext context, Symbol s) { int hashCode = s.GetHashCode(); if (!_cache.ContainsKey(hashCode)) { _cache[hashCode] = _reducer.Reduce(context, s); } return(_cache[hashCode]); }
public Symbol Reduce(ReductionContext context, Symbol s) { if (!(s is Definition d) || d.Tail.Count == 0) { return(s); } context.Scope.Parent[d.Name] = d.Tail[0]; return(d.Tail[0].ReduceTail(d.Tail.Skip(1))); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (For == null) { throw new ArgumentNullException(ForAttributeName); } if (KeyName == null && !FromRow.HasValue) { throw new ArgumentNullException(KeyAttributeName); } var rc = context.GetFatherReductionContext(); if (rc.RowParsingDisabled) { output.TagName = string.Empty; output.Content.SetHtmlContent(string.Empty); return; } var nc = new ReductionContext(TagTokens.Row, 0, rc.Defaults); context.SetChildrenReductionContext(nc); await output.GetChildContentAsync(); RowType inherit = null; if (FromRow.HasValue) { var count = 0; foreach (var item in rc.Results) { if (item.Token == TagTokens.Row) { if (FromRow.Value == count) { inherit = item.Result as RowType; continue; } else { count++; } } } } var collector = new RowCollector(nc, FromRow); var res = collector.Process(this, rc.Defaults); if (res != null) { rc.Results.Add(new ReductionResult(TagTokens.Row, 0, res)); } output.TagName = string.Empty; output.Content.SetHtmlContent(string.Empty); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var rc = context.GetFatherReductionContext(); output.TagName = string.Empty; output.Content.SetHtmlContent(string.Empty); //get row definitions IList <RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ? null : RowType.GetRowsCollection(RowsCacheKey); IList <KeyValuePair <string, string> > toolbars = string.IsNullOrEmpty(RowsCacheKey) ? null : RowType.GetToolbarsCollection(RowsCacheKey); if (rows != null || toolbars != null) { return; } var currProvider = ViewContext.TagHelperProvider(); var defaultTemplates = currProvider.GetDefaultTemplates(TagHlperForDefaults); var nc = new ReductionContext(TagTokens.RowContainer, 0, defaultTemplates, rows != null); TagContextHelper.OpenRowContainerContext(contextAccessor.HttpContext); context.SetChildrenReductionContext(nc); await output.GetChildContentAsync(); var collector = new RowContainerCollector(nc); var res = collector.Process(this, defaultTemplates) as Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >; if (rows == null) { rows = res.Item1; if (!string.IsNullOrEmpty(RowsCacheKey)) { RowType.CacheRowGroup(RowsCacheKey, rows, contextAccessor.HttpContext, true); } } if (toolbars == null) { toolbars = res.Item2; if (!string.IsNullOrEmpty(RowsCacheKey)) { RowType.CacheToolbarGroup(RowsCacheKey, toolbars, contextAccessor.HttpContext, true); } } TagContextHelper.CloseRowContainerContext(contextAccessor.HttpContext, new Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >(rows, toolbars)); }
private static void Main() { Identifier point = I("Point"), x = I("x"), y = I("y"); var ctx = new ReductionContext( new BuiltInsReducer() ); using var game = new Plots(new[] { Func(x)[ Func(y)[ Add[Mul[x][x]][Mul[y][y]] ] ] }, ctx); game.Run(); }
public Symbol Reduce(ReductionContext context, Symbol s) { Symbol current = s; for (var i = 0; i < _reducers.Length; i++) { Symbol newSymbol = context.Reduce(current, _reducers[i]); if (newSymbol.Equals(current)) { continue; } i = -1; current = newSymbol; } return(current); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var rc = context.GetFatherReductionContext(); if (rc.RowParsingDisabled) { output.TagName = string.Empty; output.Content.SetHtmlContent(string.Empty); return; } var nc = new ReductionContext(TagTokens.Column, 0, rc.Defaults); context.SetChildrenReductionContext(nc); await output.GetChildContentAsync(); output.TagName = string.Empty; output.Content.SetHtmlContent(string.Empty); var collector = new ColumnCollector(nc); rc.Results.Add(new ReductionResult(TagTokens.Column, Remove ? -1 : 1, collector.Process(this, rc.Defaults))); }
protected override Symbol ReduceImplementation(ReductionContext context, Identifier identifier) { decimal GetOperand(int index) => context.NumbersConverter.Convert(context.Reduce(identifier.Tail[index])); Lazy <decimal> operandA = new Lazy <decimal>(() => GetOperand(0)), operandB = new Lazy <decimal>(() => GetOperand(1)); decimal?value = identifier.Name switch { nameof(Add) => (decimal?)operandA.Value + operandB.Value, nameof(Sub) => operandA.Value - operandB.Value, nameof(Mul) => operandA.Value * operandB.Value, nameof(Div) => operandA.Value / operandB.Value, _ => null }; return(value is null ? null : new Literal <decimal>(value.Value)); } }
public static void Main(string[] args) { var ctx = new ReductionContext( new BuiltInsReducer() ); Identifier n = I("n"), Fact = I("Fact"); Symbol res = ctx.Reduce( Let(Fact)[ Func(n)[ If[n][ Mul[n][ Fact[ ReduceFirst[Sub[n][1]] ] ] ][1] ] ][10] ); Console.WriteLine(res); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { //estabilish context if (For == null) { throw new ArgumentNullException(ForAttributeName); } if (RequiredFunctionalities == null) { if (Type == GridType.Immediate) { RequiredFunctionalities = (x) => Functionalities.FullDetail; } else { RequiredFunctionalities = (x) => Functionalities.FullInLine; } } string fullName = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(For.Name); string id = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement); var currProvider = ViewContext.TagHelperProvider(); var actTagName = TagName + (Type == GridType.Batch ? "-batch" : "-immediate"); var defaultTemplates = currProvider.GetDefaultTemplates(actTagName); var ctx = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory); // //estabilish context for children controls TagContextHelper.OpenBindingContext(httpAccessor.HttpContext, BindingContextNames.Collection, For); TagContextHelperAdvanced.OpenPermissionBindingContext(httpAccessor.HttpContext, new PermissionInfos { ClientUserPermissions = ClientRequiredFunctionalities, UserPermissions = RequiredFunctionalities }); if (QueryFor != null && QueryEnabled.HasValue && QueryEnabled.Value) { TagContextHelper.OpenBindingContext(httpAccessor.HttpContext, BindingContextNames.Query, QueryFor); TagContextHelper.OpenTypeBindingContext(httpAccessor.HttpContext, BindingContextNames.GroupingType, GroupingOutput ?? For.Metadata.ElementType); } //get row definitions IList <RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ? null : RowType.GetRowsCollection(RowsCacheKey); var nc = new ReductionContext(TagTokens.RowContainer, 0, defaultTemplates, rows != null); context.SetChildrenReductionContext(nc); TagContextHelper.OpenRowContainerContext(httpAccessor.HttpContext); await output.GetChildContentAsync(); var collector = new RowContainerCollector(nc); var res = collector.Process(this, defaultTemplates) as Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >; if (rows == null) { rows = res.Item1; if (!string.IsNullOrEmpty(RowsCacheKey)) { RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext); httpAccessor.HttpContext.Items["_request_cache_" + RowsCacheKey] = rows; } foreach (var row in rows) { if (row.ControllerType != null) { Action action = () => { ControllerHelpers.DeclareServerRowtype(row.ControllerType, row); }; CacheViewPartsFilter.AddAction(httpAccessor.HttpContext, action); } } } var toolbars = res.Item2; TagContextHelper.CloseRowContainerContext(httpAccessor.HttpContext, new Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >(rows, toolbars)); // //Prepare grid options var options = new GridOptions(rows, toolbars, Type, id, fullName) { CssClass = CssClass, ErrorMessages = ErrorMessages, ClientRowSelection = ClientRowSelection, ServerRowSelection = ServerRowSelection, LayoutTemplate = defaultTemplates.GetLayoutTemplate(LayoutTemplate), SubTemplates = defaultTemplates.GetLayoutParts(LayoutParts) }; //finally process! await currProvider.GetTagProcessor(actTagName)(context, output, this, options, ctx); if (QueryFor != null && QueryEnabled.HasValue && QueryEnabled.Value) { TagContextHelper.CloseTypeBindingContext(httpAccessor.HttpContext, BindingContextNames.GroupingType); TagContextHelper.CloseBindingContext(httpAccessor.HttpContext, BindingContextNames.Query); } TagContextHelperAdvanced.ClosePermissionBindingContext(httpAccessor.HttpContext); TagContextHelper.CloseBindingContext(httpAccessor.HttpContext, BindingContextNames.Collection); if (!ViewContext.FormContext.CanRenderAtEndOfForm) { TagContextHelper.CloseFormContext(httpAccessor.HttpContext, output); } }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { //estabilish context if (For == null) throw new ArgumentNullException(ForAttributeName); if (RequiredFunctionalities == null) { if(Type == GridType.Immediate) RequiredFunctionalities = (x) => Functionalities.FullDetail; else RequiredFunctionalities = (x) => Functionalities.FullInLine; } string fullName = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(For.Name); string id = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement); var currProvider = ViewContext.TagHelperProvider(); var actTagName = TagName + (Type == GridType.Batch ? "-batch" : "-immediate"); var defaultTemplates = currProvider.GetDefaultTemplates(actTagName); var ctx = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory); // //get row definitions IList<RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ? null : RowType.GetRowsCollection(RowsCacheKey); var nc = new ReductionContext(TagTokens.RowContainer, 0,defaultTemplates, rows != null); context.SetChildrenReductionContext(nc); await output.GetChildContentAsync(); var collector = new RowContainerCollector(nc); var res= collector.Process(this, defaultTemplates) as Tuple<IList<RowType>, IList<KeyValuePair<string, string>>>; if (rows == null) { rows = res.Item1; if (!string.IsNullOrEmpty(RowsCacheKey)) RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext); foreach(var row in rows) { if(row.ControllerType != null) { Action action = () => { ControllerHelpers.DeclareServerRowtype(row.ControllerType, row); }; CacheViewPartsFilter.AddAction(httpAccessor.HttpContext, action); } } } var toolbars = res.Item2; // //Prepare grid options var options = new GridOptions(rows, toolbars, Type, id, fullName) { CssClass=CssClass, ErrorMessages=ErrorMessages, ClientRowSelection=ClientRowSelection, ServerRowSelection=ServerRowSelection, LayoutTemplate=defaultTemplates.GetLayoutTemplate(LayoutTemplate), SubTemplates=defaultTemplates.GetLayoutParts(LayoutParts) }; //finally process! await currProvider.GetTagProcessor(actTagName)(context, output, this, options, ctx); }
protected override Symbol ReduceImplementation(ReductionContext context, Identifier identifier) => new Literal <IList <Symbol> >(identifier.Tail);
protected override Symbol ReduceImplementation(ReductionContext context, Identifier identifier) => identifier.Tail[0];