static IList <IList <string> > _GetDysRepeat(XbnfDocument d, ICollection <string> syms, IDictionary <XbnfExpression, string> tmap, IDictionary <string, XbnfAttributeList> attrs, IList <KeyValuePair <string, IList <string> > > rules, XbnfProduction p, XbnfRepeatExpression re) { string sid = null; var sr = re.Expression as XbnfRefExpression; if (null != d && null != sr) { sid = string.Concat(sr.Symbol, "List"); } if (string.IsNullOrEmpty(sid)) { var cc = re.Expression as XbnfConcatExpression; if (null != cc) { sr = cc.Right as XbnfRefExpression; if (null != sr) { sid = string.Concat(sr.Symbol, "ListTail"); } } } if (string.IsNullOrEmpty(sid)) { sid = string.Concat(p.Name, "List"); } var listId = sid; var i = 2; var ss = listId; while (syms.Contains(ss)) { ss = string.Concat(listId, i.ToString()); ++i; } syms.Add(ss); listId = ss; var attr = new XbnfAttribute("collapsed", true); var attr2 = new XbnfAttribute("nowarn", true); var attr3 = new XbnfAttribute("factored", true); var attrlist = new XbnfAttributeList(); attrlist.Add(attr); attrlist.Add(attr2); attrlist.Add(attr3); attrs.Add(listId, attrlist); var expr = new XbnfOrExpression( new XbnfConcatExpression( new XbnfRefExpression(listId), re.Expression), re.Expression);; foreach (var nt in _GetDysjunctions(d, syms, tmap, attrs, rules, p, expr)) { var l = new List <string>(); var r = new KeyValuePair <string, IList <string> >(listId, l); foreach (var s in nt) { if (1 < r.Value.Count && null == s) { continue; } r.Value.Add(s); } rules.Add(r); } if (!re.IsOptional) { return(new List <IList <string> >(new IList <string>[] { new List <string>(new string[] { listId }) })); } else { var res = new List <IList <string> >(); res.Add(new List <string>(new string[] { listId })); res.Add(new List <string>()); return(res); } }
internal static XbnfProduction Parse(LexContext pc) { var result = new XbnfProduction(); pc.TrySkipCCommentsAndWhiteSpace(); var l = pc.Line; var c = pc.Column; var p = pc.Position; // read identifier result.Name = ParseIdentifier(pc); // read attributes if ('<' == pc.Current) { pc.Advance(); while (-1 != pc.Current && '>' != pc.Current) { result.Attributes.Add(XbnfAttribute.Parse(pc)); pc.TrySkipCCommentsAndWhiteSpace(); pc.Expecting('>', ','); if (',' == pc.Current) { pc.Advance(); } } pc.Expecting('>'); pc.Advance(); } pc.TrySkipCCommentsAndWhiteSpace(); pc.Expecting('='); pc.Advance(); result.Expression = XbnfExpression.Parse(pc); pc.Expecting(';', '='); result.SetLocation(l, c, p); if (';' == pc.Current) { pc.Advance(); return(result); } if ('=' == pc.Current) { pc.Advance(); pc.Expecting('>'); pc.Advance(); pc.TrySkipCCommentsAndWhiteSpace(); pc.Expecting('{'); pc.Advance(); l = pc.Line; c = pc.Column; p = pc.Position; var s = XbnfDocument.ReadCode(pc); pc.Expecting('}'); pc.Advance(); result.Action = new XbnfCode(s); result.SetLocation(l, c, p); } return(result); }