public static SliceZone Parse(JToken json) { var slices = new List <Slice>(); foreach (JToken sliceJson in (JArray)json) { String sliceType = (string)sliceJson["slice_type"]; String label = (string)sliceJson["slice_label"]; // Handle Deprecated SliceZones JToken fragJson = sliceJson["value"]; if (fragJson != null) { string fragmentType = (string)fragJson["type"]; JToken fragmentValue = fragJson["value"]; Fragment value = FragmentParser.Parse(fragmentType, fragmentValue); slices.Add(new SimpleSlice(sliceType, label, value)); } else { //Parse new format non-repeating slice zones JObject nonRepeatsJson = (JObject)sliceJson["non-repeat"]; GroupDoc nonRepeat = GroupDoc.Parse(nonRepeatsJson); JArray repeatJson = (JArray)sliceJson["repeat"]; Group repeat = Group.Parse(repeatJson); slices.Add(new CompositeSlice(sliceType, label, repeat, nonRepeat)); } } return(new SliceZone(slices)); }
public void CanParseFragmentWithParamBlockWithInitialValues() { // Arrange. Lexer lexer = new Lexer(null, @"fragment basic_material; [params] float alpha : ALPHA = 1.0f; float3 dir = float3(1.0f, -1.1f, 0.0); bool enable = false;" ); FragmentParser parser = new FragmentParser(null, lexer.GetTokens()); // Act. FragmentNode fragment = parser.Parse(); // Assert. Assert.AreEqual("basic_material", fragment.Name); Assert.IsNotNull(fragment.Parameters); Assert.AreEqual(3, fragment.Parameters.VariableDeclarations.Count); Assert.AreEqual(TokenType.Float, fragment.Parameters.VariableDeclarations[0].DataType); Assert.AreEqual("alpha", fragment.Parameters.VariableDeclarations[0].Name); Assert.AreEqual("ALPHA", fragment.Parameters.VariableDeclarations[0].Semantic); Assert.AreEqual("1", fragment.Parameters.VariableDeclarations[0].InitialValue); Assert.AreEqual(TokenType.Float3, fragment.Parameters.VariableDeclarations[1].DataType); Assert.AreEqual("dir", fragment.Parameters.VariableDeclarations[1].Name); Assert.AreEqual("float3(1,-1.1,0)", fragment.Parameters.VariableDeclarations[1].InitialValue); Assert.AreEqual(TokenType.Bool, fragment.Parameters.VariableDeclarations[2].DataType); Assert.AreEqual("enable", fragment.Parameters.VariableDeclarations[2].Name); Assert.AreEqual("false", fragment.Parameters.VariableDeclarations[2].InitialValue); }
public static SliceZone Parse(JToken json) { var slices = new List <Slice>(); foreach (JToken sliceJson in (JArray)json) { String sliceType = (string)sliceJson["slice_type"]; String label = (string)sliceJson["slice_label"]; JToken fragJson = sliceJson["value"]; String fragmentType = (string)fragJson["type"]; JToken fragmentValue = fragJson["value"]; Fragment value = FragmentParser.Parse(fragmentType, fragmentValue); slices.Add(new Slice(sliceType, label, value)); } return(new SliceZone(slices)); }
public static GroupDoc Parse(JToken json) { var fragmentMap = new Dictionary <String, Fragment>(); foreach (KeyValuePair <String, JToken> field in (JObject)json) { String fragmentType = (string)field.Value["type"]; JToken fragmentValue = field.Value["value"]; Fragment fragment = FragmentParser.Parse(fragmentType, fragmentValue); if (fragment != null) { fragmentMap[field.Key] = fragment; } } return(new GroupDoc(fragmentMap)); }
public static Group Parse(JToken json) { var groupDocs = new List <GroupDoc> (); foreach (JToken groupJson in (JArray)json) { // each groupJson looks like this: { "somelink" : { "type" : "Link.document", { ... } }, "someimage" : { ... } } var fragmentMap = new Dictionary <String, Fragment>(); foreach (KeyValuePair <String, JToken> field in (JObject)groupJson) { String fragmentType = (string)field.Value["type"]; JToken fragmentValue = field.Value["value"]; Fragment fragment = FragmentParser.Parse(fragmentType, fragmentValue); if (fragment != null) { fragmentMap[field.Key] = fragment; } } groupDocs.Add(new GroupDoc(fragmentMap)); } return(new Group(groupDocs)); }
public void CanParseFragmentWithParamBlock() { // Arrange. Lexer lexer = new Lexer(null, @"fragment basic_material; [params] float alpha : ALPHA; float3 color;" ); FragmentParser parser = new FragmentParser(null, lexer.GetTokens()); // Act. FragmentNode fragment = parser.Parse(); // Assert. Assert.AreEqual("basic_material", fragment.Name); Assert.IsNotNull(fragment.Parameters); Assert.AreEqual(2, fragment.Parameters.VariableDeclarations.Count); Assert.AreEqual(TokenType.Float, fragment.Parameters.VariableDeclarations[0].DataType); Assert.AreEqual("alpha", fragment.Parameters.VariableDeclarations[0].Name); Assert.AreEqual("ALPHA", fragment.Parameters.VariableDeclarations[0].Semantic); Assert.AreEqual(TokenType.Float3, fragment.Parameters.VariableDeclarations[1].DataType); Assert.AreEqual("color", fragment.Parameters.VariableDeclarations[1].Name); }