Skip to content

Instantly share code, notes, and snippets.

@cloudRoutine
Last active November 25, 2015 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudRoutine/36989187b894e7c8e47a to your computer and use it in GitHub Desktop.
Save cloudRoutine/36989187b894e7c8e47a to your computer and use it in GitHub Desktop.
Active Pattern VS Match When
let construct_toml (toplevel:(string*Value)list,
tables:(string*(string*Value)list)[]) =
let addSection (table:Dictionary<string,Value>) (kvps:(string*Value) list) =
kvps |> List.iter (fun (k,v)-> table.Add( keyName k,v ))
let foldtoml (prev:string, nested:string list, acc:Dictionary<string,Value>,toml:Dictionary<string,Value>)
(cur:string, elems:(string*Value)list) =
try
(* add parsed elements to current table *)
let emptyAccum toml = ("", [""],toml, toml)
let curtbl = makeTable [] in addSection curtbl elems
match prev,cur with
// when not at the root we connect prior node and push current forward
| IsRootOfPrev & NotAoT & AtTopLevel ->
let acc = connectToRoot cur curtbl prev acc nested
toml.Add (keyName cur, Value.Table acc)
emptyAccum toml
| IsRootOfPrev & NotAoT & NotAtTop ->
let acc = connectToRoot cur curtbl prev acc nested
(cur, getNested cur, acc, toml)
| IsRootOfPrev & AddToCurrentAoT & AtTopLevel ->
let curAoT = [connectToRoot cur curtbl prev acc nested]
toml.Add(keyName cur,Value.ArrayOfTables curAoT)
(cur, [""],toml, toml)
| IsRootOfPrev & AddToCurrentAoT & NotAtTop ->
let curAoT = [connectToRoot cur curtbl prev acc nested]
let pkey, parent = parentKey cur, makeTable[] in parent.Add(keyName cur,Value.ArrayOfTables curAoT)
(pkey, getNested pkey,parent, toml)
| DisjointSections & NotAoT & AtTopLevel ->
let toml = addToToplevel prev acc toml nested
toml.Add (keyName cur, Value.Table acc)
emptyAccum toml
| DisjointSections & NotAoT & NotAtTop ->
let toml = addToToplevel prev acc toml nested
(cur, getNested cur,curtbl, toml)
(* If we're creating a new AoT it's parent needs to be created to store it inside of *)
| DisjointSections & AddToCurrentAoT & AtTopLevel ->
let toml = addToToplevel prev acc toml nested
toml.Add(keyName cur,Value.ArrayOfTables [curtbl])
(prev, [""], toml , toml)
(* if we're at the toplevel and the prior insertion wasn't an Array of tables we can igore prev
since we're not an Array of Tables we don't need to carry anything over *)
| AddToPrevAoT & NotAtTop ->
consOnAoT cur curtbl acc
(cur, getNested cur, acc, toml)
| AddToPrevAoT & AtTopLevel ->
consOnAoT cur curtbl acc
(cur, getNested cur,acc, toml)
(* If all else fails, keep on trucking??? *)
| _, _ ->
printfn "kept on trucking\n cur is - %s" cur
printfn "\n Nested : %A " nested
( cur, nested, acc, toml)
with
| exn ->
printfn "caught exception - \n%s\n but fuck that noise keep rolling" exn.Message
printfn "\n Nested : %A " nested
( cur, nested, acc, toml)
let tables = tables |> Array.filter (fun (_,ls)-> ls<>[])
let initToml, acc = makeTable[], makeTable[]
let _,_,_,toml = Array.fold foldtoml (String.Empty,[""],acc,initToml) tables
addSection toml toplevel
---------------------------------------------------------------------------------------------------------
// TomlFs.Parsers
public static void construct_toml(FSharpList<Tuple<string, AST.Value>> toplevel, Tuple<string, FSharpList<Tuple<string, AST.Value>>>[] tables)
{
FSharpFunc<Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>, FSharpFunc<Tuple<string, FSharpList<Tuple<string, AST.Value>>>, Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>>> foldtoml = new Parsers.foldtoml@449();
Tuple<string, FSharpList<Tuple<string, AST.Value>>>[] tables2 = ArrayModule.Filter<Tuple<string, FSharpList<Tuple<string, AST.Value>>>>(new Parsers.tables@522(), tables);
FSharpList<Tuple<string, AST.Value>> empty = FSharpList<Tuple<string, AST.Value>>.Empty;
Dictionary<string, AST.Value> dictionary = new Dictionary<string, AST.Value>();
AST.Dictionary`2.AddSeq<string, AST.Value>(dictionary, (IEnumerable<Tuple<string, AST.Value>>)empty);
Dictionary<string, AST.Value> item = dictionary;
empty = FSharpList<Tuple<string, AST.Value>>.Empty;
Dictionary<string, AST.Value> dictionary2 = new Dictionary<string, AST.Value>();
AST.Dictionary`2.AddSeq<string, AST.Value>(dictionary2, (IEnumerable<Tuple<string, AST.Value>>)empty);
dictionary = dictionary2;
Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>> tuple = ArrayModule.Fold<Tuple<string, FSharpList<Tuple<string, AST.Value>>>, Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>>(foldtoml, new Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>(string.Empty, FSharpList<string>.Cons("", FSharpList<string>.Empty), dictionary, item), tables2);
Parsers.addSection@428(tuple.Item4, toplevel);
}
--------------------------------------------------------------------------------------------------------------
.method public static
void construct_toml (
class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>> toplevel,
class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>[] tables
) cil managed
{
// Method begins at RVA 0x5e40
// Code size 132 (0x84)
.maxstack 7
.locals init (
[0] class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>, class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>>> foldtoml,
[1] class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>[] tables,
[2] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[3] class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>,
[4] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[5] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[6] class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>
)
IL_0000: nop
IL_0001: newobj instance void TomlFs.Parsers/foldtoml@449::.ctor()
IL_0006: stloc.0
IL_0007: newobj instance void TomlFs.Parsers/tables@522::.ctor()
IL_000c: ldarg.1
IL_000d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Filter<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0, bool>, !!0[])
IL_0012: stloc.1
IL_0013: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>::get_Empty()
IL_0018: stloc.3
IL_0019: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>::.ctor()
IL_001e: stloc.s 4
IL_0020: ldloc.s 4
IL_0022: ldloc.3
IL_0023: unbox.any class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>
IL_0028: call void TomlFs.AST::Dictionary`2.AddSeq<string, class TomlFs.AST/Value>(class [mscorlib]System.Collections.Generic.Dictionary`2<!!0, !!1>, class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<!!0, !!1>>)
IL_002d: nop
IL_002e: ldloc.s 4
IL_0030: stloc.2
IL_0031: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>::get_Empty()
IL_0036: stloc.3
IL_0037: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>::.ctor()
IL_003c: stloc.s 5
IL_003e: ldloc.s 5
IL_0040: ldloc.3
IL_0041: unbox.any class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>
IL_0046: call void TomlFs.AST::Dictionary`2.AddSeq<string, class TomlFs.AST/Value>(class [mscorlib]System.Collections.Generic.Dictionary`2<!!0, !!1>, class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<!!0, !!1>>)
IL_004b: nop
IL_004c: ldloc.s 5
IL_004e: stloc.s 4
IL_0050: ldloc.0
IL_0051: ldsfld string [mscorlib]System.String::Empty
IL_0056: ldstr ""
IL_005b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>::get_Empty()
IL_0060: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0>)
IL_0065: ldloc.s 4
IL_0067: ldloc.2
IL_0068: newobj instance void class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>::.ctor(!0, !1, !2, !3)
IL_006d: ldloc.1
IL_006e: call !!1 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Fold<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>, class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!1, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0, !!1>>, !!1, !!0[])
IL_0073: stloc.s 6
IL_0075: ldloc.s 6
IL_0077: call instance !3 class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>::get_Item4()
IL_007c: ldarg.0
IL_007d: call void TomlFs.Parsers::addSection@428(class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>)
IL_0082: nop
IL_0083: ret
} // end of method Parsers::construct_toml
let construct_toml_when (toplevel:(string*Value)list,
tables:(string*(string*Value)list)[]) =
let addSection (table:Dictionary<string,Value>) (kvps:(string*Value) list) =
kvps |> List.iter (fun (k,v)-> table.Add( keyName k,v ))
let foldtoml (prev:string, nested:string list, acc:Dictionary<string,Value>,toml:Dictionary<string,Value>)
(cur:string, elems:(string*Value)list) =
try
(* add parsed elements to current table *)
let emptyAccum toml = ("", [""],toml, toml)
let curtbl = makeTable [] in addSection curtbl elems
match prev,cur with
// when not at the root we connect prior node and push current forward
| prev,cur when (isRootOfPrev|&|(isAoT>>(=)notAoT)|&|isAtTopLevel)(prev,cur) ->
let acc = connectToRoot cur curtbl prev acc nested
toml.Add (keyName cur, Value.Table acc)
emptyAccum toml
| prev,cur when (isRootOfPrev|&|(isAoT>>(=)notAoT)|&|(not<<isAtTopLevel))(prev,cur) ->
let acc = connectToRoot cur curtbl prev acc nested
(cur, getNested cur, acc, toml)
| prev,cur when (isRootOfPrev|&|(isAoT>>(=)addToCurrentAoT)|&|isAtTopLevel)(prev,cur) ->
let curAoT = [connectToRoot cur curtbl prev acc nested]
toml.Add(keyName cur,Value.ArrayOfTables curAoT)
(cur, [""],toml, toml)
| prev,cur when (isRootOfPrev|&|(isAoT>>(=)addToCurrentAoT)|&|(not<<isAtTopLevel))(prev,cur) ->
let curAoT = [connectToRoot cur curtbl prev acc nested]
let pkey, parent = parentKey cur, makeTable[] in parent.Add(keyName cur,Value.ArrayOfTables curAoT)
(pkey, getNested pkey,parent, toml)
| prev,cur when ((not<<isRootOfPrev)|&|(isAoT>>(=)notAoT)|&|isAtTopLevel)(prev,cur) ->
let toml = addToToplevel prev acc toml nested
toml.Add (keyName cur, Value.Table acc)
emptyAccum toml
| prev,cur when ((not<<isRootOfPrev)|&|(isAoT>>(=)notAoT)|&|(not<<isAtTopLevel))(prev,cur) ->
let toml = addToToplevel prev acc toml nested
(cur, getNested cur,curtbl, toml)
(* If we're creating a new AoT it's parent needs to be created to store it inside of *)
| prev,cur when ((not<<isRootOfPrev)|&|(isAoT>>(=)addToCurrentAoT)|&|isAtTopLevel)(prev,cur) ->
let toml = addToToplevel prev acc toml nested
toml.Add(keyName cur,Value.ArrayOfTables [curtbl])
(prev, [""], toml , toml)
(* if we're at the toplevel and the prior insertion wasn't an Array of tables we can igore prev
since we're not an Array of Tables we don't need to carry anything over *)
| prev,cur when ((isAoT>>(=)addToPrevAoT)|&|(not<<isAtTopLevel))(prev,cur) ->
consOnAoT cur curtbl acc; (cur, getNested cur, acc, toml)
| prev,cur when ((isAoT>>(=)addToPrevAoT)|&|isAtTopLevel)(prev,cur) ->
consOnAoT cur curtbl acc; (cur, getNested cur,acc, toml)
(* If all else fails, keep on trucking??? *)
| _, _ ->
printfn "kept on trucking\n cur is - %s" cur
printfn "\n Nested : %A " nested
( cur, nested, acc, toml)
with
| exn ->
printfn "caught exception - \n%s\n but fuck that noise keep rolling" exn.Message
printfn "\n Nested : %A " nested
( cur, nested, acc, toml)
let tables = tables |> Array.filter (fun (_,ls)-> ls<>[])
let initToml, acc = makeTable[], makeTable[]
let _,_,_,toml = Array.fold foldtoml (String.Empty,[""],acc,initToml) tables
addSection toml toplevel
---------------------------------------------------------------------------------------------------------
// TomlFs.Parsers
public static Dictionary<string, AST.Value> construct_toml_when(FSharpList<Tuple<string, AST.Value>> toplevel, Tuple<string, FSharpList<Tuple<string, AST.Value>>>[] tables)
{
FSharpFunc<Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>, FSharpFunc<Tuple<string, FSharpList<Tuple<string, AST.Value>>>, Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>>> foldtoml = new Parsers.foldtoml@547-38();
Tuple<string, FSharpList<Tuple<string, AST.Value>>>[] tables2 = ArrayModule.Filter<Tuple<string, FSharpList<Tuple<string, AST.Value>>>>(new Parsers.tables@609-1(), tables);
FSharpList<Tuple<string, AST.Value>> empty = FSharpList<Tuple<string, AST.Value>>.Empty;
Dictionary<string, AST.Value> dictionary = new Dictionary<string, AST.Value>();
AST.Dictionary`2.AddSeq<string, AST.Value>(dictionary, (IEnumerable<Tuple<string, AST.Value>>)empty);
Dictionary<string, AST.Value> item = dictionary;
empty = FSharpList<Tuple<string, AST.Value>>.Empty;
Dictionary<string, AST.Value> toml = new Dictionary<string, AST.Value>();
AST.Dictionary`2.AddSeq<string, AST.Value>(toml, (IEnumerable<Tuple<string, AST.Value>>)empty);
dictionary = toml;
Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>> tuple = ArrayModule.Fold<Tuple<string, FSharpList<Tuple<string, AST.Value>>>, Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>>(foldtoml, new Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>(string.Empty, FSharpList<string>.Cons("", FSharpList<string>.Empty), dictionary, item), tables2);
toml = tuple.Item4;
Parsers.addSection@530-4(toml, toplevel);
return toml;
}
--------------------------------------------------------------------------------------------------------------
.method public static
class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value> construct_toml_when (
class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>> toplevel,
class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>[] tables
) cil managed
{
// Method begins at RVA 0x8ebc
// Code size 138 (0x8a)
.maxstack 7
.locals init (
[0] class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>, class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>>> foldtoml,
[1] class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>[] tables,
[2] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[3] class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>,
[4] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[5] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value> toml,
[6] class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>
)
IL_0000: nop
IL_0001: newobj instance void TomlFs.Parsers/'foldtoml@547-38'::.ctor()
IL_0006: stloc.0
IL_0007: newobj instance void TomlFs.Parsers/'tables@609-1'::.ctor()
IL_000c: ldarg.1
IL_000d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Filter<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0, bool>, !!0[])
IL_0012: stloc.1
IL_0013: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>::get_Empty()
IL_0018: stloc.3
IL_0019: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>::.ctor()
IL_001e: stloc.s 4
IL_0020: ldloc.s 4
IL_0022: ldloc.3
IL_0023: unbox.any class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>
IL_0028: call void TomlFs.AST::Dictionary`2.AddSeq<string, class TomlFs.AST/Value>(class [mscorlib]System.Collections.Generic.Dictionary`2<!!0, !!1>, class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<!!0, !!1>>)
IL_002d: nop
IL_002e: ldloc.s 4
IL_0030: stloc.2
IL_0031: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>::get_Empty()
IL_0036: stloc.3
IL_0037: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>::.ctor()
IL_003c: stloc.s toml
IL_003e: ldloc.s toml
IL_0040: ldloc.3
IL_0041: unbox.any class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>
IL_0046: call void TomlFs.AST::Dictionary`2.AddSeq<string, class TomlFs.AST/Value>(class [mscorlib]System.Collections.Generic.Dictionary`2<!!0, !!1>, class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<!!0, !!1>>)
IL_004b: nop
IL_004c: ldloc.s toml
IL_004e: stloc.s 4
IL_0050: ldloc.0
IL_0051: ldsfld string [mscorlib]System.String::Empty
IL_0056: ldstr ""
IL_005b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>::get_Empty()
IL_0060: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0>)
IL_0065: ldloc.s 4
IL_0067: ldloc.2
IL_0068: newobj instance void class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>::.ctor(!0, !1, !2, !3)
IL_006d: ldloc.1
IL_006e: call !!1 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Fold<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>, class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!1, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0, !!1>>, !!1, !!0[])
IL_0073: stloc.s 6
IL_0075: ldloc.s 6
IL_0077: call instance !3 class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>::get_Item4()
IL_007c: stloc.s toml
IL_007e: ldloc.s toml
IL_0080: ldarg.0
IL_0081: call void TomlFs.Parsers::'addSection@530-4'(class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>)
IL_0086: nop
IL_0087: ldloc.s toml
IL_0089: ret
} // end of method Parsers::construct_toml_when
let construct_toml_when_no_lambda (toplevel:(string*Value)list,
tables:(string*(string*Value)list)[]) =
let addSection (table:Dictionary<string,Value>) (kvps:(string*Value) list) =
kvps |> List.iter (fun (k,v)-> table.Add( keyName k,v ))
let foldtoml (prev:string, nested:string list, acc:Dictionary<string,Value>,toml:Dictionary<string,Value>)
(cur:string, elems:(string*Value)list) =
try
(* add parsed elements to current table *)
let emptyAccum toml = ("", [""],toml, toml)
let curtbl = makeTable [] in addSection curtbl elems
match prev,cur with
// when not at the root we connect prior node and push current forward
| prev,cur when isRootOfPrev (prev,cur) && isAoT (prev,cur) = notAoT && isAtTopLevel (prev,cur) ->
let acc = connectToRoot cur curtbl prev acc nested
toml.Add (keyName cur, Value.Table acc)
emptyAccum toml
| prev,cur when isRootOfPrev (prev,cur) && isAoT (prev,cur) = notAoT && (not<<isAtTopLevel)(prev,cur) ->
let acc = connectToRoot cur curtbl prev acc nested
(cur, getNested cur, acc, toml)
| prev,cur when isRootOfPrev(prev,cur)&&isAoT (prev,cur) = addToCurrentAoT&&isAtTopLevel(prev,cur) ->
let curAoT = [connectToRoot cur curtbl prev acc nested]
toml.Add(keyName cur,Value.ArrayOfTables curAoT)
(cur, [""],toml, toml)
| prev,cur when isRootOfPrev(prev,cur)&&(isAoT (prev,cur) = addToCurrentAoT)&&(not<<isAtTopLevel)(prev,cur) ->
let curAoT = [connectToRoot cur curtbl prev acc nested]
let pkey, parent = parentKey cur, makeTable[] in parent.Add(keyName cur,Value.ArrayOfTables curAoT)
(pkey, getNested pkey,parent, toml)
| prev,cur when (not<<isRootOfPrev)(prev,cur)&&(isAoT (prev,cur) = notAoT)&&isAtTopLevel(prev,cur) ->
let toml = addToToplevel prev acc toml nested
toml.Add (keyName cur, Value.Table acc)
emptyAccum toml
| prev,cur when (not<<isRootOfPrev)(prev,cur)&&(isAoT (prev,cur) = notAoT)&&(not<<isAtTopLevel)(prev,cur) ->
let toml = addToToplevel prev acc toml nested
(cur, getNested cur,curtbl, toml)
(* If we're creating a new AoT it's parent needs to be created to store it inside of *)
| prev,cur when (not<<isRootOfPrev)(prev,cur)&&(isAoT (prev,cur) = addToCurrentAoT)&&isAtTopLevel(prev,cur) ->
let toml = addToToplevel prev acc toml nested
toml.Add(keyName cur,Value.ArrayOfTables [curtbl])
(prev, [""], toml , toml)
(* if we're at the toplevel and the prior insertion wasn't an Array of tables we can igore prev
since we're not an Array of Tables we don't need to carry anything over *)
| prev,cur when (isAoT (prev,cur) = addToPrevAoT)&&(not<<isAtTopLevel)(prev,cur) ->
consOnAoT cur curtbl acc; (cur, getNested cur, acc, toml)
| prev,cur when (isAoT (prev,cur) = addToPrevAoT)&&isAtTopLevel(prev,cur) ->
consOnAoT cur curtbl acc; (cur, getNested cur,acc, toml)
(* If all else fails, keep on trucking??? *)
| _, _ ->
printfn "kept on trucking\n cur is - %s" cur
printfn "\n Nested : %A " nested
( cur, nested, acc, toml)
with
| exn ->
printfn "caught exception - \n%s\n but fuck that noise keep rolling" exn.Message
printfn "\n Nested : %A " nested
( cur, nested, acc, toml)
let tables = tables |> Array.filter (fun (_,ls)-> ls<>[])
let initToml, acc = makeTable[], makeTable[]
let _,_,_,toml = Array.fold foldtoml (String.Empty,[""],acc,initToml) tables
addSection toml toplevel
---------------------------------------------------------------------------------------------------------
// TomlFs.Parsers
public static Dictionary<string, AST.Value> construct_toml_when_no_lambda(FSharpList<Tuple<string, AST.Value>> toplevel, Tuple<string, FSharpList<Tuple<string, AST.Value>>>[] tables)
{
FSharpFunc<Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>, FSharpFunc<Tuple<string, FSharpList<Tuple<string, AST.Value>>>, Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>>> foldtoml = new Parsers.foldtoml@600-63();
Tuple<string, FSharpList<Tuple<string, AST.Value>>>[] tables2 = ArrayModule.Filter<Tuple<string, FSharpList<Tuple<string, AST.Value>>>>(new Parsers.tables@662-2(), tables);
FSharpList<Tuple<string, AST.Value>> empty = FSharpList<Tuple<string, AST.Value>>.Empty;
Dictionary<string, AST.Value> dictionary = new Dictionary<string, AST.Value>();
AST.Dictionary`2.AddSeq<string, AST.Value>(dictionary, (IEnumerable<Tuple<string, AST.Value>>)empty);
Dictionary<string, AST.Value> item = dictionary;
empty = FSharpList<Tuple<string, AST.Value>>.Empty;
Dictionary<string, AST.Value> toml = new Dictionary<string, AST.Value>();
AST.Dictionary`2.AddSeq<string, AST.Value>(toml, (IEnumerable<Tuple<string, AST.Value>>)empty);
dictionary = toml;
Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>> tuple = ArrayModule.Fold<Tuple<string, FSharpList<Tuple<string, AST.Value>>>, Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>>(foldtoml, new Tuple<string, FSharpList<string>, Dictionary<string, AST.Value>, Dictionary<string, AST.Value>>(string.Empty, FSharpList<string>.Cons("", FSharpList<string>.Empty), dictionary, item), tables2);
toml = tuple.Item4;
Parsers.addSection@593-8(toml, toplevel);
return toml;
}
-------------------------------------------------------------------------------------------------------------
.method public static
class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value> construct_toml_when_no_lambda (
class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>> toplevel,
class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>[] tables
) cil managed
{
// Method begins at RVA 0xbcdc
// Code size 138 (0x8a)
.maxstack 7
.locals init (
[0] class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>, class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>>> foldtoml,
[1] class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>[] tables,
[2] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[3] class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>,
[4] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>,
[5] class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value> toml,
[6] class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>
)
IL_0000: nop
IL_0001: newobj instance void TomlFs.Parsers/'foldtoml@600-63'::.ctor()
IL_0006: stloc.0
IL_0007: newobj instance void TomlFs.Parsers/'tables@662-2'::.ctor()
IL_000c: ldarg.1
IL_000d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Filter<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0, bool>, !!0[])
IL_0012: stloc.1
IL_0013: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>::get_Empty()
IL_0018: stloc.3
IL_0019: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>::.ctor()
IL_001e: stloc.s 4
IL_0020: ldloc.s 4
IL_0022: ldloc.3
IL_0023: unbox.any class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>
IL_0028: call void TomlFs.AST::Dictionary`2.AddSeq<string, class TomlFs.AST/Value>(class [mscorlib]System.Collections.Generic.Dictionary`2<!!0, !!1>, class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<!!0, !!1>>)
IL_002d: nop
IL_002e: ldloc.s 4
IL_0030: stloc.2
IL_0031: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>::get_Empty()
IL_0036: stloc.3
IL_0037: newobj instance void class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>::.ctor()
IL_003c: stloc.s toml
IL_003e: ldloc.s toml
IL_0040: ldloc.3
IL_0041: unbox.any class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>
IL_0046: call void TomlFs.AST::Dictionary`2.AddSeq<string, class TomlFs.AST/Value>(class [mscorlib]System.Collections.Generic.Dictionary`2<!!0, !!1>, class [mscorlib]System.Collections.Generic.IEnumerable`1<class [mscorlib]System.Tuple`2<!!0, !!1>>)
IL_004b: nop
IL_004c: ldloc.s toml
IL_004e: stloc.s 4
IL_0050: ldloc.0
IL_0051: ldsfld string [mscorlib]System.String::Empty
IL_0056: ldstr ""
IL_005b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>::get_Empty()
IL_0060: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0> class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!0>)
IL_0065: ldloc.s 4
IL_0067: ldloc.2
IL_0068: newobj instance void class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>::.ctor(!0, !1, !2, !3)
IL_006d: ldloc.1
IL_006e: call !!1 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Fold<class [mscorlib]System.Tuple`2<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>>, class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!1, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0, !!1>>, !!1, !!0[])
IL_0073: stloc.s 6
IL_0075: ldloc.s 6
IL_0077: call instance !3 class [mscorlib]System.Tuple`4<string, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<string>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>>::get_Item4()
IL_007c: stloc.s toml
IL_007e: ldloc.s toml
IL_0080: ldarg.0
IL_0081: call void TomlFs.Parsers::'addSection@593-8'(class [mscorlib]System.Collections.Generic.Dictionary`2<string, class TomlFs.AST/Value>, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<class [mscorlib]System.Tuple`2<string, class TomlFs.AST/Value>>)
IL_0086: nop
IL_0087: ldloc.s toml
IL_0089: ret
} // end of method Parsers::construct_toml_when_no_lambda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment