public void Execute(ExpressionBuilder builder) { var result = new List <ExoExpressionCommand>(); // treat a whole entry for (int j = 0; j < builder.expressions.Count; j++) { TreatSinglePage(builder.expressions[j]); } // treat a single line void TreatSinglePage(List <StructureExpr> page) { List <string> rawtokens = new List <string>(); for (int i = 0; i < page.Count; i++) { var current = page[i]; if (current.Mode == FilterExoConfig.StructurizerMode.comm) { continue; } if (i == 0) { if (current?.Value == null) { LoggingFacade.LogDebug("No VALUE on: " + current.ToString()); continue; } } rawtokens.Add(current.Value); } //var command = rawtokens.First(); //rawtokens.RemoveAt(0); var filterCommand = new ExoExpressionCommand(rawtokens); result.Add(filterCommand); } // Resolve rule into a "Show" filter entry. var newEntry = new ExoBlock(); newEntry.Parent = builder.Owner.WriteCursor; builder.Owner.WriteCursor.Scopes.Add(newEntry); foreach (var item in result) { newEntry.AddCommand(item); } }
public void SetParent(ExoBlock parent) { this.Parent = parent; }
public void Execute(ExpressionBuilder builder) { var properties = builder.Owner.ReadCursor.PropertyExpression; var functionName = properties[1]; var split = properties.SelectInnerContents( x => x.Value == "(", x => x.Value == ")"); List <string> varNames = new List <string>(); if (split != null) { var vars = split.SplitDivide(x => x.Value == ","); if (vars != null && vars.Count >= 1) { varNames = vars.Select(x => x.FirstOrDefault().Value).ToList(); } } var result = new List <ExoExpressionCommand>(); // treat a whole entry for (int j = 0; j < builder.expressions.Count; j++) { TreatSinglePage(builder.expressions[j]); } // treat a single line void TreatSinglePage(List <StructureExpr> page) { List <string> rawtokens = new List <string>(); for (int i = 0; i < page.Count; i++) { var current = page[i]; if (current.Mode == FilterExoConfig.StructurizerMode.comm) { continue; } if (i == 0) { if (current?.Value == null) { LoggingFacade.LogDebug("No VALUE on: " + current.ToString()); continue; } } rawtokens.Add(current.Value); } var filterCommand = new ExoExpressionCommand(rawtokens); result.Add(filterCommand); } var newEntry = new ExoBlock(); newEntry.Parent = builder.Owner.WriteCursor; // newEntry.Parent = builder.Owner.WriteCursor; //builder.Owner.WriteCursor.Scopes.Add(newEntry); foreach (var item in result) { newEntry.AddCommand(item); } // Resolve rule into a "Show" filter entry. var function = new ExoFunction { Name = functionName.Value, Content = newEntry, Variables = varNames }; builder.Owner.WriteCursor.Functions.Add(functionName.Value, new ExoAtom(function)); }
public ExoFilter Execute(StructureExpr tree) { var result = new ExoFilter(); // transformation process definition ReadCursor = tree.GoToRoot(); WriteCursor = new ExoBlock() { Type = FilterExoConfig.ExoFilterType.root }; // builder information var builder = new ExpressionBuilder(this); // call ProcessTreeStep(ReadCursor); result.RootEntry = WriteCursor; // LOCAL: process the tree void ProcessTreeStep(StructureExpr cursor) { foreach (var readChild in cursor.Children) { DoWorkOnReadChild(readChild); if (readChild.Children.Count > 0) { ProcessTreeStep(readChild); } } this.ReadCursor = cursor; PerformClosingScopeResolution(cursor); } void PerformClosingScopeResolution(StructureExpr cursor) { var success = builder.Execute(); if (cursor.IsSection()) { WriteCursor = WriteCursor.GetParent(); } if (success) { builder = new ExpressionBuilder(this); } } // LOCAL: Perform work on write branch, by reading current step void DoWorkOnReadChild(StructureExpr readChild) { if (readChild.Mode == FilterExoConfig.StructurizerMode.atom) { return; } // identify the line type if (readChild?.PrimitiveValue?.type == FilterExoConfig.TokenizerMode.comment) { // treat it as comment return; } // explicit scope handling if (readChild.ScopeType == FilterExoConfig.StructurizerScopeType.expl) { if (readChild.IsSection()) { var child = new ExoBlock(); child.Parent = this.WriteCursor; WriteCursor.Scopes.Add(child); WriteCursor = child; } return; } // implicit scope handling if (readChild.ScopeType == FilterExoConfig.StructurizerScopeType.impl) { builder.AddNewPage(); foreach (var item in readChild.Children) { if (item.Mode == FilterExoConfig.StructurizerMode.atom) { builder.AddKeyWord(item); } } } } return(result); }
public ExoExpressionCombineBuilder(ExoBlock parent) { this.ResolutionParent = parent; }