SystemCall 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SystemCall --version 1.1.0                
NuGet\Install-Package SystemCall -Version 1.1.0                
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="SystemCall" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SystemCall --version 1.1.0                
#r "nuget: SystemCall, 1.1.0"                
#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 SystemCall as a Cake Addin
#addin nuget:?package=SystemCall&version=1.1.0

// Install SystemCall as a Cake Tool
#tool nuget:?package=SystemCall&version=1.1.0                

System Call

NuGet

System Call is a command-parsing .NET library inspired by Jinx and named after Sword Art Online.

It uses natural language syntax and is intended for use in command line interfaces and magic systems.

using SystemCall;

// Define commands
Command[] Commands = [
    new("enhance_weapon", "enhance my {weapon}(!)"),
];

// Run commands
string? RunCommand(CommandCall Call) {
    switch (Call.Command.Name) {
        case "enhance_weapon":
            return $"Weapon enhanced: {Call.GetArgument<string>("weapon")}";
        default:
            return null;
    }
}

// Call commands
CommandCallParser.Interpret("Enhance my 'Sword'!", Commands, RunCommand);

Arguments are parsed as Hjson, which is a flexible superset of JSON.

Defining Commands

Commands can be defined using a format string:

Command[] Commands = [
    new("enhance_weapon", "enhance my {weapon}(!)"),
];

Format strings use the following syntax:

  • A sequence of tokens in brackets may be entirely omitted: (optional tokens)
  • A token in curly brackets is the name of an argument: {username}
  • A list of sequences of tokens in square brackets is a list of choices: [vanilla, chocolate, strawberry and cream]
  • Any token can be escaped with a backslash: not a bracket \(

Alternatively, commands can be manually constructed:

Command[] Commands = [
    new("enhance_weapon", [
        new CommandLiteralComponent("enhance my"),
        new CommandArgumentComponent("weapon"),
        new CommandOptionalComponent([
            new CommandLiteralComponent("!"),
        ]),
    ]),
];

Calling Commands

Commands can be parsed into a list of calls:

List<CommandCall> Calls = CommandCallParser.ParseCalls("enhance my 'Sword'!", Commands);

Alternatively, commands can be parsed and interpreted, returning the output:

string? RunCommand(CommandCall Call) {
    switch (Call.Command.Name) {
        case "enhance_weapon":
            return $"Weapon enhanced: {Call.GetArgument<string>("weapon")}";
        default:
            return null;
    }
}

string Output = CommandCallParser.Interpret("Enhance my 'Sword'!", Commands, RunCommand);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  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 is compatible.  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.  net9.0 is compatible. 
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.2.0 72 11/24/2024
1.1.0 63 11/24/2024
1.0.0 73 11/13/2024