protected virtual void setUpImpl() { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-us"); TemplateGroup.DefaultGroup = new TemplateGroup(); TemplateCompiler.subtemplateCount = 0; // new output dir for each test tmpdir = Path.GetFullPath(Path.Combine(Path.GetTempPath(), "st4-" + currentTimeMillis())); }
internal CultureInfo GetLocale() { string?locale = null; RuntimeAssembly runtimeAssembly = this; GetLocale(new QCallAssembly(ref runtimeAssembly), new StringHandleOnStack(ref locale)); if (locale == null) { return(CultureInfo.InvariantCulture); } return(CultureInfo.GetCultureInfo(locale)); }
/** We really only need a single locale for entire running ANTLR code * in a single VM. Only pay attention to the language, not the country * so that French Canadians and French Frenchies all get the same * template file, fr.stg. Just easier this way. */ public static void SetLocale(CultureInfo locale) { if (ErrorManager.locale == locale) { return; } ErrorManager.locale = locale; string language = locale.TwoLetterISOLanguageName; string fileName = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine(AntlrTool.ToolPathRoot, "Tool"), "Templates"), "messages"), "languages"), language + ".stg"); if (!File.Exists(fileName) && locale.TwoLetterISOLanguageName != CultureInfo.GetCultureInfo("en-us").TwoLetterISOLanguageName) { SetLocale(CultureInfo.GetCultureInfo("en-us")); return; } messages = new TemplateGroupFile(fileName); messages.EnableCache = AntlrTool.EnableTemplateCache; messages.Listener = initSTListener; if (!messages.IsDefined("INTERNAL_ERROR")) { // pick random msg to load if (language.Equals(CultureInfo.GetCultureInfo("en-us").TwoLetterISOLanguageName)) { RawError("ANTLR installation corrupted; cannot find English messages file " + fileName); Panic(); } else { // recurse on this rule, trying the US locale SetLocale(CultureInfo.GetCultureInfo("en-us")); } } messages.Listener = blankSTListener; bool messagesOK = VerifyMessages(); if (!messagesOK && language.Equals(CultureInfo.GetCultureInfo("en-us").TwoLetterISOLanguageName)) { RawError("ANTLR installation corrupted; English messages file " + language + ".stg incomplete"); Panic(); } else if (!messagesOK) { SetLocale(CultureInfo.GetCultureInfo("en-us")); // try US to see if that will work } }
/** We really only need a single locale for entire running ANTLR code * in a single VM. Only pay attention to the language, not the country * so that French Canadians and French Frenchies all get the same * template file, fr.stg. Just easier this way. */ public static void SetLocale(CultureInfo locale) { ErrorManager.locale = locale; String language = locale.TwoLetterISOLanguageName; //String fileName = "org/antlr/tool/templates/messages/languages/"+language+".stg"; string fileName = @"Tool\Templates\messages\languages\" + language + ".stg"; string streamName = "Antlr3." + fileName.Replace('\\', '.'); fileName = System.IO.Path.Combine(AntlrTool.ToolPathRoot, fileName); //ClassLoader cl = Thread.currentThread().getContextClassLoader(); //InputStream @is = cl.getResourceAsStream(fileName); System.IO.Stream @is; if (System.IO.File.Exists(fileName)) { @is = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(fileName)); } else { @is = typeof(ErrorManager).Assembly.GetManifestResourceStream(streamName); } //if ( @is==null ) { // cl = typeof(ErrorManager).getClassLoader(); // @is = cl.getResourceAsStream(fileName); //} if (@is == null && language.Equals(CultureInfo.GetCultureInfo("en-us").TwoLetterISOLanguageName)) { RawError("ANTLR installation corrupted; cannot find English messages file " + fileName); Panic(); } else if (@is == null) { //rawError("no such locale file "+fileName+" retrying with English locale"); SetLocale(CultureInfo.GetCultureInfo("en-us")); // recurse on this rule, trying the US locale return; } StreamReader br = null; try { br = new StreamReader(new System.IO.BufferedStream(@is)); messages = new StringTemplateGroup(br, typeof(AngleBracketTemplateLexer), initSTListener); br.Close(); } catch (IOException ioe) { RawError("error reading message file " + fileName, ioe); } finally { if (br != null) { try { br.Close(); } catch (IOException ioe) { RawError("cannot close message file " + fileName, ioe); } } } messages.ErrorListener = blankSTListener; bool messagesOK = VerifyMessages(); if (!messagesOK && language.Equals(CultureInfo.GetCultureInfo("en-us").TwoLetterISOLanguageName)) { RawError("ANTLR installation corrupted; English messages file " + language + ".stg incomplete"); Panic(); } else if (!messagesOK) { SetLocale(CultureInfo.GetCultureInfo("en-us")); // try US to see if that will work } }