From e8b59d4fdb8b25bca8563414d9a4f6680cc11911 Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Wed, 2 Mar 2011 19:29:07 +0100 Subject: [PATCH] simplify SubstituteInType, just try all strings that match [\w|\.]+ --- .../CS2JTemplate/TranslationTemplate.cs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs index e261e2a..fcb2bc8 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTemplate/TranslationTemplate.cs @@ -35,15 +35,45 @@ namespace Twiglet.CS2J.Translator.TypeRep } return ret; } - + + private class TypeVarMapper + { + private Dictionary myArgMap; + + public TypeVarMapper(Dictionary inArgMap) + { + myArgMap = inArgMap; + } + + public string ReplaceFromMap(Match m) + { + if (myArgMap.ContainsKey(m.Value)) + { + return myArgMap[m.Value].mkSafeTypeName(); + } + return m.Value; + } + } + public static string SubstituteInType(String type, Dictionary argMap) + { + if (String.IsNullOrEmpty(type)) + return type; + + TypeVarMapper mapper = new TypeVarMapper(argMap); + return Regex.Replace(type, @"([\w|\.]+)*", new MatchEvaluator(mapper.ReplaceFromMap)); + } + + + private static string OldSubstituteInType(String type, Dictionary argMap) { if (String.IsNullOrEmpty(type)) return type; string ret = type; - // type is either "string" or "string" - Match match = Regex.Match(type, @"^([\w|\.]+)(?:\s*\[\s*([\w|\.]+)(?:\s*,\s*([\w|\.]+))*\s*\])?$"); + // type is either "string" or "string*[type,type,...]*" or string[] +// Match match = Regex.Match(type, @"^([\w|\.]+)(?:\s*\*\[\s*([\w|\.]+)(?:\s*,\s*([\w|\.]+))*\s*\]\*)?$"); + Match match = Regex.Match(type, @"([\w|\.]+)*"); if (match.Success) { CaptureCollection captures = match.Captures;