コード例 #1
0
ファイル: TemplateRuleInstance.cs プロジェクト: sebgod/hime
        /// <summary>
        /// Initializes this template rule instance
        /// </summary>
        /// <param name="tRule">The parent template rule</param>
        /// <param name="parameters">The values for the template rule parameters</param>
        /// <param name="grammar">The parent grammar</param>
        public TemplateRuleInstance(TemplateRule tRule, List <Symbol> parameters, Grammar grammar)
        {
            // Build the head variable name
            StringBuilder builder = new StringBuilder();

            builder.Append(tRule.HeadName);
            builder.Append("<");
            for (int i = 0; i != parameters.Count; i++)
            {
                if (i != 0)
                {
                    builder.Append(", ");
                }
                builder.Append(parameters[i].Name);
            }
            builder.Append(">");
            string name = builder.ToString();

            // Create and add the variable to the grammar
            variable = grammar.AddVariable(name);
            // Copy parameters
            this.parameters = new List <Symbol>(parameters);
            // Set parent template rule
            templateRule = tRule;
        }
コード例 #2
0
        /// <summary>
        /// Adds the template rule to this grammar
        /// </summary>
        /// <param name="node">The rule's definition AST</param>
        /// <returns>The new template rule</returns>
        public TemplateRule AddTemplateRule(ASTNode node)
        {
            TemplateRule rule = new TemplateRule(this, node);

            templateRules.Add(rule);
            return(rule);
        }
コード例 #3
0
 /// <summary>
 /// Initializes this template rule as copy of another root
 /// </summary>
 /// <param name="copied">The copied template rule</param>
 /// <param name="grammar">The parent grammar</param>
 public TemplateRule(TemplateRule copied, Grammar grammar)
 {
     instances    = new List <TemplateRuleInstance>();
     this.grammar = grammar;
     head         = copied.head;
     parameters   = new List <string>(copied.parameters);
     root         = copied.root;
     foreach (TemplateRuleInstance instance in copied.instances)
     {
         List <Symbol> param = new List <Symbol>();
         foreach (Symbol symbol in instance.Parameters)
         {
             param.Add(grammar.GetSymbol(symbol.Name));
         }
         instances.Add(new TemplateRuleInstance(this, param, grammar));
     }
 }
コード例 #4
0
ファイル: LoaderContext.cs プロジェクト: sebgod/hime
 /// <summary>
 /// Adds a template rule to this context
 /// </summary>
 /// <param name="templateRule">A template rule</param>
 public void AddTemplateRule(TemplateRule templateRule)
 {
     templateRules.Add(templateRule);
 }