A simple example showing how to extract a value from a nested configuration block.
ID: 939
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.Text = "Config { setting = 123; }";
// 1. Define the parent rule to capture the content inside the braces.
var parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false);
// 2. Get the local transformer for the parent rule.
var local_t = parentRule.LocalTransformer;
// 3. Define a rule that operates ONLY on the text captured by '{body}'.
local_t.FromTo("setting = {val}", "Found Value: {val}");
// 4. Perform the transformation.
// The local rule will run on the text " setting = 123; ".
t.Transform();
Console.WriteLine(t.Text);
Config { Found Value: 123; } using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.Text = "Config { setting = 123; }"; // 1. Define the parent rule to capture the content inside the braces. var parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false); // 2. Get the local transformer for the parent rule. var local_t = parentRule.LocalTransformer; // 3. Define a rule that operates ONLY on the text captured by '{body}'. local_t.FromTo("setting = {val}", "Found Value: {val}"); // 4. Perform the transformation. // The local rule will run on the text " setting = 123; ". t.Transform(); Console.WriteLine(t.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.Text("Config { setting = 123; }");
// 1. Define the parent rule to capture the content inside the braces.
auto parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false);
// 2. Get the local transformer for the parent rule.
auto local_t = parentRule.LocalTransformer();
// 3. Define a rule that operates ONLY on the text captured by '{body}'.
local_t.FromTo("setting = {val}", "Found Value: {val}");
// 4. Perform the transformation.
// The local rule will run on the text " setting = 123; ".
t.Transform();
cout << t.Text() << endl;
}
Config { Found Value: 123; } #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.Text("Config { setting = 123; }"); // 1. Define the parent rule to capture the content inside the braces. auto parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false); // 2. Get the local transformer for the parent rule. auto local_t = parentRule.LocalTransformer(); // 3. Define a rule that operates ONLY on the text captured by '{body}'. local_t.FromTo("setting = {val}", "Found Value: {val}"); // 4. Perform the transformation. // The local rule will run on the text " setting = 123; ". t.Transform(); cout << t.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.Text = "Config { setting = 123; }"
'// 1. Define the parent rule to capture the content inside the braces.
Dim parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false)
'// 2. Get the local transformer for the parent rule.
Dim local_t = parentRule.LocalTransformer
'// 3. Define a rule that operates ONLY on the text captured by '{body}'.
local_t.FromTo("setting = {val}", "Found Value: {val}")
'// 4. Perform the transformation.
'// The local rule will run on the text " setting = 123; ".
t.Transform()
Console.WriteLine(t.Text)
End Sub
End Module
Config { Found Value: 123; } Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.Text = "Config { setting = 123; }" '// 1. Define the parent rule to capture the content inside the braces. Dim parentRule = t.Pattern("Config '{' {body} '}'").SetStatementSensitive(false) '// 2. Get the local transformer for the parent rule. Dim local_t = parentRule.LocalTransformer '// 3. Define a rule that operates ONLY on the text captured by '{body}'. local_t.FromTo("setting = {val}", "Found Value: {val}") '// 4. Perform the transformation. '// The local rule will run on the text " setting = 123; ". t.Transform() Console.WriteLine(t.Text) End Sub End Module