Term is a simple interpreter that can convert key-value pairs defined in text to C# dictionaries.
You can find here:
<!> This guide assumes that your project contains a csproj file.
First, you have to download the Term.zip zip file from the latest release.
Once it's downloaded, unzip it.
There's also another method you could use, see it here.
Once you have the unzipped folder, place it inside your project.
Next, you have to add a reference to the file (Term.dll).
To do that, add this to your csproj:
<ItemGroup>
<Reference Include="Term">
<HintPath>PATH/TO/TERM.dll</HintPath>
</Reference>
</ItemGroup><!> Replace "PATH/TO/TERM.dll" with the path where the
dllis in your project.
<!> If you're using Visual Studio, you can add the reference via Visual Studio's GUI.
That's it! You've successfully finished the setup. Continue in the docs.
Any problems during the setup? Check the setup guide again. Still have problems? Post an issue so I can help you!
Jump to the example.
namespace Term;namespace Term;
public static class TermInterpreter { }The interpreter itself.
Methods:
-
public static Dictionary<string, string> Interpret(string path)
The Interpreter's method.
Thismethod reads aTermfile located at a specified path andreturnsaDictionarycontaining the keys and values that were found.-
path
Type:string
Description: The absolute path to the file that will be interpreted.
-
A dictionary containing the keys and values that were found in the file.
new Dictionary<string, string>
-
-
public static void WriteToFile(string path, Dictionary<string, string> termContent, bool replaceContent = true)
Writes a
dictionaryinto a term file.It automatically generates
Term configsbased on the dictionary provided.The method will also format correctly any key in the dictionary. So if the dictionary contains a key named "
My Key" it will be formatted to "my_key" before writing it to the file.-
path
Type:string
Description: The absolute path to the term file to write into.termContent
Type:Dictionary<string, string>
Description: The content that will be written in the file.replaceContent
Type:bool
Description: Iftrue, replace all the contents in the term file.
iffalse, append all the contents to the end of the file with a comment "# Written from C#:".
This parameter is optional. Defaults totrue.
-
-
Comments in
Termare really simple.Every line starting with a
#it's a comment and it's going to be ignored by theInterpreter.Example:
# This is a comment -
Configs are made of key-value pairs.
A
configis how we call these key-value pairs inTerm.The key is separated from the value by this symbol:
->Example:
my_key -> My valueIt's important that these
configsare declared on a single line, otherwise it can cause errors.
- Any empty line found in the
Termfile is going to be ignored by theInterpreter. - The keys should be named using
snake_case. stringvalues don't need to be surrounded by"".
Let's code a simple example using Term.
Assuming we already created a dotnet project and we did the setup...
First, let's start by creating our Term file and writing some configs:
# Epic configs going here
# Window
window_title -> My Window
window_color -> LIMEGREEN
# User
username -> YisusGaming
epic_stuff -> Yes it's epic
Now, let's save this file, in my case, I'm saving the Term file next to my Program.cs file.
The file structure is something like this:
Project Folder
| Program.cs
| Term.dll
| test.term
| project.csproj
Note:
test.termis the name I gave to the file.
Ok, let's go into the Program.cs.
First, we have to make sure the Term namespace is being use in the C# file:
using Term;That way, we can use the Interpret method from the TermInterpreter class.
Now, the Interpret method needs one argument: The path to the file that will be interpreted. In order to give it the path, we can use the Path.GetFullPath() method included in C#.
In my case, It will be something like this:
string path = Path.GetFullPath("test.term");Note: This is inside of
C#'sMainmethod.
We call Path.GetFullPath and we pass in the path to our Term file, relative to the project's folder.
<!> Remember: The file structure in this example is like this.
Now that we got the Term's file path, we can call TermInterpreter.Interpret and give it the path!
Dictionary<string, string> load = TermInterpreter.Interpret(path);Notice that, I'm creating a variable called
loadto store theDictionarythat this method returns.
And we're done! The Interpret method does everything for us and returns a Dictionary with the keys and values in our term file!
That means: Now we can access these values using the keys.
For example: We can now access the config we created before called window_title and print the value in console:
Console.WriteLine(load["window_title"]);<!> Remember:
loadwas the name I give to myDictionarywith all the keys and values.
And should print us the value of window_title!
Full code of the Example:
using System;
using System.Collections.Generic;
using Term;
namespace MyProgram
{
class Program
{
public static void Main(string[] args)
{
string path = Path.GetFullPath("test.term"); // Get the full path from a path relative to our project's folder
Dictionary<string, string> load = TermInterpreter.Interpret(path); // Interpret the file
Console.WriteLine(load["window_title"]); // Should print the value!
}
}
}-
You may get errors by trying to accessing a keys that isn't in the returned dictionary. This can happen for reasons like the key being not defined at the term file.
You can manage these errors as you want.
Any problems during the example? Check the example again. Still have problems? Post an issue so I can help you!
- Arithmetic operations in
Termvalues.

Term by YisusGaming is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
