Пример #1
0
        /* Function: GetTargetHeader
         * If the passed identifier starts a target like "Source Folder", adds a new target for it in <projectConfig> and returns true.  If
         * it is a recognized target header but there is a syntax error in the value, it will add an error to <errorList> and still return true.
         * It only returns false for unrecognized identifiers.
         */
        protected bool GetTargetHeader(string lcIdentifier, string value, PropertyLocation propertyLocation, out Targets.Base newTarget)
        {
            // Source folder

            System.Text.RegularExpressions.Match match = sourceFolderRegex.Match(lcIdentifier);

            if (match.Success)
            {
                var target = new Targets.SourceFolder(propertyLocation, Files.InputType.Source);

                target.Folder = value;
                target.FolderPropertyLocation = propertyLocation;

                if (target.Folder.IsRelative)
                {
                    target.Folder = propertyLocation.FileName.ParentFolder + "/" + target.Folder;
                }

                int number = 0;

                if (int.TryParse(match.Groups[1].Value, out number))
                {
                    target.Number = number;
                    target.NumberPropertyLocation = propertyLocation;
                }

                projectConfig.InputTargets.Add(target);
                newTarget = target;
                return(true);
            }


            // Image folder

            match = imageFolderRegex.Match(lcIdentifier);

            if (match.Success)
            {
                var target = new Targets.SourceFolder(propertyLocation, Files.InputType.Image);

                target.Folder = value;
                target.FolderPropertyLocation = propertyLocation;

                if (target.Folder.IsRelative)
                {
                    target.Folder = propertyLocation.FileName.ParentFolder + "/" + target.Folder;
                }

                int number = 0;

                if (int.TryParse(match.Groups[1].Value, out number))
                {
                    target.Number = number;
                    target.NumberPropertyLocation = propertyLocation;
                }

                projectConfig.InputTargets.Add(target);
                newTarget = target;
                return(true);
            }


            // HTML output folder

            else if (htmlOutputFolderRegex.IsMatch(lcIdentifier))
            {
                var target = new Targets.HTMLOutputFolder(propertyLocation);

                target.Folder = value;
                target.FolderPropertyLocation = propertyLocation;

                if (target.Folder.IsRelative)
                {
                    target.Folder = propertyLocation.FileName.ParentFolder + "/" + target.Folder;
                }

                projectConfig.OutputTargets.Add(target);
                newTarget = target;
                return(true);
            }


            // Ignored source folder

            else if (ignoredSourceFolderRegex.IsMatch(lcIdentifier))
            {
                var target = new Targets.IgnoredSourceFolder(propertyLocation);

                target.Folder = value;
                target.FolderPropertyLocation = propertyLocation;

                if (target.Folder.IsRelative)
                {
                    target.Folder = propertyLocation.FileName.ParentFolder + "/" + target.Folder;
                }

                projectConfig.FilterTargets.Add(target);
                newTarget = target;
                return(true);
            }


            // Ignored source folder pattern

            else if (ignoredSourceFolderPatternRegex.IsMatch(lcIdentifier))
            {
                var target = new Targets.IgnoredSourceFolderPattern(propertyLocation);

                target.Pattern = value;
                target.PatternPropertyLocation = propertyLocation;

                projectConfig.FilterTargets.Add(target);
                newTarget = target;
                return(true);
            }


            else
            {
                newTarget = null;
                return(false);
            }
        }
Пример #2
0
        /* Function: GetTargetProperty
         * If the passed identifier is a valid keyword for <currentTarget>, applies the property and returns true.  This does not cover
         * the <ProjectInfo> settings for output targets, use <GetProjectInfoProperty()> for that instead.  If the value is invalid it will
         * add an error to <errorList> and still return true.  It will only return false if the identifier is unrecognized.
         */
        protected bool GetTargetProperty(string lcIdentifier, string value, PropertyLocation propertyLocation, Targets.Base target)
        {
            if (lcIdentifier == "name")
            {
                if (target is Targets.SourceFolder &&
                    (target as Targets.SourceFolder).Type == Files.InputType.Source)
                {
                    (target as Targets.SourceFolder).Name = value;
                    (target as Targets.SourceFolder).NamePropertyLocation = propertyLocation;
                }
                else
                {
                    errorList.Add(Locale.Get("NaturalDocs.Engine", "Project.txt.NameOnlyAppliesToSourceFolders"),
                                  propertyLocation.FileName, propertyLocation.LineNumber);
                }

                return(true);
            }

            else
            {
                return(false);
            }
        }
Пример #3
0
        // Group: Loading Functions
        // __________________________________________________________________________


        /* Function: Load
         * Attempts to parse <Project.txt> and return it as a <ProjectConfig>.  Any syntax errors found will be added to the
         * <ErrorList>.  The <ProjectConfig> object will always exist, even if all its properties are empty.
         */
        public bool Load(Path path, out ProjectConfig projectConfig, ErrorList errorList)
        {
            projectConfig = new ProjectConfig(Source.ProjectFile);

            this.errorList     = errorList;
            this.projectConfig = projectConfig;

            int originalErrorCount = errorList.Count;

            using (var configFile = new ConfigFile())
            {
                // We don't condense value whitespace because some things like title, subtitle, and copyright may want multiple spaces.
                bool openResult = configFile.Open(path,
                                                  ConfigFile.FileFormatFlags.CondenseIdentifierWhitespace |
                                                  ConfigFile.FileFormatFlags.MakeIdentifiersLowercase,
                                                  errorList);

                if (openResult == false)
                {
                    return(false);
                }

                string lcIdentifier, value;

                Targets.Base currentTarget      = null;
                ProjectInfo  currentProjectInfo = projectConfig.ProjectInfo;

                while (configFile.Get(out lcIdentifier, out value))
                {
                    var          propertyLocation = new PropertyLocation(Source.ProjectFile, configFile.FileName, configFile.LineNumber);
                    Targets.Base target           = null;

                    if (GetGlobalProperty(lcIdentifier, value, propertyLocation))
                    {
                        currentTarget      = null;
                        currentProjectInfo = projectConfig.ProjectInfo;
                    }
                    else if (GetTargetHeader(lcIdentifier, value, propertyLocation, out target))
                    {
                        currentTarget = target;

                        if (target is Targets.OutputBase)
                        {
                            currentProjectInfo = (target as Targets.OutputBase).ProjectInfo;
                        }
                        else
                        {
                            currentProjectInfo = projectConfig.ProjectInfo;
                        }
                    }
                    else if (GetProjectInfoProperty(lcIdentifier, value, propertyLocation, currentProjectInfo))
                    {
                    }
                    else if (currentTarget != null && GetTargetProperty(lcIdentifier, value, propertyLocation, currentTarget))
                    {
                    }
                    else
                    {
                        errorList.Add(
                            message: Locale.Get("NaturalDocs.Engine", "ConfigFile.NotAValidIdentifier(identifier)", lcIdentifier),
                            propertyLocation: propertyLocation
                            );
                    }
                }

                configFile.Close();
            }

            return(errorList.Count == originalErrorCount);
        }