hrszpuk / odin-ini

:fire: An easy to use and highly customizable INI serialiser/deserialiser for Odin!
MIT License
1 stars 0 forks source link

Implement `Options` configuration into parser, lexer, erroring, and serializer #14

Open hrszpuk opened 5 months ago

hrszpuk commented 5 months ago
hrszpuk commented 2 months ago

As of v0.2.1 the current options struct looks like this:

niOptions :: struct {
    Syntax: struct {
        AllowEmptyValues: bool,         // Whether empty values are allowed or not (default: true)
        AllowEmptySections: bool,       // Whether empty sections are allowed or not (default: true)
        AllowQuotedValues: bool,        // Whether quoted values are allowed or not (default: true)
        AllowNestedSections: bool,      // Whether nested sections are allowed or not (default: true)

        IgnoreCaseSensitivity: bool,    // Whether case sensitivity is ignored or not (default: false)
        IgnoreDuplicateKeys: bool,      // Whether duplicate keys are ignored or not (default: false)
        IgnoreDuplicateSections: bool,  // Whether duplicate sections are ignored or not (default: false)
        IgnoreDelimiterPadding: bool,   // Whether delimiter padding is ignored or not (default: true)
        IgnoreSectionNamePadding: bool, // Whether section name padding is ignored or not (default: true)

        NestedSectionSymbol: rune,      // Nested section symbol (default: '.')
    },

    Parsing: struct {
        ParseComments: bool,            // Whether comments are parsed or not (default: false)
        Multithreading: bool,           // Whether parsing is multithreaded or not (default: false)
    },

    Serialization: struct {
        SerializeComments: bool,        // Whether comments are serialized or not (default: false)
        PadDelimiters: bool,            // Whether delimiters are padded or not (default: false)
        ForceQuotes: bool,              // Whether values are forced to be quoted or not (default: false)
        QuoteEmptyValues: bool,         // Whether empty values are quoted or not (default: false)
        RemoveEmptyValues: bool,        // Whether empty values are removed or not (default: false)
        Multithreading: bool,           // Whether serialization is multithreaded or not (default: false)
    },

    ErrorHandling: struct {
        Mode: ErrorMode,                // Error handling mode (default: ErrorMode.WARN_ON_ERROR)
        PrintErrors: bool,              // Whether errors are printed or not (default: false)
        Output: bufio.Writer,           // Output writer for errors (default: os.Stderr)
    },

    Debug: bool,                        // Debugging mode will print debug information (default: false)
}

I may simplify some of the options, like disable comments requires setting 2 bools when it could just be 1, and remove the categories so its just a struct of all options.

hrszpuk commented 2 months ago

v0.3.0 has changed the options struct. It now looks like


// Ini is not standardised. Therefore I've given the programmer the ability to interchange symbols and rules.
IniOptions :: struct {

    // Symbols
    // - These are the symbols used during (de)serialisation.
    Symbols: struct {
        Delimiter: rune,          // Delimiter symbol (default: '=')
        Comment: rune,            // Comment symbol (default: ';')
        SectionLeft: rune,        // Section left symbol (default: '[')
        SectionRight: rune,       // Section right symbol (default: ']')
        NestedSection: rune,      // Nested section symbol (default: '.')

        // Examples:
        // [section]
        // key = value
        // [nested.section]
        // ; this is a comment
    },

    // Rules
    // - Allows you to allow/disallow/ignore certain rules.
    Rules: struct {
        // If you are reading these rules and think there are more that could be added open an issue (https://github.com/hrszpuk/odin-ini)

        AllowEmptyValues: bool,         // Whether empty values are allowed or not (default: true)
        AllowEmptySections: bool,       // Whether empty sections are allowed or not (default: true)
        AllowNestedSections: bool,      // Whether nested sections are allowed or not (default: true)
        AllowSpacesInKeys: bool,        // Whether spaces are allowed to be a part of keys or not (default: false)
        AllowSpacesInValues: bool,      // Whether spaces are allowed to be a part of values or not (default: true)

        IgnoreCaseSensitivity: bool,    // Whether case sensitivity is ignored or not (default: false)
        IgnoreDuplicateKeys: bool,      // Whether duplicate keys are ignored or not (default: false)
        IgnoreDuplicateSections: bool,  // Whether duplicate sections are ignored or not (default: false)
        IgnoreDelimiterPadding: bool,   // Whether delimiter padding is ignored or not (default: true)
        IgnoreSectionNamePadding: bool, // Whether section name padding is ignored or not (default: true)
        IgnoreValueQuotes: bool,        // Whether the quotes around a value are counted as part of the value or not (default: true)
    },

    Debug: bool,    // Debugging mode will print debug information (default: false)
}