private string GetTypeDefinitionName() { if (TypeName == "vector") { TypeParser arrayType = GetArrayType(); return($"{arrayType.GetTypeDefinitionName()}[]"); } if (TypeName == "map") { TypeParser pair = GetArrayType(); if (pair.TypeName != "pair") { throw new Exception($"Pair has unsupported type {pair.TypeName}"); } if (pair.Children.Count != 2) { throw new Exception($"Pair contains {pair.Children.Count} children"); } TypeParser first = pair.Children[0]; if (first.VarName != "first") { throw new Exception($"First has unsupported name {first.VarName}"); } TypeParser second = pair.Children[1]; if (second.VarName != "second") { throw new Exception($"Second has unsupported name {second.VarName}"); } return($"map<{first.GetTypeDefinitionName()}, {second.GetTypeDefinitionName()}>"); } if (TypeName == "pair") { if (VarName != "data") { throw new Exception($"Pair has unsupported type {VarName}"); } if (Children.Count != 2) { throw new Exception($"Pair contains {Children.Count} children"); } TypeParser first = Children[0]; if (first.VarName != "first") { throw new Exception($"First has unsupported name {first.VarName}"); } TypeParser second = Children[1]; if (second.VarName != "second") { throw new Exception($"Second has unsupported name {second.VarName}"); } return($"pair<{first.GetTypeDefinitionName()}, {second.GetTypeDefinitionName()}>"); } return(TypeName); }
private string GetTypeDefinitionName() { switch (TypeName) { case "Array": { TypeParser arrayType = GetArrayElement(); return($"{arrayType.GetTypeDefinitionName()}[]"); } case "vector": { TypeParser vectorType = GetElement(); return($"vector<{vectorType.GetTypeDefinitionName()}>"); } case "set": { TypeParser setType = GetElement(); return($"set<{setType.GetTypeDefinitionName()}>"); } case "map": { TypeParser pair = GetElement(); if (pair.TypeName != "pair") { throw new Exception($"Pair has unsupported type {pair.TypeName}"); } if (pair.Children.Count != 2) { throw new Exception($"Pair contains {pair.Children.Count} children"); } TypeParser key = pair.Children[0]; if (key.VarName != "first") { throw new Exception($"First has unsupported name {key.VarName}"); } TypeParser value = pair.Children[1]; if (value.VarName != "second") { throw new Exception($"Second has unsupported name {value.VarName}"); } return($"map<{key.GetTypeDefinitionName()}, {value.GetTypeDefinitionName()}>"); } case "pair": { if (Children.Count != 2) { throw new Exception($"Pair contains {Children.Count} children"); } TypeParser key = Children[0]; if (key.VarName != "first") { throw new Exception($"First has unsupported name {key.VarName}"); } TypeParser value = Children[1]; if (value.VarName != "second") { throw new Exception($"Second has unsupported name {value.VarName}"); } return($"pair<{key.GetTypeDefinitionName()}, {value.GetTypeDefinitionName()}>"); } default: return(TypeName); } }