Beispiel #1
0
        // Group: Functions
        // __________________________________________________________________________


        /* Constructor: Manager
         */
        public Manager(Engine.Instance engineInstance) : base(engineInstance)
        {
            languages      = new IDObjects.Manager <Language>(KeySettingsForLanguageName, false);
            aliases        = new StringTable <Language>(KeySettingsForLanguageName);
            extensions     = new StringTable <Language>(KeySettingsForExtensions);
            shebangStrings = new SortedStringTable <Language>(new ShebangStringComparer(), KeySettingsForShebangStrings);

            predefinedLanguages = new Language[6];

            predefinedLanguages[0]            = new Language(this, "Text File");
            predefinedLanguages[0].Type       = Language.LanguageType.TextFile;
            predefinedLanguages[0].Predefined = true;

            predefinedLanguages[1]            = new Languages.Parsers.ShebangScript(this);
            predefinedLanguages[1].Predefined = true;

            predefinedLanguages[2]            = new Languages.Parsers.CSharp(this);
            predefinedLanguages[2].Predefined = true;

            predefinedLanguages[3]            = new Languages.Parsers.Perl(this);
            predefinedLanguages[3].Predefined = true;

            predefinedLanguages[4]            = new Languages.Parsers.Python(this);
            predefinedLanguages[4].Predefined = true;

            predefinedLanguages[5]            = new Languages.Parsers.Ruby(this);
            predefinedLanguages[5].Predefined = true;
        }
Beispiel #2
0
        // Group: Functions
        // __________________________________________________________________________


        /* Constructor: Config
         */
        public Config()
        {
            languages      = new IDObjects.Manager <Language>(KeySettingsForLanguageName, false);
            aliases        = new StringTable <int>(KeySettingsForLanguageName);
            fileExtensions = new StringTable <int>(KeySettingsForFileExtensions);
            shebangStrings = new SortedStringTable <int>(new ShebangStringComparer(), KeySettingsForShebangStrings);
        }
Beispiel #3
0
        // Group: Functions
        // __________________________________________________________________________


        /* Constructor: Config
         */
        public Config()
        {
            commentTypes = new IDObjects.Manager <CommentType>(KeySettingsForCommentTypes, false);
            tags         = new IDObjects.Manager <Tag>(KeySettingsForTags, false);

            singleDefinitionKeywords = new StringTable <KeywordDefinition>(KeySettingsForKeywords);
            multiDefinitionKeywords  = new StringTable <List <KeywordDefinition> >(KeySettingsForKeywords);
        }
Beispiel #4
0
        // Group: Initialization and Configuration Functions
        // __________________________________________________________________________


        /* Function: Manager
         */
        public Manager(Engine.Instance engineInstance) : base(engineInstance)
        {
            fileSources           = new List <FileSource>();
            filters               = new List <Filter>();
            claimedFolderPrefixes = new StringSet(KeySettings.IgnoreCase);

            files = new IDObjects.Manager <File>(Config.Manager.KeySettingsForPaths, false);

            accessLock     = new object();
            changeWatchers = new List <IChangeWatcher>();
        }
Beispiel #5
0
        // Group: Functions
        // __________________________________________________________________________


        /* Constructor: Manager
         */
        public Manager(Engine.Instance engineInstance) : base(engineInstance)
        {
            // Comment type names aren't normalized because they're only referenced in other config files.  Tags and keywords are
            // referenced in source files so they should be more tolerant.
            commentTypes = new IDObjects.Manager <CommentType>(KeySettingsForCommentTypes, false);
            tags         = new IDObjects.Manager <Tag>(KeySettingsForTags, false);

            singularKeywords = new StringTable <CommentType>(KeySettingsForKeywords);
            pluralKeywords   = new StringTable <CommentType>(KeySettingsForKeywords);

            groupCommentTypeID = 0;
        }
Beispiel #6
0
        // Group: Initialization and Configuration Functions
        // __________________________________________________________________________


        /* Function: Manager
         */
        public Manager(Engine.Instance engineInstance) : base(engineInstance)
        {
            fileSources = new List <FileSource>();
            filters     = new List <Filter>();

            files = new IDObjects.Manager <File>(Config.Manager.KeySettingsForPaths, false);
            filesAddedSinceStart = new IDObjects.NumberSet();
            unprocessedChanges   = new UnprocessedChanges();

            accessLock     = new object();
            changeWatchers = new List <IChangeWatcher>();
        }
