KSPMMCfgParser 1.0.8

dotnet add package KSPMMCfgParser --version 1.0.8                
NuGet\Install-Package KSPMMCfgParser -Version 1.0.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KSPMMCfgParser" Version="1.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KSPMMCfgParser --version 1.0.8                
#r "nuget: KSPMMCfgParser, 1.0.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KSPMMCfgParser as a Cake Addin
#addin nuget:?package=KSPMMCfgParser&version=1.0.8

// Install KSPMMCfgParser as a Cake Tool
#tool nuget:?package=KSPMMCfgParser&version=1.0.8                

Kerbal Space Program Module Manager Config File Parser

Validator

The validator is a small command line tool that finds cfg files, parses them, and reports syntax errors. It can be used as a GitHub Action/Workflow or as a standalone utility. The validator returns success (0) if no syntax errors are found, or failure (2) otherwise.

Configuring on GitHub

To validate all of the cfg files in a GitHub repo every time they change, add a file called .github/workflows/validate-cfg.yml to your repo containing:

name: Config file validation
on:
  push:
    branches:
      - master
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
jobs:
  validate:
    name: Validate cfg files
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - name: Validate config files
        uses: KSP-CKAN/KSPMMCfgParser@master

The results will appear in the Actions tab, as annotations in the Files changed tab of pull requests, and probably also in your email inbox.

Standalone

You may pass zero or more parameters to the validator. If you pass no parameters, it will scan the current working directory recursively. If you pass the name of a file, it will scan that file. If you pass the name of a directory, it will scan that directory recursively.

The file, line, and column of each syntax error will be reported, one per line:

> KSPMMCfgValidator.exe UnKerballedStart
UnKerballedStart\Mod Support\Breaking_Ground.cfg:48:1: Unexpected '@<0x40>'
UnKerballedStart\Mod Support\CNAR.cfg:164:1: Unexpected '<EndOfStream>'
UnKerballedStart\Mod Support\InterstellarExtended.cfg:3:1: Unexpected '<EndOfStream>'
UnKerballedStart\Mod Support\knes.cfg:1:1: Unexpected '/<0x2F>'
UnKerballedStart\Mod Support\Luciole.cfg:1:1: Unexpected '/<0x2F>'
UnKerballedStart\Mod Support\NovaPunch.cfg:178:1: Unexpected '[<0x5B>'
UnKerballedStart\Mod Support\Orion.cfg:1:1: Unexpected '/<0x2F>'
UnKerballedStart\Mod Support\reDIRECT.cfg:1:1: Unexpected '/<0x2F>'
UnKerballedStart\Mod Support\SOCK.cfg:1:1: Unexpected '/<0x2F>'
UnKerballedStart\Mod Support\TACSelfDestruct.cfg:25:1: Expected '<EndOfStream>' but was '/<0x2F>'
UnKerballedStart\Mod Support\X-20.cfg:1:1: Unexpected '/<0x2F>'

See also

If you host your own CKAN metanetkan, you can validate it with:

https://github.com/KSP-CKAN/xKAN-meta_testing

Consider validating your version file as well:

https://github.com/DasSkelett/AVC-VersionFileValidator

Parser

The KSPMMCfgParser project provides a monadic parser for Kerbal Space Program / Module Manager config files. It turns a string or a Stream containing KSP/ModuleManager config file data into a sequence of KSPConfigNode objects, and you can also use it to find syntax errors.

Installing

NuGet:

nuget install KSPMMCfgParser

The equivalent dotnet command might also work, but we don't use those tools for CKAN currently so I haven't tested it.

Or you can add this to your csproj:

<ItemGroup>
  <PackageReference Include="ParsecSharp" Version="3.4.0" />
  <PackageReference Include="KSPMMCfgParser" Version="1.0.5" />
</ItemGroup>

Remember to tell MSBuild to download it:

msbuild -r

Using

See the code for the validator for a full working example; here's a more concise excerpt:

using System;
using System.IO;
using System.Linq;

using ParsecSharp;

using KSPMMCfgParser;
using static KSPMMCfgParser.KSPMMCfgParser;

namespace KSPMMCfgExample
{
    public class KSPMMCfgExample
    {
        public static int Main(string[] args)
        {
            ConfigFile.Parse(File.Open(args[0], FileMode.Open))
                      .CaseOf(failure =>
                              {
                                  Console.WriteLine("{0}:{1}:{2}: {3}",
                                                    args[0],
                                                    failure.State.Position.Line,
                                                    failure.State.Position.Column,
                                                    failure.Message);
                                  return Enumerable.Empty<KSPConfigNode>();
                              },
                              success => success.Value);
        }
    }
}

The success.Value variable at the end contains the sequence of KSPConfigNode objects from the file.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8 218 12/20/2023
1.0.7 436 8/15/2022
1.0.6 453 4/30/2022
1.0.5 433 4/29/2022
1.0.4 445 4/29/2022
1.0.3 423 4/28/2022
1.0.2 403 4/28/2022
1.0.1 425 4/28/2022
1.0.0 436 4/22/2022