Loads language raws and processes them into languages and codes
Beispiel #1
0
        private static void WriteCodeTemplates(IList <LanguageProcessor.DocCode> list, IndentedTextWriter indentedWriter, IList <CodeTemplate> templates)
        {
            Dictionary <string, List <string> >       dictionary = new Dictionary <string, List <string> > ((IEqualityComparer <string>)StringComparer.CurrentCultureIgnoreCase);
            Dictionary <string, List <CodeTemplate> > dict       = new Dictionary <string, List <CodeTemplate> > ();

            for (int index = 0; index < templates.Count; ++index)
            {
                string humanString = ((IEnumerable <string>)list [index].languages).ToHumanString <string> ();
                dict.GetOldOrSetNew <string, List <CodeTemplate> > (humanString).Add(templates [index]);
                foreach (TemplateParameter templateParameter in templates[index])
                {
                    dictionary.GetOldOrSetNew <string, List <string> > (templateParameter.name).AddRange((IEnumerable <string>)list [index].parameterDocs [templateParameter.name]);
                }
            }
            foreach (KeyValuePair <string, List <CodeTemplate> > keyValuePair in dict)
            {
                indentedWriter.WriteLine(keyValuePair.Key + ":");
                ++indentedWriter.Indent;
                foreach (CodeTemplate code in keyValuePair.Value)
                {
                    CodeTemplate.WriteDoc((TextWriter)indentedWriter, code);
                }
                --indentedWriter.Indent;
            }
            ++indentedWriter.Indent;
            List <string> stringList = new List <string> ();

            foreach (LanguageProcessor.DocCode docCode in (IEnumerable <LanguageProcessor.DocCode>)list)
            {
                if (docCode.mainDoc.Count > 0)
                {
                    stringList.AddRange((IEnumerable <string>)docCode.mainDoc);
                    break;
                }
            }
            if (stringList.Count > 0)
            {
                indentedWriter.WriteLineNoTabs("");
                foreach (string str in stringList)
                {
                    indentedWriter.WriteLine(str);
                }
            }
            if (dictionary.Count > 0)
            {
                LanguageProcessor.WriteParameters(indentedWriter, dictionary);
            }
            --indentedWriter.Indent;
        }
Beispiel #2
0
        private static void WriteTerminatingStringTemplate(IList <LanguageProcessor.DocCode> list, IndentedTextWriter writer, IList <TerminatingStringTemplate> templates)
        {
            Dictionary <string, List <string> > dictionary = new Dictionary <string, List <string> > ((IEqualityComparer <string>)StringComparer.CurrentCultureIgnoreCase);
            Dictionary <string, List <TerminatingStringTemplate> > dict = new Dictionary <string, List <TerminatingStringTemplate> > ();

            for (int index = 0; index < templates.Count; ++index)
            {
                string humanString = ((IEnumerable <string>)list [index].languages).ToHumanString <string> ();
                dict.GetOldOrSetNew <string, List <TerminatingStringTemplate> > (humanString).Add(templates [index]);
                dictionary.GetOldOrSetNew <string, List <string> > (templates [index].Parameter.name).AddRange((IEnumerable <string>)list [index].parameterDocs [templates [index].Parameter.name]);
            }
            foreach (KeyValuePair <string, List <TerminatingStringTemplate> > keyValuePair in dict)
            {
                writer.WriteLine(keyValuePair.Key + ":");
                ++writer.Indent;
                foreach (TerminatingStringTemplate template in keyValuePair.Value)
                {
                    TerminatingStringTemplate.WriteDoc((TextWriter)writer, template);
                }
                --writer.Indent;
            }
            writer.WriteLineNoTabs("");
            ++writer.Indent;
            string[] strArray = (string[])null;
            foreach (LanguageProcessor.DocCode docCode in (IEnumerable <LanguageProcessor.DocCode>)list)
            {
                if (docCode.mainDoc.Count > 0)
                {
                    strArray = docCode.mainDoc.ToArray();
                    break;
                }
            }
            if (strArray != null)
            {
                foreach (string str in list[0].mainDoc)
                {
                    writer.WriteLine(str);
                }
            }
            if (dictionary.Count > 0)
            {
                LanguageProcessor.WriteParameters(writer, dictionary);
            }
            --writer.Indent;
        }
