public Parser <NamedTemplate> NamedTemplate() { return(Name().Bind( n => (Template(string.Empty) | (() => _p.Fail <Template>("template"))).Bind( t => End().BindIgnoringLeft( _p.Whitespace().BindIgnoringLeft( Parser.Return(new NamedTemplate(n, t))))))); }
private static Parser <Json> JsonRoot(ParsersBase p) { return(p.Whitespace().SkipL( () => JsonObject(p) | (() => JsonArray(p)) | (() => p.Fail <Json>("expected an object or an array")))); }
private static Parser <Parser <Row> > HeaderParser(ParsersBase p) { var dateParser1 = DateParser(p, false); var temperatureParser1 = TemperatureParser(p, true); var rowParser1 = p.Map2(dateParser1, () => temperatureParser1, Row.MakeRowFunc); var temperatureParser2 = TemperatureParser(p, false); var dateParser2 = DateParser(p, true); var rowParser2 = p.Map2(temperatureParser2, () => dateParser2, Flip(Row.MakeRowFunc)); var columnTitlesParser = ColumnTitlesParser(p); return(columnTitlesParser.Map(cols => { var colsList1 = cols.ToList(); if (colsList1.SequenceEqual(new[] { "Date", "Temperature" })) { return rowParser1; } if (colsList1.SequenceEqual(new[] { "Temperature", "Date" })) { return rowParser2; } return p.Fail <Row>(""); })); }
private static Parser <Json> JsonValue(ParsersBase p) { return (JsonLiteral(p) | (() => JsonArray(p)) | (() => JsonObject(p)) | (() => p.Fail <Json>("expected a literal or an array or an object"))); }
private static Parser <Json> JsonLiteral(ParsersBase p) { return(p.Scope( "literal", p.Token(p.String("null")).As(new JNull() as Json) | (() => p.Double().Map(n => new JNumber(n) as Json)) | (() => p.Token(p.Quoted()).Map(s => new JString(s) as Json)) | (() => p.Token(p.String("true")).As(new JBool(true) as Json)) | (() => p.Token(p.String("false")).As(new JBool(false) as Json))) | (() => p.Fail <Json>("expected a literal"))); }