private static string GetType(ParserRuleContext context) { var declarationContext = context.GetAncestor <CLanguageParser.DeclarationContext>(); if (declarationContext == null) { throw new InvalidOperationException($"Could not get the type for context \"{context.GetName()}\""); } string text = declarationContext.GetContextText(); if (text.ContainsInvariant(SEMICOLUMN_TOKEN)) { text = text.TrimEnd(SEMICOLUMN_TOKEN); } if (text.ContainsInvariant(EQUALS_TOKEN)) { text = text.Substring(0, text.InvariantLastIndexOf(EQUALS_TOKEN)); } text = text.TrimEnd(SEPARATOR_TOKEN); string result; if (text.Contains(POINTER_TOKEN)) { result = string.Format("{0} {1}", text.Substring(0, text.InvariantIndexOf(POINTER_TOKEN)).TrimEnd(SEPARATOR_TOKEN), text.Substring(text.InvariantIndexOf(POINTER_TOKEN), text.InvariantLastIndexOf(POINTER_TOKEN) - text.InvariantIndexOf(POINTER_TOKEN) + 1)); } else { result = text.Substring(0, text.InvariantLastIndexOf(SEPARATOR_TOKEN)); } result = result.RemoveDuplicateSpaces(); return(result); }