private static RTree ParseStdGroup(RevgexStringReader inp, GroupSet groups) { string name = null; var id = -1; if (inp.Peek() == ':') { name = ParseGroupName(inp); } if (name != null) { if (!groups.Add(name)) { throw Error(inp, $"Group name {name} is already used."); } } else { groups.Add(id = groups.GetNextId()); } var body = ParseGroupBody(inp, groups); if (name != null) { groups.Specify(name, new RGroup(body)); return(new RNamedGroupRef(name, LookupQuantifier(inp))); } else { groups.Specify(id, new RGroup(body)); return(new RGroupRef(id, LookupQuantifier(inp))); } }
private static GroupSet Parse(RevgexStringReader inp, bool allowPredefinedGroups) { var groups = new GroupSet(); if (allowPredefinedGroups) { groups.Add(":maleName", PredefinedGroups.MaleName); groups.Add(":femaleName", PredefinedGroups.FemaleName); groups.Add(":surname", PredefinedGroups.Surname); groups.Add(":byte", PredefinedGroups.Byte); groups.Add(":int", PredefinedGroups.Int); groups.Add(":uint", PredefinedGroups.UnsignedInt); groups.Add(":usPhone", PredefinedGroups.USPhone); groups.Add(":mailSuffix", PredefinedGroups.MailSuffix); groups.Add(":passwd", PredefinedGroups.Password); } groups.Add(0); var alternatives = new List <List <RTree> > { new List <RTree>() }; while (inp.Peek() >= 0) { if (inp.Peek() == '|') { inp.Read(); alternatives.Add(new List <RTree>()); } else { alternatives[alternatives.Count - 1].Add(ParseSingleSubtree(inp, groups)); } } groups.Specify(0, alternatives.Count == 1 ? new RGroup(alternatives[0].ToArray()) : new RGroup(new RAlternation(alternatives.Select(a => new RGroup(a.ToArray())).ToArray()))); return(groups); }