diff --git a/Nuclex.Support (net-4.0).csproj b/Nuclex.Support (net-4.0).csproj index efa4c66..48e83ad 100644 --- a/Nuclex.Support (net-4.0).csproj +++ b/Nuclex.Support (net-4.0).csproj @@ -197,14 +197,14 @@ WeakCollection.cs - - + + ConfigurationFileStore.cs - - - - + + + + @@ -317,7 +317,6 @@ - diff --git a/Source/Configuration/MemoryStore.cs b/Source/Configuration/MemoryStore.cs deleted file mode 100644 index e602821..0000000 --- a/Source/Configuration/MemoryStore.cs +++ /dev/null @@ -1,29 +0,0 @@ -#region CPL License -/* -Nuclex Framework -Copyright (C) 2002-2014 Nuclex Development Labs - -This library is free software; you can redistribute it and/or -modify it under the terms of the IBM Common Public License as -published by the IBM Corporation; either version 1.0 of the -License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -IBM Common Public License for more details. - -You should have received a copy of the IBM Common Public -License along with this library -*/ -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Nuclex.Support.Source.Configuration { - class MemoryStore { - } -} diff --git a/Source/Configuration/WindowsRegistryStore.cs b/Source/Configuration/WindowsRegistryStore.cs deleted file mode 100644 index 7ebf6c5..0000000 --- a/Source/Configuration/WindowsRegistryStore.cs +++ /dev/null @@ -1,34 +0,0 @@ -#region CPL License -/* -Nuclex Framework -Copyright (C) 2002-2014 Nuclex Development Labs - -This library is free software; you can redistribute it and/or -modify it under the terms of the IBM Common Public License as -published by the IBM Corporation; either version 1.0 of the -License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -IBM Common Public License for more details. - -You should have received a copy of the IBM Common Public -License along with this library -*/ -#endregion - -using System; - -namespace Nuclex.Support.Configuration { - - /// Stores settings in the registry of Windows systems - public class WindowsRegistryStore : IDisposable { - - /// Immediately releases all resources owned by the instance - public void Dispose() { - } - - } - -} // namespace Nuclex.Support.Configuration diff --git a/Source/Configuration/ConfigurationFileStore.Parsing.cs b/Source/Settings/ConfigurationFileStore.Parsing.cs similarity index 63% rename from Source/Configuration/ConfigurationFileStore.Parsing.cs rename to Source/Settings/ConfigurationFileStore.Parsing.cs index aa633d1..e02eb7b 100644 --- a/Source/Configuration/ConfigurationFileStore.Parsing.cs +++ b/Source/Settings/ConfigurationFileStore.Parsing.cs @@ -23,24 +23,102 @@ using System.IO; using Nuclex.Support.Parsing; -namespace Nuclex.Support.Configuration { +namespace Nuclex.Support.Settings { partial class ConfigurationFileStore { + #region class ParserState + + /// Remembers the target store and current category of the parser + private class ParserState { + + /// Store to which the parsed categories and options will be added + public ConfigurationFileStore Store; + + /// Current category options belong to + public Category Category; + + } + + #endregion // class ParserState + /// Parses a configuration file from the specified text reader /// Reader the configuration file will be parsed from /// The configuration file parsed from the specified reader public static ConfigurationFileStore Parse(TextReader reader) { var store = new ConfigurationFileStore(); + var state = new ParserState() { + Store = store, + Category = store.RootCategory + }; for(; ; ) { string line = reader.ReadLine(); if(line == null) { - return store; + break; } - + parseLine(state, line); } + + return store; + } + + /// Incrementally parses a line read from a configuration file + /// Current parser state + /// Line that has been read + private static void parseLine(ParserState state, string line) { + state.Store.lines.Add(line); + + // If the line is empty, ignore it + int length = line.Length; + if(length == 0) { + return; + } + + // Skip all spaces at the beginning of the line + int firstCharacterIndex = 0; + ParserHelper.SkipSpaces(line, ref firstCharacterIndex); + + // If the line contained nothing but spaces, ignore it + if(firstCharacterIndex == length) { + return; + } + + // If the line is a comment, ignore it + if((line[firstCharacterIndex] == '#') || (line[firstCharacterIndex] == ';')) { + return; + } + + // Now the line is either a category definition or some attempt to set an option + if(line[firstCharacterIndex] == '[') { + parseCategory(state, line, firstCharacterIndex); + } else { + parseOption(state, line, firstCharacterIndex); + } + } + + /// Parses a category definition encountered on a line + /// Current parser state + /// Line containing the category definition + /// Index of the definition's first character + private static void parseCategory( + ParserState state, string line, int firstCharacterIndex + ) { + throw new NotImplementedException(); + } + + /// Parses an option definition encountered on a line + /// Current parser state + /// Line containing the option definition + /// Index of the definition's first character + private static void parseOption( + ParserState state, string line, int firstCharacterIndex + ) { + Option option = new Option() { + LineIndex = state.Store.lines.Count - 1 + }; + throw new NotImplementedException(); } /// Determines the best matching type for an option value diff --git a/Source/Configuration/ConfigurationFileStore.cs b/Source/Settings/ConfigurationFileStore.cs similarity index 82% rename from Source/Configuration/ConfigurationFileStore.cs rename to Source/Settings/ConfigurationFileStore.cs index 97f09c5..b4ec07c 100644 --- a/Source/Configuration/ConfigurationFileStore.cs +++ b/Source/Settings/ConfigurationFileStore.cs @@ -24,7 +24,7 @@ using System.IO; using Nuclex.Support.Parsing; -namespace Nuclex.Support.Configuration { +namespace Nuclex.Support.Settings { /// Represents an ini- or cfg-like configuration file /// @@ -44,6 +44,9 @@ namespace Nuclex.Support.Configuration { /// Name of the category as a string public StringSegment CategoryName; + /// Lookup table for the options in this category + public IDictionary OptionLookup; + } #endregion // class Category @@ -71,6 +74,11 @@ namespace Nuclex.Support.Configuration { this.lines = new List(); this.categories = new List(); this.options = new List