Repository navigation
Home
Welcome to the NetChains wiki!
This is designed to serve as the man-page-esque document repository to document the NetChains Language.
Either clone the whole repo for the source, or download the binary at NCI/bin/release/NCI.exe.
NetChains is so-called because it is a direct, scriptable interface to the .NET framework with a chain-y method of constructing commands.
NetChains commands are formed of phrases separated by double colons (::). Phrases fall under one of two types:
- A selection/shift phrase starts with a bang (!) and is the name of an object to 'select'. You can think of selecting as class as moving into its scope. For instance, to use the WriteLine method you would first need to select the Console class with
!Console. NOTE: you cannot select namespaces, only classes/enums/etc. - An access/command phrase allows you to use any of the members/methods in the selected class.
Other notes:
- The parent variable, denoted with a dollar sign ($), allows you to access the most recently returned value in the chain. This is useful for processing user input or passing items from an enum to methods that are expecting them.
The NetChains interpreter assumes that you would like to use the System namespace, and imports it for you. Class selection commands are automatically rooted in System. For example, to use the System.Console class, type !Console (not !System.Console). You can also access objects within sub-namespaces using dot (.) notation (e.g. !Threading.Thread).
To use a member of a class/enum/etc, reference it by (case-sensitive) name. Don't forget to separate commands with the double colon. As an example, to get at the System.ConsoleColor "Red", type !ConsoleColor::Red.
As with members, methods are case-sensitive. Method calls are treated very similarly to member access requests by the interpreter. Thus, their usage is identical. NetChains doesn't care if a method call has brackets/parentheses unless there are arguments that are being passed through (like VB.NET, e.g. !Console::ReadLine::WriteLine($) takes user input and echos it back).
NetChains treats single quotes ('), double quotes ("), and back-ticks (`) very differently. A double quote is demoted to a single quote whenever it is used (on the outside of a quoted block). Single quotes are deleted on use. Back-ticks are persistent. This means that a back-tick will stay intact all the way through the processing of the command. Therefore, !Console::WriteLine(`Hello!`) will output `Hello!`. To output "Hello!", use a single-double (i.e. !Console::WriteLine('"Hello!"'), using just a double quote will output 'Hello!').
The NetChains CLI is designed to be easy to use. As NetChains does not rely on an installer, it is recommended that you add the executable directory to your system path. The NetChains CLI currently supports two arguments.
- To load and run a .net file, use
netchains -p <path>. - To execute a single chain directly, use
netchains -e <chain>.
The interpreter supports basic branching, looping, and testing through the following (non-case-sensitive) pre-execution directives:
- $: a $ followed by the name of a variable and its value (e.g.
$test Hello!) will associate that name with that value anywhere in the code. Note that once a variable has been assigned, the $ is no longer required or even allowed as it would conflict with the parent variable (see above). There is no way to escape these variable keys, so choose names wisely. Variable names are not case-sensitive. If no value is provided, the variable will be auto initialized toTRUE. Variables may also be assigned to the result of a chain, in which case the chain should be quoted by back-ticks (e.g.$input `!Console::ReadLine`). Note: variables are replaced by the preprocesser (bash-style), so make sure to single-double any user supplied data in case it contains spaces.
Side note: If you try and overwrite a variable, the name of the variable will be replaced by its value in the assignment command. - #IF: evaluates whatever follows into a Boolean true/false. This can be a variable name or just the word true/false, but cannot be a math expression (i.e.
#IF TRUEor#IF myVarare okay, but#IF 1 + 1 = 2is not supported). If an undefined variable name (or just random junk) is given, the condition auto-evaluates toFALSE. This allows for C/C++ style#ifdef-type functionality. The following block of code is strongly advised to be indented and must terminate with the commandendon its own line (preferably also indented). - #NAME: must be at top of file. Labels a file with provided name for easier reference. (e.g.
#NAME "Test Script"or#NAME test) - #LOOP: evaluates whatever follows to a number of times to repeat (otherwise throws an error). The code to be repeated is structured as with the #if block detailed above and must terminate with the same
endcommand. - #LOAD (preferred in file)/load (preferred in CLI): loads a script at the provided path but does not execute it. A script name can be specified in the command after the filepath, and will override any
#NAMEdirectives in the file itself. If no name is specified and no#NAMEdirective is included, the name will default to the filename without the rest of the path. - #RUN (preferred in file)/run (preferred in CLI): runs an already loaded script associated with the given name.
- #EXEC (file)/exec (CLI): runs the supplied command with an optional argument.
- Single Quote: '
- Double Quote: "
- Back-Tick: `
- Single-Double: '"
- Back-Single-Double: `'"
- Etc.
- Parent Object / Variable Declaration: $
- Directive Header: #
- Selection Header: !
- Phrase Chain Operator: ::