public virtual void AddContextGetters(OutputModelFactory factory, ICollection<RuleAST> contextASTs)
{
IList<AltAST> unlabeledAlternatives = new List<AltAST>();
IDictionary<string, IList<AltAST>> labeledAlternatives = new Dictionary<string, IList<AltAST>>();
foreach (RuleAST ast in contextASTs)
{
try
{
foreach (var altAst in rule.g.GetUnlabeledAlternatives(ast))
unlabeledAlternatives.Add(altAst);
foreach (KeyValuePair<string, IList<System.Tuple<int, AltAST>>> entry in rule.g.GetLabeledAlternatives(ast))
{
IList<AltAST> list;
if (!labeledAlternatives.TryGetValue(entry.Key, out list))
{
list = new List<AltAST>();
labeledAlternatives[entry.Key] = list;
}
foreach (System.Tuple<int, AltAST> tuple in entry.Value)
{
list.Add(tuple.Item2);
}
}
}
catch (RecognitionException)
{
}
}
// Add ctx labels for elements in alts with no '#' label
if (unlabeledAlternatives.Count > 0)
{
ISet<Decl.Decl> decls = GetDeclsForAllElements(unlabeledAlternatives);
// put directly in base context
foreach (Decl.Decl decl in decls)
{
ruleCtx.AddDecl(decl);
}
}
// make structs for '#' labeled alts, define ctx labels for elements
altLabelCtxs = new Dictionary<string, AltLabelStructDecl>();
if (labeledAlternatives.Count > 0)
{
foreach (KeyValuePair<string, IList<AltAST>> entry in labeledAlternatives)
{
AltLabelStructDecl labelDecl = new AltLabelStructDecl(factory, rule, entry.Key);
altLabelCtxs[entry.Key] = labelDecl;
ISet<Decl.Decl> decls = GetDeclsForAllElements(entry.Value);
foreach (Decl.Decl decl in decls)
{
labelDecl.AddDecl(decl);
}
}
}
}