public void RunPhases(AstNode astRoot, CompilerContext context, params AstProcessingPhase[] phases) { IEnumerable<AstNode> allNodes = astRoot.GetAll(); foreach (AstProcessingPhase phase in phases) { foreach (AstNode node in allNodes) node.OnAstProcessing(context, phase); }//foreach phase }
//#region (private) GetCurrentCommandCategory(CurrentCommand) //private CLICommandCategory GetCurrentCommandCategory(string CurrentCommand) //{ // byte CommandSign; // CommandSign = (byte)Commands[CurrentCommand].aCategory; // if ((CommandSign & (byte)CLICommandCategory.FSCommand).CompareTo(1) >=0) // return CLICommandCategory.FSCommand; // else // if ((CommandSign & (byte)CLICommandCategory.DBCommand).CompareTo(1) >= 0) // return CLICommandCategory.DBCommand; // else // return CLICommandCategory.CLIStandardCommand; //}//method //#endregion #region (private) ExtractOptionsFromTree(_ExecutionTree) private void ExtractOptionsFromTree(AstNode _ExecutionTree) { List<AstNode> AllNodes = (List<AstNode>)_ExecutionTree.GetAll(); //get the command CurrentCommand = AllNodes[0].GetContent().Clone().ToString(); //get the category of the command //CommandCategory = GetCurrentCommandCategory(CurrentCommand); List<AstNode> ToBeDeleted = new List<AstNode>(); foreach (AstNode aAstNOde in AllNodes) { if (aAstNOde.Term.GraphOptions.Contains(GraphOption.IsStructuralObject) || aAstNOde.Term.GraphOptions.Contains(GraphOption.IsCommandRoot)) { ToBeDeleted.Add(aAstNOde); } } foreach (AstNode aElement in ToBeDeleted) { AllNodes.Remove(aElement); } //finally, remove first Element (the command) AddOptionToParameters(CreateNewOption(AllNodes[0].GetContent(), AllNodes[0].Span)); AllNodes.RemoveAt(0); bool _IsNewOption = false; bool _DidIEverDetectAnOption = false; foreach (AstNode aAstNOde in AllNodes) { if (aAstNOde.Term.GraphOptions.Contains(GraphOption.IsOption)) { //wohoo, new Option _IsNewOption = true; _DidIEverDetectAnOption = true; } else { if (_IsNewOption) { AddOptionToParameters(CreateNewOption(aAstNOde.GetContent(), aAstNOde.Span)); _IsNewOption = false; } else { if (!_DidIEverDetectAnOption) { //for one-line bnf-rules AddOptionToParameters(CreateNewOption(aAstNOde.GetContent(), aAstNOde.Span)); } else { int _ActualCountOfOptions = Parameters[CurrentOption.Option].Count; Parameters[CurrentOption.Option][_ActualCountOfOptions - 1].AddParameter(aAstNOde.GetContent()); } } } } }