Skip to content
Snippets Groups Projects
Select Git revision
  • 98158b32301f91f6af2239f77c07fa679285fe0d
  • master default
2 results

ConfigParser.cs

Blame
  • ConfigParser.cs 15.10 KiB
    // i3csstatus - Alternative generator of i3 status bar written in c#
    // (c)   2022 Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
    
    // This program is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License, or
    // any later version.
    
    // This program 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
    // GNU General Public License for more details.
    
    // You should have received a copy of the GNU General Public License
    // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    
    #nullable enable
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    using System.IO;
    
    using System.Linq;
    
    using Color = System.Drawing.Color;
    
    namespace Config;
    
    abstract class ConfigException: Exception
    {
    	public ConfigParser Parser;
    	internal ConfigException(ConfigParser parser)
    	{
    		Parser = parser;
    	}
    	public override string ToString()
    	{
    		return $"Mistake in config: {ErrorString()}";
    	}
    	abstract public string ErrorString();
    }
    abstract class ConfigDuplicitException: ConfigException
    {
    	public string Name;
    	public int LineA, LineB;
    	public ConfigDuplicitException(ConfigParser parser, string name, int lineA, int lineB): base(parser)
    	{
    		Name = name;
    		LineA = lineA;
    		LineB = lineB;
    	}
    }
    class ConfigDuplicitSectionException: ConfigDuplicitException
    {
    	public ConfigDuplicitSectionException(ConfigParser parser, string name, int lineA, int lineB)
    		:base(parser, name, lineA, lineB){}
    	public override string ErrorString()
    	{
    		return $"Duplicit section name {Name} on lines {LineA}, {LineB}";
    	}
    }
    class ConfigDuplicitKeyException: ConfigDuplicitException
    {
    	public ConfigDuplicitKeyException(ConfigSection section, string name, int lineA, int lineB)
    		:base(section.Root, name, lineA, lineB){}
    	public override string ErrorString()
    	{
    		return $"Duplicit key name {Name} on lines {LineA}, {LineB}";
    	}