Beispiel #7
0
        /* Function: Save
         * Saves the current state into <Files.nd>.  Throws an exception if unsuccessful.  All <Files> in the structure should have
         * their last modification time set to tick count zero before calling this function.
         */
        public void Save(Path filename, IDObjects.Manager <File> files)
        {
            BinaryFile binaryFile = new BinaryFile();

            binaryFile.OpenForWriting(filename);

            try
            {
                foreach (File file in files)
                {
                    // [Int32: ID]
                    // [String: Path]
                    // [Byte: Type]
                    // [Int64: Last Modification in Ticks or 0]
                    // (if image)
                    //    [UInt32: Width in Pixels or 0 if unknown]
                    //    [UInt32: Height in Pixels or 0 if unknown]

                    binaryFile.WriteInt32(file.ID);
                    binaryFile.WriteString(file.FileName);
                    binaryFile.WriteByte((byte)file.Type);
                    binaryFile.WriteInt64(file.LastModified.Ticks);

                    if (file.Type == FileType.Image)
                    {
                        ImageFile imageFile = (ImageFile)file;

                        if (imageFile.DimensionsKnown)
                        {
                            binaryFile.WriteUInt32(imageFile.Width);
                            binaryFile.WriteUInt32(imageFile.Height);
                        }
                        else
                        {
                            binaryFile.WriteUInt32(0);
                            binaryFile.WriteUInt32(0);
                        }
                    }
                }

                // [Int32: 0]
                binaryFile.WriteInt32(0);
            }
            finally
            { binaryFile.Close(); }
        }
Beispiel #8
0
        /* Function: Load
         * Loads <Files.nd> and returns whether it was successful.  If it wasn't it will still return valid objects, they will just
         * be empty.
         */
        public bool Load(Path filename, out IDObjects.Manager <File> files)
        {
            files = new IDObjects.Manager <File>(Config.Manager.KeySettingsForPaths, false);

            BinaryFile binaryFile = new BinaryFile();
            bool       result     = true;

            try
            {
                // We'll continue to handle 2.0 files in 2.0.2 since it's easy enough
                if (binaryFile.OpenForReading(filename, "2.0") == false)
                {
                    result = false;
                }
                else
                {
                    // [Int32: ID]
                    // [String: Path]
                    // [Byte: Type]
                    // [Int64: Last Modification in Ticks or 0]
                    // (if image)
                    //    [UInt32: Width in Pixels or 0 if unknown]
                    //    [UInt32: Height in Pixels or 0 if unknown]
                    // ...
                    // [Int32: 0]

                    int      id;
                    Path     path;
                    FileType type;
                    DateTime lastModification;
                    File     file;
                    uint     width, height;

                    for (;;)
                    {
                        id = binaryFile.ReadInt32();

                        if (id == 0)
                        {
                            break;
                        }

                        path             = binaryFile.ReadString();
                        type             = (FileType)binaryFile.ReadByte();
                        lastModification = new DateTime(binaryFile.ReadInt64());

                        if (type == FileType.Image)
                        {
                            if (binaryFile.Version < "2.0.2")
                            {
                                width  = 0;
                                height = 0;
                            }
                            else
                            {
                                width  = binaryFile.ReadUInt32();
                                height = binaryFile.ReadUInt32();
                            }

                            if (width == 0 || height == 0)
                            {
                                // If this file is from a different version of Natural Docs, no matter which one, reset the last modification
                                // time so they'll be reparsed and take another stab at getting the dimensions
                                if (binaryFile.Version != Engine.Instance.Version)
                                {
                                    lastModification = new DateTime(0);
                                }

                                file = new ImageFile(path, lastModification);
                            }
                            else
                            {
                                file = new ImageFile(path, lastModification, width, height);
                            }
                        }
                        else
                        {
                            file = new File(path, type, lastModification);
                        }

                        file.ID = id;
                        files.Add(file);
                    }
                }
            }
            catch
            {
                result = false;
            }
            finally
            {
                binaryFile.Close();
            }

            if (result == false)
            {
                files.Clear();
            }

            return(result);
        }
