protected LNode GenerateSetDecl(PGIntSet set, Symbol setName) { var ranges = set.InternalRangeList(); IEnumerable <object> args; Symbol method; if (ranges.Count * 2 < set.SizeIgnoringInversion) // use ranges { method = _NewSetOfRanges; args = ranges.SelectMany(r => { if (r.Lo >= 32 && r.Hi < 0xFFFC) { return new object[] { (char)r.Lo, (char)r.Hi } } ; else { return new object[] { r.Lo, r.Hi } }; }); } else { method = _NewSet; args = set.IntegerSequence(false).Select(n => set.IsCharSet && n >= 32 && n < 0xFFFC ? (object)(char)n : (object)(int)n); } return (F.Attr(F.Id(S.Static), F.Id(S.Readonly), F.Var(SetType, setName, ApiCall(method, new RVList <LNode>(args.Select(a => F.Literal(a))), true)))); }
public int?ExampleInt(PGIntSet set) { if (set.IsCharSet && set.IsInverted && set.Contains('_')) { return('_'); } if (set.ContainsEverything) { return(0); } if (set.IsEmptySet) { return(null); } int example = int.MinValue; int min = set.IsCharSet ? 32 : 0; foreach (var range in set.Runs()) { example = range.Lo < min ? range.Hi : range.Lo; if (example > min) { break; } } return(example); }
public override Pred CodeToPred(LNode expr, ref string errorMsg) { bool isInt = false; PGIntSet set; if (expr.IsIdNamed(_underscore)) { set = PGIntSet.AllExceptEOF; } else if (expr.IsIdNamed(_EOF)) { set = PGIntSet.EOF; } else if (expr.Calls(S.DotDot, 2)) { int?from = ConstValue(expr.Args[0], ref isInt); int?to = ConstValue(expr.Args[1], ref isInt); if (from == null || to == null) { errorMsg = "Expected int32 or character literal on each side of «..»"; return(null); } set = PGIntSet.WithRanges(from.Value, to.Value); } else if (expr.Value is string) { return(Pred.Seq((string)expr.Value)); } else { int?num = ConstValue(expr, ref isInt); if (num == null) { errorMsg = "Unrecognized expression. Expected int32 or character literal instead of: " + expr.ToString(); // warning return(null); } set = PGIntSet.With(num.Value); } set.IsCharSet = !isInt; return(new TerminalPred(expr, set, true)); }
public static TerminalPred Chars(params char[] c) { var set = PGIntSet.WithChars(c.Select(ch => (int)ch).ToArray()); return(new TerminalPred(null, set)); }
public static TerminalPred Set(string set) { return(Set(PGIntSet.Parse(set))); }
public int? ExampleInt(PGIntSet set) { if (set.IsCharSet && set.IsInverted && set.Contains('_')) return '_'; if (set.ContainsEverything) return 0; if (set.IsEmptySet) return null; int example = int.MinValue; int min = set.IsCharSet ? 32 : 0; foreach (var range in set.Runs()) { example = range.Lo < min ? range.Hi : range.Lo; if (example > min) break; } return example; }
protected LNode GenerateSetDecl(PGIntSet set, Symbol setName) { var ranges = set.InternalRangeList(); IEnumerable<object> args; Symbol method; if (ranges.Count * 2 < set.SizeIgnoringInversion) { // use ranges method = _NewSetOfRanges; args = ranges.SelectMany(r => { if (r.Lo >= 32 && r.Hi < 0xFFFC) return new object[] { (char)r.Lo, (char)r.Hi }; else return new object[] { r.Lo, r.Hi }; }); } else { method = _NewSet; args = set.IntegerSequence(false).Select(n => set.IsCharSet && n >= 32 && n < 0xFFFC ? (object)(char)n : (object)(int)n); } return F.Attr(F.Id(S.Static), F.Id(S.Readonly), F.Var(SetType, setName, ApiCall(method, new RVList<LNode>(args.Select(a => F.Literal(a))), true))); }