internal override IElement CreateElement(IElementFactory elementFactory, IElement parent, IRule rule, IdentifierCollection ruleIds) { Collection <RuleElement> newRules = new(); CalcCount(null); Optimize(newRules); foreach (GrammarBuilderBase baseRule in newRules) { Items.Add(baseRule); } // The id of the root rule string rootId = ruleIds.CreateNewIdentifier("root"); // Set the grammar's root rule elementFactory.Grammar.Root = rootId; elementFactory.Grammar.TagFormat = System.Speech.Recognition.SrgsGrammar.SrgsTagFormat.KeyValuePairs; // Create the root rule IRule root = elementFactory.Grammar.CreateRule(rootId, RulePublic.False, RuleDynamic.NotSet, false); // Create all the rules foreach (GrammarBuilderBase item in Items) { if (item is RuleElement) { item.CreateElement(elementFactory, root, root, ruleIds); } } // Create an item which represents the grammar foreach (GrammarBuilderBase item in Items) { if (!(item is RuleElement)) { IElement element = item.CreateElement(elementFactory, root, root, ruleIds); if (element != null) { element.PostParse(root); elementFactory.AddElement(root, element); } } } // Post parse the root rule root.PostParse(elementFactory.Grammar); elementFactory.Grammar.PostParse(null); return(null); }
internal override IElement CreateElement(IElementFactory elementFactory, IElement parent, IRule rule, IdentifierCollection ruleIds) { Collection <RuleElement> collection = new Collection <RuleElement>(); CalcCount(null); Optimize(collection); foreach (RuleElement item in collection) { base.Items.Add(item); } string text = ruleIds.CreateNewIdentifier("root"); elementFactory.Grammar.Root = text; elementFactory.Grammar.TagFormat = SrgsTagFormat.KeyValuePairs; IRule rule2 = elementFactory.Grammar.CreateRule(text, RulePublic.False, RuleDynamic.NotSet, false); foreach (GrammarBuilderBase item2 in base.Items) { if (item2 is RuleElement) { item2.CreateElement(elementFactory, rule2, rule2, ruleIds); } } foreach (GrammarBuilderBase item3 in base.Items) { if (!(item3 is RuleElement)) { IElement element = item3.CreateElement(elementFactory, rule2, rule2, ruleIds); if (element != null) { element.PostParse(rule2); elementFactory.AddElement(rule2, element); } } } rule2.PostParse(elementFactory.Grammar); elementFactory.Grammar.PostParse(null); return(null); }