Beispiel #1
0
        public FileParser(LangMatcher langMatcher, Lang lang, string path, string relPath)
        {
            this.langMatcher = langMatcher;
            this.lang        = lang;
            this.path        = path;
            this.relPath     = relPath;

            paramMatcher = new ParamMatcher(lang);

            Lines = File.ReadAllLines(path);             // Load each line of the file in the buffer

            ModuleParam moduleParam = new ModuleParam(); // adds a new wrapper with default "none" data

            // initialize wrapper list
            WrapperDict = new SortedDictionary <string, WrapperParam>
            {
                { moduleParam.WrapperName, moduleParam }
            };

            // initializes the current vars for easy and fast access
            CurrentWrapper = moduleParam;
            CurrentSection = CurrentWrapper.GetSectionNone();
        }
Beispiel #2
0
        public static int Run(Options options)
        {
            NEWDIR         = options.OutputFolder;
            ErrorLogFormat = options.LogFormat;
            DEBUGGING      = options.Verbose;

            if (!Directory.Exists(options.Folder))
            {
                Console.Error.WriteLine("Provided folder '" + options.Folder + "' does not exists!");

                return((int)ERROR_CODES.NOT_EXISTS);
            }

            // Build the file tree
            string[] files = Directory.GetFiles(options.Folder, "*.*", SearchOption.AllDirectories);

            // Prepare the files
            List <FileParser> fileParsers = new List <FileParser>();

            int amount = files.Length;

            LangMatcher langMatcher = new LangMatcher();             // lang processing system

            for (int n = 0; n < amount; n++)
            {
                string file = files[n];

                string relPath = file.Remove(0, options.Folder.Length);
                relPath = relPath.TrimStart('\\');
                relPath = relPath.Replace('\\', '/');

                Progress = (int)Math.Floor((n + 1) / (double)amount * 100.0);

                WriteDebugInfo("[" + Progress + "%] '" + relPath + "'");

                // get the lang based on the file extension
                Lang lang = langMatcher.GetByFileExtension(Path.GetExtension(file));

                if (lang == null)
                {
                    continue;
                }

                WriteDebugInfo("Running '" + lang.GetName() + "' parser");

                FileParser fileParser = new FileParser(langMatcher, lang, file, relPath);                 // fileParser is used to process a file
                fileParser.CleanUp();
                fileParser.Process();

                fileParsers.Add(fileParser);

                WriteDebugInfo("Finished parsing");
                WriteDebugInfo("");
            }

            List <WrapperParam> wrapperList = new List <WrapperParam>(ProcessFileParsers(fileParsers, out SortedDictionary <string, SortedDictionary <string, List <DataStructure> > > globalsDict));

            if (string.IsNullOrEmpty(NEWDIR))
            {
                WriteDebugInfo("Finished checking the documentation.");

                return(Environment.ExitCode);
            }

            // Generate Folders
            DirectoryInfo outputFolderInfo = new DirectoryInfo(NEWDIR);

            if (outputFolderInfo.Exists)
            {
                outputFolderInfo.Empty();
            }
            else
            {
                Directory.CreateDirectory(NEWDIR);
            }

            // Write single files
            GenerateDocumentationData(wrapperList, globalsDict);

            // Write overviews JSON
            GenerateJSONIndex(wrapperList, globalsDict);

            // Write search JSON
            GenerateJSONSearch(wrapperList, globalsDict);

            WriteDebugInfo("Finished generating the documentation.");

            return(Environment.ExitCode);
        }