Beispiel #9
0
        // Group: Saving Functions
        // __________________________________________________________________________


        /* Function: Save
         * Saves the current computed languages into <Languages.nd>.  Throws an exception if unsuccessful.
         */
        public void Save(Path filename, IDObjects.Manager <Language> languages,
                         StringTable <Language> aliases, StringTable <Language> extensions,
                         SortedStringTable <Language> shebangStrings, StringSet ignoredExtensions)
        {
            BinaryFile file = new BinaryFile();

            file.OpenForWriting(filename);

            try
            {
                // [String: Language Name]
                // [Int32: ID]
                // [Byte: Type]
                // [String: Simple Identifier]
                // [Byte: Enum Values]
                // [Byte: Case Sensitive (1 or 0)]
                // [String: Member Operator Symbol]
                // [String: Line Extender Symbol]
                // [String: Line Comment Symbol] [] ... [String: null]
                // [String: Opening Block Comment Symbol] [String: Closing Block Comment Symbo] [] [] ... [String: null]
                // [String: Opening Javadoc Line Comment Symbol] [String: Remainder Javadoc Line Comment Symbol [] ... [String: null]
                // [String: Opening Javadoc Block Comment Symbol] [String: Closing Javadoc Block Comment Symbol] [] [] ... [String: null]
                // [String: XML Line Comment Symbol] [] ... [String: null]

                // [Int32: Comment Type ID]
                // [Byte: Include Line Breaks (0 or 1)]
                // [String: Prototype Ender Symbol] [] ... [String: null]
                // ...
                // [Int32: 0]

                // ...
                // [String: null]

                foreach (Language language in languages)
                {
                    file.WriteString(language.Name);
                    file.WriteInt32(language.ID);
                    file.WriteByte((byte)language.Type);
                    file.WriteString(language.SimpleIdentifier);
                    file.WriteByte((byte)language.EnumValue);
                    file.WriteByte((byte)(language.CaseSensitive ? 1 : 0));
                    file.WriteString(language.MemberOperator);
                    file.WriteString(language.LineExtender);

                    WriteStringArray(file, language.LineCommentStrings);
                    WriteStringArray(file, language.BlockCommentStringPairs);
                    WriteStringArray(file, language.JavadocLineCommentStringPairs);
                    WriteStringArray(file, language.JavadocBlockCommentStringPairs);
                    WriteStringArray(file, language.XMLLineCommentStrings);

                    int[] commentTypes = language.GetCommentTypesWithPrototypeEnders();
                    if (commentTypes != null)
                    {
                        foreach (int commentType in commentTypes)
                        {
                            PrototypeEnders prototypeEnders = language.GetPrototypeEnders(commentType);

                            file.WriteInt32(commentType);
                            file.WriteByte((byte)(prototypeEnders.IncludeLineBreaks ? 1 : 0));
                            WriteStringArray(file, prototypeEnders.Symbols);
                        }
                    }
                    file.WriteInt32(0);
                }

                file.WriteString(null);


                // [String: Alias] [Int32: Language ID] [] [] ... [String: Null]

                foreach (KeyValuePair <string, Language> pair in aliases)
                {
                    file.WriteString(pair.Key);
                    file.WriteInt32(pair.Value.ID);
                }

                file.WriteString(null);


                // [String: Extension] [Int32: Language ID] [] [] ... [String: Null]

                foreach (KeyValuePair <string, Language> pair in extensions)
                {
                    file.WriteString(pair.Key);
                    file.WriteInt32(pair.Value.ID);
                }

                file.WriteString(null);


                // [String: Shebang String] [Int32: Language ID] [] [] ... [String: Null]

                foreach (KeyValuePair <string, Language> pair in shebangStrings)
                {
                    file.WriteString(pair.Key);
                    file.WriteInt32(pair.Value.ID);
                }

                file.WriteString(null);


                // [String: Ignored Extension] [] ... [String: Null]

                foreach (string ignoredExtension in ignoredExtensions)
                {
                    file.WriteString(ignoredExtension);
                }

                file.WriteString(null);
            }

            finally
            {
                file.Close();
            }
        }
Beispiel #10
0
        /* Function: Save
         * Saves the current computed comment types into <Comments.nd>.  Throws an exception if unsuccessful.
         */
        public void Save(Path filename, IDObjects.Manager <CommentType> commentTypes, IDObjects.Manager <Tag> tags,
                         StringTable <CommentType> singularKeywords, StringTable <CommentType> pluralKeywords,
                         StringSet ignoredKeywords)
        {
            BinaryFile file = new BinaryFile();

            file.OpenForWriting(filename);

            try
            {
                // [String: Tag Name]
                // [Int32: ID]
                // ...
                // [String: null]

                foreach (Tag tag in tags)
                {
                    file.WriteString(tag.Name);
                    file.WriteInt32(tag.ID);
                }

                file.WriteString(null);


                // [String: Comment Type Name]
                // [Int32: ID]
                // [String: Display Name]
                // [String: Plural Display Name]
                // [String: Simple Identifier]
                // [Byte: Index]
                // [Int32: Index With ID]?
                // [Byte: Scope]
                // [Byte: Break Lists]
                // [UInt16: Flags]
                // ...
                // [String: null]

                foreach (CommentType commentType in commentTypes)
                {
                    file.WriteString(commentType.Name);
                    file.WriteInt32(commentType.ID);
                    file.WriteString(commentType.DisplayName);
                    file.WriteString(commentType.PluralDisplayName);
                    file.WriteString(commentType.SimpleIdentifier);
                    file.WriteByte((byte)commentType.Index);

                    if (commentType.Index == CommentType.IndexValue.IndexWith)
                    {
                        file.WriteInt32(commentType.IndexWith);
                    }

                    file.WriteByte((byte)commentType.Scope);
                    file.WriteByte((byte)(commentType.BreakLists ? 1 : 0));
                    file.WriteUInt16((ushort)commentType.Flags.AllConfigurationProperties);
                }

                file.WriteString(null);


                // [String: Singular Keyword]
                // [Int32: Comment Type ID]
                // ...
                // [String: null]

                foreach (KeyValuePair <string, CommentType> pair in singularKeywords)
                {
                    file.WriteString(pair.Key);
                    file.WriteInt32(pair.Value.ID);
                }

                file.WriteString(null);


                // [String: Plural Keyword]
                // [Int32: Comment Type ID]
                // ...
                // [String: null]

                foreach (KeyValuePair <string, CommentType> pair in pluralKeywords)
                {
                    file.WriteString(pair.Key);
                    file.WriteInt32(pair.Value.ID);
                }

                file.WriteString(null);


                // [String: Ignored Keyword]
                // ...
                // [String: null]

                foreach (string keyword in ignoredKeywords)
                {
                    file.WriteString(keyword);
                }

                file.WriteString(null);
            }

            finally
            {
                file.Close();
            }
        }