static JSON() { var number = Terminal.Create("Number", (position, data) => ToDecimal(data), Join( Literal('-').Optional(), Literal('0').Or(OneOf("123456789").And(OneOf(PredefinedSets.Number).ZeroOrMore())), Literal('.').And(OneOf(PredefinedSets.Number).AtLeast(1)).Optional(), Join( OneOf("eE"), OneOf("+-").Optional(), OneOf(PredefinedSets.Number).AtLeast(1)).Optional())); var jsonString = Terminals.StringEx("/bfnrt", true, false, '"', "String"); var jsonObject = Nonterminal.Create <Json>("Object"); var jsonArray = Nonterminal.Create <Json>("Array"); var value = Nonterminal.Create("Value", jsonString.Finish(Json.NewString), number.AsIs(), jsonObject.AsIs(), jsonArray.AsIs(), "true".FinishConstant(Json.NewBool(true)), "false".FinishConstant(Json.NewBool(false)), "null".FinishConstant(Json.NewNull(null))); var arrayReversed = Nonterminal.Create <FSharpList <Json> >("Array Reversed"); arrayReversed.SetProductions( arrayReversed.Extended().Append(",").Extend(value).Finish((xs, x) => FSharpList <Json> .Cons(x, xs)), value.Finish(ListModule.Singleton)); var arrayOptional = Nonterminal.Create("Array Optional", arrayReversed.Finish(ListModule.Reverse), ProductionBuilder.Empty.FinishConstant(FSharpList <Json> .Empty)); jsonArray.SetProductions("[".Appended().Extend(arrayOptional).Append("]").Finish(Json.NewArray)); var objectElement = Nonterminal.Create <FSharpList <Tuple <string, Json> > >("Object Element"); objectElement.SetProductions( objectElement.Extended().Append(",").Extend(jsonString).Append(":").Extend(value) .Finish((xs, k, v) => FSharpList <Tuple <string, Json> > .Cons(Tuple.Create(k, v), xs)), jsonString.Extended().Append(":").Extend(value).Finish((k, v) => ListModule.Singleton(Tuple.Create(k, v)))); var objectOptional = Nonterminal.Create("Object Optional", objectElement.Finish(x => Json.NewObject(MapModule.OfList(x))), ProductionBuilder.Empty.FinishConstant(Json.NewObject(MapModule.Empty <string, Json>()))); jsonObject.SetProductions("{".Appended().Extend(objectOptional).Append("}").AsIs()); Designtime = value.CaseSensitive().UseDynamicCodeGen(); Runtime = Designtime.Build(); }
// Probably a bit goofy taking the 'add if missing' as a lambda, as the caller technically has the true value, which should match what he'd just put in here // Maybe to get rid of ambiguity the action should be ResourceHolder.Build... or something and just take it all private in here. internal void AddKeyRebuildingHeldResourceFromPassedInOnlyIfItSomehowWasMissing(TInterestedHoldingParty ask, Func <TResourceObject> getResourceObject) => InterestedHoldingPartyToResource.AddUnrepresentedKeyWithRecreateIfMissing(ask, () => ListModule.Singleton(getResourceObject()));
internal ResourceHolder( TResourceObject resource, KeyWeakSharedSoleItemContainer <TMechanicalResourceKey, Unit> allComponentMechanicalsThisResource) { InterestedHoldingPartyToResource = new KeyWeakSharedSoleItemContainer <TInterestedHoldingParty, FSharpList <TResourceObject> >(ListModule.Singleton(resource)); AllComponentMechanicalsThisResource = allComponentMechanicalsThisResource; }