/// <summary> /// Inherits the variables from the parent grammar /// </summary> /// <param name="parent">The parent's grammar</param> /// <param name="doClone">Clone the symbols</param> private void InheritVariables(Grammar parent, bool doClone) { foreach (Variable variable in parent.Variables) { if (doClone) { Variable clone = new Variable(variable.ID, variable.Name); variables.Add(clone.Name, clone); } else { AddVariable(variable.Name); } } foreach (Variable variable in parent.Variables) { Variable clone = variables[variable.Name]; foreach (Rule rule in variable.Rules) { List <RuleBodyElement> parts = new List <RuleBodyElement>(); for (int i = 0; i != rule.Body.Length; i++) { RuleBodyElement part = rule.Body[i]; Symbol symbol = null; if (part.Symbol is Variable) { symbol = variables[part.Symbol.Name]; } else if (part.Symbol is Terminal) { symbol = terminalsByName[part.Symbol.Name]; } else if (part.Symbol is Virtual) { symbol = virtuals[part.Symbol.Name]; } else if (part.Symbol is Action) { symbol = actions[part.Symbol.Name]; } parts.Add(new RuleBodyElement(symbol, part.Action)); } clone.AddRule(new Rule(clone, rule.HeadAction, new RuleBody(parts), ResolveContext(parent.contexts[rule.Context]))); } } }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="Hime.SDK.Grammars.RuleBodyElement"/>. /// </summary> /// <param name='obj'> /// The <see cref="System.Object"/> to compare with the current <see cref="Hime.SDK.Grammars.RuleBodyElement"/>. /// </param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to the current /// <see cref="Hime.SDK.Grammars.RuleBodyElement"/>; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { RuleBodyElement temp = obj as RuleBodyElement; return(temp != null && symbol.Equals(temp.symbol) && Action == temp.Action); }