public bool Equals(XbnfConcatExpression rhs) { if (ReferenceEquals(rhs, this)) { return(true); } if (ReferenceEquals(rhs, null)) { return(false); } return(Left == rhs.Left && Right == rhs.Right); }
public XbnfConcatExpression(XbnfExpression left, params XbnfExpression[] right) { Left = left; for (int i = 0; i < right.Length; i++) { var r = right[i]; if (null == Right) { Right = r; } var c = new XbnfConcatExpression(); c.Left = Left; c.Right = Right; Right = null; Left = c; } }
static IList <IList <string> > _GetDysConcat(XbnfDocument d, ICollection <string> syms, IDictionary <XbnfExpression, string> tmap, IDictionary <string, XbnfAttributeList> attrs, IList <KeyValuePair <string, IList <string> > > rules, XbnfProduction p, XbnfConcatExpression ce) { var l = new List <IList <string> >(); if (null == ce.Right) { if (null == ce.Left) { return(l); } foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Left)) { l.Add(new List <string>(ll)); } return(l); } else if (null == ce.Left) { foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Right)) { l.Add(new List <string>(ll)); } return(l); } foreach (var ll in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Left)) { foreach (var ll2 in _GetDysjunctions(d, syms, tmap, attrs, rules, p, ce.Right)) { var ll3 = new List <string>(); ll3.AddRange(ll); ll3.AddRange(ll2); if (!l.Contains(ll3, OrderedCollectionEqualityComparer <string> .Default)) { l.Add(ll3); } } } return(l); }
internal static XbnfExpression Parse(LexContext pc) { XbnfExpression current = null; XbnfExpression e; long position; int line; int column; pc.TrySkipCCommentsAndWhiteSpace(); position = pc.Position; line = pc.Line; column = pc.Column; while (-1 != pc.Current && ']' != pc.Current && ')' != pc.Current && '}' != pc.Current && ';' != pc.Current && ':' != pc.Current) { pc.TrySkipCCommentsAndWhiteSpace(); position = pc.Position; line = pc.Line; column = pc.Column; switch (pc.Current) { case '|': pc.Advance(); position = pc.Position; line = pc.Line; column = pc.Column; current = new XbnfOrExpression(current, Parse(pc)); current.SetLocation(line, column, position); break; case '(': pc.Advance(); position = pc.Position; line = pc.Line; column = pc.Column; e = Parse(pc); if (null != current) { current.SetLocation(line, column, position); } pc.Expecting(')'); pc.Advance(); e.SetLocation(line, column, position); if (null == current) { current = e; } else { current = new XbnfConcatExpression(current, e); } break; case '[': pc.Advance(); e = new XbnfOptionalExpression(Parse(pc)); e.SetLocation(line, column, position); pc.TrySkipCCommentsAndWhiteSpace(); pc.Expecting(']'); pc.Advance(); if (null == current) { current = e; } else { current = new XbnfConcatExpression(current, e); } break; case '{': pc.Advance(); e = new XbnfRepeatExpression(Parse(pc)); e.SetLocation(line, column, position); pc.TrySkipCCommentsAndWhiteSpace(); pc.Expecting('}'); pc.Advance(); if ('+' == pc.Current) { pc.Advance(); ((XbnfRepeatExpression)e).IsOptional = false; } if (null == current) { current = e; } else { current = new XbnfConcatExpression(current, e); } break; case '\"': e = new XbnfLiteralExpression(pc.ParseJsonString()); if (null == current) { current = e; } else { current = new XbnfConcatExpression(current, e); } e.SetLocation(line, column, position); break; case '\'': pc.Advance(); pc.ClearCapture(); pc.TryReadUntil('\'', '\\', false); pc.Expecting('\''); pc.Advance(); e = new XbnfRegexExpression(pc.GetCapture()); if (null == current) { current = e; } else { current = new XbnfConcatExpression(current, e); } e.SetLocation(line, column, position); break; case ';': case ']': case ')': case '}': case '=': case ':': return(current); default: e = new XbnfRefExpression(ParseIdentifier(pc)); if (null == current) { current = e; } else { current = new XbnfConcatExpression(current, e); } e.SetLocation(line, column, position); break; } } pc.TrySkipCCommentsAndWhiteSpace(); return(current); }