/// <summary> /// Add transition corresponding to Special or Uri. /// </summary> internal RuleRef(ParseElementCollection parent, Backend backend, Uri uri, List <Rule> undefRules, string semanticKey, string initParameters) : base(parent._rule) { string id = uri.OriginalString; Rule ruleRef = null; int posPound = id.IndexOf('#'); // Get the initial state for the RuleRef. if (posPound == 0) { // Internal RuleRef. Get InitialState of RuleRef. // GetRuleRef() may temporarily create a Rule placeholder for later resolution. ruleRef = GetRuleRef(backend, id.Substring(1), undefRules); } else { // External RuleRef. Build URL:GrammarUri#RuleName StringBuilder sbExternalRuleUri = new("URL:"); // Add the parameters to initialize a rule if (!string.IsNullOrEmpty(initParameters)) { // look for the # and insert the parameters sbExternalRuleUri.Append(posPound > 0 ? id.Substring(0, posPound) : id); sbExternalRuleUri.Append('>'); sbExternalRuleUri.Append(initParameters); if (posPound > 0) { sbExternalRuleUri.Append(id.Substring(posPound)); } } else { sbExternalRuleUri.Append(id); } // Get InitialState of external RuleRef. string sExternalRuleUri = sbExternalRuleUri.ToString(); ruleRef = backend.FindRule(sExternalRuleUri); if (ruleRef == null) { ruleRef = backend.CreateRule(sExternalRuleUri, SPCFGRULEATTRIBUTES.SPRAF_Import); } } Arc rulerefArc = backend.RuleTransition(ruleRef, _rule, 1.0f); #pragma warning disable 0618 if (!string.IsNullOrEmpty(semanticKey)) { CfgGrammar.CfgProperty propertyInfo = new(); propertyInfo._pszName = "SemanticKey"; propertyInfo._comValue = semanticKey; propertyInfo._comType = VarEnum.VT_EMPTY; backend.AddPropertyTag(rulerefArc, rulerefArc, propertyInfo); } #pragma warning restore 0618 parent.AddArc(rulerefArc); }
internal RuleRef(ParseElementCollection parent, Backend backend, Uri uri, List <Rule> undefRules, string semanticKey, string initParameters) : base(parent._rule) { string originalString = uri.OriginalString; Rule rule = null; int num = originalString.IndexOf('#'); if (num == 0) { rule = GetRuleRef(backend, originalString.Substring(1), undefRules); } else { StringBuilder stringBuilder = new StringBuilder("URL:"); if (!string.IsNullOrEmpty(initParameters)) { stringBuilder.Append((num > 0) ? originalString.Substring(0, num) : originalString); stringBuilder.Append('>'); stringBuilder.Append(initParameters); if (num > 0) { stringBuilder.Append(originalString.Substring(num)); } } else { stringBuilder.Append(originalString); } string text = stringBuilder.ToString(); rule = backend.FindRule(text); if (rule == null) { rule = backend.CreateRule(text, SPCFGRULEATTRIBUTES.SPRAF_Import); } } Arc arc = backend.RuleTransition(rule, _rule, 1f); if (!string.IsNullOrEmpty(semanticKey)) { backend.AddPropertyTag(arc, arc, new CfgGrammar.CfgProperty { _pszName = "SemanticKey", _comValue = semanticKey, _comType = VarEnum.VT_EMPTY }); } parent.AddArc(arc); }