Beispiel #3
0
 private void WriteCode(List <LanguageProcessor.DocCode> list, IndentedTextWriter writer)
 {
     if (list [0].code is CodeTemplate)
     {
         CodeTemplate[] codeTemplateArray = Array.ConvertAll <LanguageProcessor.DocCode, CodeTemplate> (list.ToArray(), (Converter <LanguageProcessor.DocCode, CodeTemplate>)(x => x.code as CodeTemplate));
         LanguageProcessor.WriteCodeTemplates((IList <LanguageProcessor.DocCode>)list, writer, (IList <CodeTemplate>)codeTemplateArray);
     }
     else if (list [0].code is TerminatingStringTemplate)
     {
         TerminatingStringTemplate[] terminatingStringTemplateArray = Array.ConvertAll <LanguageProcessor.DocCode, TerminatingStringTemplate> (list.ToArray(), (Converter <LanguageProcessor.DocCode, TerminatingStringTemplate>)(x => x.code as TerminatingStringTemplate));
         LanguageProcessor.WriteTerminatingStringTemplate((IList <LanguageProcessor.DocCode>)list, writer, (IList <TerminatingStringTemplate>)terminatingStringTemplateArray);
     }
     else
     {
         if (!(list [0].code is IFixedDocString))
         {
             return;
         }
         foreach (string str in (list[0].code as IFixedDocString).DocString.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
         {
             writer.WriteLine(str);
         }
     }
 }
        public static void MakeDoc(string output, string rawsFolder, 
            string extension, bool isDirectory, string header, string footer)
        {
            var pro = new LanguageProcessor(true,
                new TemplateComparer(), stringComparer);
            //IPointerMaker<int> ptrMaker = new GBAPointerMaker();
            if (isDirectory)
            {
                pro.ProcessCode(rawsFolder, extension);
            }
            else
            {
                pro.ProcessCode(rawsFolder);
            }
            using (StreamWriter writer = File.CreateText(output))
            {
                if (header != null)
                {
                    writer.WriteLine(File.ReadAllText(header));
                    writer.WriteLine();
                }

                pro.WriteDocs(writer);

                if (footer != null)
                {
                    writer.WriteLine(File.ReadAllText(footer));
                    writer.WriteLine();
                }
            }
        }
        public static void LoadCodes(string rawsFolder, string extension, bool isDirectory, bool collectDocCodes)
        {
            languages = new Dictionary<string, EACodeLanguage>();
            LanguageProcessor pro = new LanguageProcessor(collectDocCodes,
                new TemplateComparer(), stringComparer);
            IPointerMaker<int> ptrMaker = new GBAPointerMaker();
            if (isDirectory)
            {
                pro.ProcessCode(rawsFolder, extension);
            }
            else
            {
                pro.ProcessCode(rawsFolder);
            }
            foreach (KeyValuePair<string, ICodeTemplateStorer> item in pro.Languages)
            {
                Tuple<string, List<Priority>>[][] pointerList;

                switch (item.Key)
                {
                    case "FE6":
                        pointerList = FE6CodeLanguage.PointerList;
                        break;
                    case "FE7":
                        pointerList = FE7CodeLanguage.PointerList;
                        break;
                    case "FE8":
                        pointerList = FE8CodeLanguage.PointerList;
                        break;
                    default:
                        throw new NotSupportedException("Language " + item.Key + " not supported.");
                }
                ICodeTemplateStorer storer = item.Value;
                if (item.Key == "FE8")
                {
                    storer.AddCode(new GenericFE8Template(), Priority.none);
                }
                EACodeLanguage language = new EACodeLanguage(
                    item.Key, ptrMaker,
                    pointerList,
                    storer, stringComparer
                    );
                languages[item.Key] = language;
            }
        }
        public static void LoadCodes()
        {
            if (languages != null)
            {
                languages.Clear();
            }
            else
            {
                languages = new Dictionary<String, EACodeLanguage>();
            }

            LanguageProcessor processor = new LanguageProcessor(false,
                new TemplateComparer(), stringComparer);
            processor.ProcessCode("Language raws", ".txt");

            IPointerMaker ptrMaker = new GBAPointerMaker();

            foreach (KeyValuePair<string, ICodeTemplateStorer> item in processor.Languages)
            {
                Tuple<string, List<Priority>>[][] pointerList;

                switch (item.Key)
                {
                    case "FE6":
                        pointerList = FE6CodeLanguage.PointerList;
                        break;
                    case "FE7":
                        pointerList = FE7CodeLanguage.PointerList;
                        break;
                    case "FE8":
                        pointerList = FE8CodeLanguage.PointerList;
                        break;
                    default:
                        throw new NotSupportedException("Language " + item.Key + " not supported.");
                }
                EACodeLanguage language = new EACodeLanguage(
                    item.Key, ptrMaker,
                    pointerList,
                    item.Value, stringComparer
                    );
                language.MessageLog = messageLog;
                languages[item.Key] = language;
            }
        }