コード例 #1
0
ファイル: Program.cs プロジェクト: danslapman/PegExample
 static void Main(string[] args)
 {
     var parser = new Parser();
     var obj = parser.ParseAll(
     @"[
     {
     ""foo"" : null,
     ""array"" : [
     null,
     ""a"",
     ""b""
     ]
     },
     ""foo""
     ]");
     Console.WriteLine(obj);
     Console.ReadKey();
 }
コード例 #2
0
        private static Parser<object> GetObjectParser(Parser<string> stringParser, MainParser mainParser)
        {
            var memberParser =
                from name in stringParser
                from colon in Parse.Char(':').Token()
                from value in Parse.Ref(() => mainParser.Value)
                select new Member { Name = name, Value = value };

            var objectParser =
                from openBrace in Parse.Char('{').Token()
                from firstMember in memberParser.Optional()
                from otherMembers in
                    (from comma in Parse.Char(',').Token()
                     from member in memberParser
                     select member).Many()
                from closeBrace in Parse.Char('}').Token()
                select GetExpandoObject(firstMember, otherMembers);

            return objectParser;
        }