Getting started
9/24/25Less than 1 minute
First, you need to create a dotnet project and install the RCParsing
NuGet package using one of these commands:
dotnet add package RCParsing
Install-Package RCParsing
Then paste and run this code:
using RCParsing;
// First, you need to create a builder
var builder = new ParserBuilder();
// Enable and configure the auto-skip for 'Whitespaces' (you can replace it with any other rule)
builder.Settings.SkipWhitespaces();
// Create a main sequential expression rule
builder.CreateMainRule("expression")
.Number<double>()
.LiteralChoice("+", "-")
.Number<double>()
.Transform(v => {
var value1 = v.GetValue<double>(index: 0);
var op = v.GetValue<string>(index: 1);
var value2 = v.GetValue<double>(index: 2);
return op == "+" ? value1 + value2 : value1 - value2;
});
// Build the parser
var parser = builder.Build();
// Parse a string using 'expression' rule and get the raw AST (value will be calculated lazily)
var parsedRule = parser.Parse("10 + 15");
// We can now get the value from our 'Transform' functions (value calculates now)
var transformedValue = parsedRule.GetValue<double>();
// Outputs: 25
Console.WriteLine(transformedValue);
Wanna see more? Go to the tutorials!