IRule IGrammar.CreateRule(string id, RulePublic publicRule, RuleDynamic dynamic, bool hasScript) { SPCFGRULEATTRIBUTES sPCFGRULEATTRIBUTES = (SPCFGRULEATTRIBUTES)0; if (id == _sRoot) { sPCFGRULEATTRIBUTES |= (SPCFGRULEATTRIBUTES.SPRAF_TopLevel | SPCFGRULEATTRIBUTES.SPRAF_Active | SPCFGRULEATTRIBUTES.SPRAF_Root); _hasRoot = true; } if (publicRule == RulePublic.True) { sPCFGRULEATTRIBUTES |= (SPCFGRULEATTRIBUTES.SPRAF_TopLevel | SPCFGRULEATTRIBUTES.SPRAF_Export); } if (dynamic == RuleDynamic.True) { sPCFGRULEATTRIBUTES |= SPCFGRULEATTRIBUTES.SPRAF_Dynamic; } Rule rule = GetRule(id, sPCFGRULEATTRIBUTES); if (publicRule == RulePublic.True || id == _sRoot || hasScript) { _cg._rules.Add(rule); } return(rule); }
internal CfgRule(int id, int nameOffset, SPCFGRULEATTRIBUTES attributes) { _flag = 0u; _nameOffset = nameOffset; _id = id; TopLevel = ((attributes & SPCFGRULEATTRIBUTES.SPRAF_TopLevel) != 0); DefaultActive = ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Active) != 0); PropRule = ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Interpreter) != 0); Export = ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Export) != 0); Dynamic = ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Dynamic) != 0); Import = ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Import) != 0); }
internal Rule CreateRule(string name, SPCFGRULEATTRIBUTES attributes) { SPCFGRULEATTRIBUTES sPCFGRULEATTRIBUTES = SPCFGRULEATTRIBUTES.SPRAF_TopLevel | SPCFGRULEATTRIBUTES.SPRAF_Active | SPCFGRULEATTRIBUTES.SPRAF_Export | SPCFGRULEATTRIBUTES.SPRAF_Import | SPCFGRULEATTRIBUTES.SPRAF_Interpreter | SPCFGRULEATTRIBUTES.SPRAF_Dynamic | SPCFGRULEATTRIBUTES.SPRAF_Root; if (attributes != 0 && ((attributes & ~sPCFGRULEATTRIBUTES) != 0 || ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Import) != 0 && (attributes & SPCFGRULEATTRIBUTES.SPRAF_Export) != 0))) { throw new ArgumentException(SR.Get(SRID.InvalidFlagsSet), "attributes"); } if ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Import) != 0 && ((attributes & SPCFGRULEATTRIBUTES.SPRAF_TopLevel) != 0 || (attributes & SPCFGRULEATTRIBUTES.SPRAF_Active) != 0 || (attributes & SPCFGRULEATTRIBUTES.SPRAF_Root) != 0)) { attributes &= ~(SPCFGRULEATTRIBUTES.SPRAF_TopLevel | SPCFGRULEATTRIBUTES.SPRAF_Active | SPCFGRULEATTRIBUTES.SPRAF_Root); } if ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Import) != 0 && name[0] == '\0') { LogError(name, SRID.InvalidImport); } if (_fLoadedFromBinary) { foreach (Rule rule2 in _rules) { string b = _symbols[rule2._cfgRule._nameOffset]; if (!rule2._cfgRule.Dynamic && name == b) { LogError(name, SRID.DuplicatedRuleName); } } } int cImportedRules = 0; int idWord; Rule rule = new Rule(this, name, _symbols.Add(name, out idWord), attributes, _ruleIndex, 0, _grammarOptions & GrammarOptions.TagFormat, ref cImportedRules); rule._iSerialize2 = _ruleIndex++; if ((attributes & SPCFGRULEATTRIBUTES.SPRAF_Root) != 0) { if (_rootRule != null) { LogError(name, SRID.RootRuleAlreadyDefined); } else { _rootRule = rule; } } if (rule._cfgRule._nameOffset != 0) { _nameOffsetRules.Add(rule._cfgRule._nameOffset, rule); } _rules.Add(rule); _rules.Sort(); return(rule); }
internal void SetRuleAttributes(Rule rule, SPCFGRULEATTRIBUTES dwAttributes) { if ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_Root) != 0) { if (_rootRule != null) { XmlParser.ThrowSrgsException(SRID.RootRuleAlreadyDefined); } else { _rootRule = rule; } } rule._cfgRule.TopLevel = ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_TopLevel) != 0); rule._cfgRule.DefaultActive = ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_Active) != 0); rule._cfgRule.PropRule = ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_Interpreter) != 0); rule._cfgRule.Export = ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_Export) != 0); rule._cfgRule.Dynamic = ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_Dynamic) != 0); rule._cfgRule.Import = ((dwAttributes & SPCFGRULEATTRIBUTES.SPRAF_Import) != 0); }
IRule IGrammar.CreateRule(string id, RulePublic publicRule, RuleDynamic dynamic, bool hasScript) { SPCFGRULEATTRIBUTES dwRuleAttributes = 0; // Determine rule attributes to apply based on RuleScope, IsDynamic, and IsRootRule. // IsRootRule RuleScope IsDynamic Rule Attributes // ---------------------------------------------------------------------- // true * true Root | Active | TopLevel | Export | Dynamic // true * false Root | Active | TopLevel | Export // false internal true TopLevel | Export | Dynamic // false internal false TopLevel | Export // false private true Dynamic // false private false 0 if (id == _sRoot) { dwRuleAttributes |= SPCFGRULEATTRIBUTES.SPRAF_Root | SPCFGRULEATTRIBUTES.SPRAF_Active | SPCFGRULEATTRIBUTES.SPRAF_TopLevel; _hasRoot = true; } if (publicRule == RulePublic.True) { dwRuleAttributes |= SPCFGRULEATTRIBUTES.SPRAF_TopLevel | SPCFGRULEATTRIBUTES.SPRAF_Export; } if (dynamic == RuleDynamic.True) { // BackEnd supports exported dynamic rules for SRGS grammars. dwRuleAttributes |= SPCFGRULEATTRIBUTES.SPRAF_Dynamic; } // Create rule with specified attributes Rule rule = GetRule(id, dwRuleAttributes); // Add this rule to the list of rules of the STG list if (publicRule == RulePublic.True || id == _sRoot || hasScript) { _cg._rules.Add(rule); } return(rule); }
private Rule GetRule(string sRuleId, SPCFGRULEATTRIBUTES dwAttributes) { Rule rule = _backend.FindRule(sRuleId); if (rule != null) { int num = _undefRules.IndexOf(rule); if (num != -1) { _backend.SetRuleAttributes(rule, dwAttributes); _undefRules.RemoveAt(num); } else { XmlParser.ThrowSrgsException(SRID.RuleRedefinition, sRuleId); } } else { rule = _backend.CreateRule(sRuleId, dwAttributes); } return(rule); }
/// <summary> /// Create a new rule with the specified name and attribute, and return the initial state. /// Verify if Rule is unique. A Rule may already have been created as a placeholder during RuleRef. /// </summary> /// <param name="sRuleId">Rule name</param> /// <param name="dwAttributes">Rule attributes</param> private Rule GetRule(string sRuleId, SPCFGRULEATTRIBUTES dwAttributes) { System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(sRuleId)); // Check if RuleID is unique. Rule rule = _backend.FindRule(sRuleId); if (rule != null) { // Rule already defined. Check if it is a placeholder. int iRule = _undefRules.IndexOf(rule); if (iRule != -1) { // This is a UndefinedRule created as a placeholder for a RuleRef. // - Update placeholder rule with correct attributes. _backend.SetRuleAttributes(rule, dwAttributes); // - Remove this now defined rule from UndefinedRules. // Swap top element with this rule and pop the top element. _undefRules.RemoveAt(iRule); } else { // Multiple definitions of the same Rule. XmlParser.ThrowSrgsException(SRID.RuleRedefinition, sRuleId); // "Redefinition of rule ""%s""." } } else { // Rule not yet defined. Create a new rule and return the InitalState. rule = _backend.CreateRule(sRuleId, dwAttributes); } return(rule); }
internal Rule(Backend backend, string name, int offsetName, SPCFGRULEATTRIBUTES attributes, int id, int iSerialize, GrammarOptions SemanticFormat, ref int cImportedRules) : base(backend, null) { _rule = this; Init(name, new CfgRule(id, offsetName, attributes), iSerialize, SemanticFormat, ref cImportedRules); }