private IEnumerable <BfsNode> NextStates(BfsNode node) { return(node.Parser.AcceptableStructuralChars().Select(c => { var newJson = new StructuralChar[node.Json.Length + 1]; node.Json.CopyTo(newJson, 0); newJson[node.Json.Length] = c; return new BfsNode { Json = newJson, Parser = node.Parser.Read(c) }; })); }
public JsonParser Read(StructuralChar c) { if (_parsers.ContainsKey(c)) { var parser = _parsers[c](); AssignReturn(parser); return(parser); } if (CanComplete && Return != null) { return(Return.Read(c)); } throw new ArgumentException("Cannot read " + c); }
public static string AllRenderings(StructuralChar structuralChar) { return(structuralChar switch { StructuralChar.Whitespace => " ", StructuralChar.ArrayBegin => "[", StructuralChar.ArrayEnd => "]", StructuralChar.Comma => ",", StructuralChar.LeadingNegative => "-", StructuralChar.LeadingIntegerDigit => "123456789", StructuralChar.FollowingIntegerDigit => "0123456789", StructuralChar.DecimalSeparator => ".", StructuralChar.ScientificNotationSeparator => "eE", StructuralChar.ObjectBegin => "{", StructuralChar.ObjectEnd => "}", StructuralChar.KeyValueSeparator => ":", StructuralChar.StringDelimiter => "\"", StructuralChar.UnescapedStringBody => " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~", StructuralChar.StringEscapeMarker => "\\", StructuralChar.SingleEscapedChar => "\"\\/bfnrt", StructuralChar.UnicodeEscapedChar => "0123456789abcdefABCDEF", StructuralChar.UnicodeEscapeMarker => "u", StructuralChar.OnlyZero => "0", StructuralChar.NullOne => "n", StructuralChar.NullTwo => "u", StructuralChar.NullThree => "l", StructuralChar.NullFour => "l", StructuralChar.TrueOne => "t", StructuralChar.TrueTwo => "r", StructuralChar.TrueThree => "u", StructuralChar.TrueFour => "e", StructuralChar.FalseOne => "f", StructuralChar.FalseTwo => "a", StructuralChar.FalseThree => "l", StructuralChar.FalseFour => "s", StructuralChar.FalseFive => "e", _ => throw new ArgumentException("Unknown structural char") });
protected void NextChar(StructuralChar schar, Func <JsonParser> parser) { // var renderings = Structure.AllRenderings(schar); // NextChar(renderings, parser); _parsers[schar] = parser; }