Importing a list of tokens from one transformer to another
ID: 167
See: Add(Tokens), Clear
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
// This creates a simpler (not very useful) set of tokens for sake of example
var MyTokens = t.Tokens;
MyTokens.Clear(); // removes the default list of tokens
MyTokens.Add("."); // Should always have a fallback token like this one
MyTokens.Add(";", TokenType.StatementSep);
MyTokens.Add("<", TokenType.Generic, ">");
MyTokens.Add("[0-9]+", TokenType.Literal);
MyTokens.Add(" +", TokenType.Whitespace);
MyTokens.Add("[a-z]+", TokenType.AlphaNumeric);
t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep
Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC"));
Console.WriteLine("");
var OtherTransform = new uCalc.Transformer(uc); // This is an alternative way of constructing a new transformer
OtherTransform.Tokens.Add(MyTokens); // Imports the entire token list from the other transformer
OtherTransform.Pattern("{word:1}");
Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text);
[This is a test]; [That < 123.456; abc >]; ABC
This
is
a
test
;
That
<
123
.
456
;
abc
>
;
ABC using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); // This creates a simpler (not very useful) set of tokens for sake of example var MyTokens = t.Tokens; MyTokens.Clear(); // removes the default list of tokens MyTokens.Add("."); // Should always have a fallback token like this one MyTokens.Add(";", TokenType.StatementSep); MyTokens.Add("<", TokenType.Generic, ">"); MyTokens.Add("[0-9]+", TokenType.Literal); MyTokens.Add(" +", TokenType.Whitespace); MyTokens.Add("[a-z]+", TokenType.AlphaNumeric); t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC")); Console.WriteLine(""); var OtherTransform = new uCalc.Transformer(uc); // This is an alternative way of constructing a new transformer OtherTransform.Tokens.Add(MyTokens); // Imports the entire token list from the other transformer OtherTransform.Pattern("{word:1}"); Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
// This creates a simpler (not very useful) set of tokens for sake of example
auto MyTokens = t.Tokens();
MyTokens.Clear(); // removes the default list of tokens
MyTokens.Add("."); // Should always have a fallback token like this one
MyTokens.Add(";", TokenType::StatementSep);
MyTokens.Add("<", TokenType::Generic, ">");
MyTokens.Add("[0-9]+", TokenType::Literal);
MyTokens.Add(" +", TokenType::Whitespace);
MyTokens.Add("[a-z]+", TokenType::AlphaNumeric);
t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep
cout << t.Transform("This is a test; That < 123.456; abc >; ABC") << endl;
cout << "" << endl;
uCalc::Transformer OtherTransform(uc); // This is an alternative way of constructing a new transformer
OtherTransform.Tokens().Add(MyTokens); // Imports the entire token list from the other transformer
OtherTransform.Pattern("{word:1}");
cout << OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches().Text() << endl;
}
[This is a test]; [That < 123.456; abc >]; ABC
This
is
a
test
;
That
<
123
.
456
;
abc
>
;
ABC #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); // This creates a simpler (not very useful) set of tokens for sake of example auto MyTokens = t.Tokens(); MyTokens.Clear(); // removes the default list of tokens MyTokens.Add("."); // Should always have a fallback token like this one MyTokens.Add(";", TokenType::StatementSep); MyTokens.Add("<", TokenType::Generic, ">"); MyTokens.Add("[0-9]+", TokenType::Literal); MyTokens.Add(" +", TokenType::Whitespace); MyTokens.Add("[a-z]+", TokenType::AlphaNumeric); t.FromTo("{ This | That} {etc}", "[{@Self}]"); // {etc} stops at the semicolon ";" TokenType.StatementSep cout << t.Transform("This is a test; That < 123.456; abc >; ABC") << endl; cout << "" << endl; uCalc::Transformer OtherTransform(uc); // This is an alternative way of constructing a new transformer OtherTransform.Tokens().Add(MyTokens); // Imports the entire token list from the other transformer OtherTransform.Pattern("{word:1}"); cout << OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches().Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
'// This creates a simpler (not very useful) set of tokens for sake of example
Dim MyTokens = t.Tokens
MyTokens.Clear() '// removes the default list of tokens
MyTokens.Add(".") '// Should always have a fallback token like this one
MyTokens.Add(";", TokenType.StatementSep)
MyTokens.Add("<", TokenType.Generic, ">")
MyTokens.Add("[0-9]+", TokenType.Literal)
MyTokens.Add(" +", TokenType.Whitespace)
MyTokens.Add("[a-z]+", TokenType.AlphaNumeric)
t.FromTo("{ This | That} {etc}", "[{@Self}]") '// {etc} stops at the semicolon ";" TokenType.StatementSep
Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC"))
Console.WriteLine("")
Dim OtherTransform As New uCalc.Transformer(uc) '// This is an alternative way of constructing a new transformer
OtherTransform.Tokens.Add(MyTokens) '// Imports the entire token list from the other transformer
OtherTransform.Pattern("{word:1}")
Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text)
End Sub
End Module
[This is a test]; [That < 123.456; abc >]; ABC
This
is
a
test
;
That
<
123
.
456
;
abc
>
;
ABC Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() '// This creates a simpler (not very useful) set of tokens for sake of example Dim MyTokens = t.Tokens MyTokens.Clear() '// removes the default list of tokens MyTokens.Add(".") '// Should always have a fallback token like this one MyTokens.Add(";", TokenType.StatementSep) MyTokens.Add("<", TokenType.Generic, ">") MyTokens.Add("[0-9]+", TokenType.Literal) MyTokens.Add(" +", TokenType.Whitespace) MyTokens.Add("[a-z]+", TokenType.AlphaNumeric) t.FromTo("{ This | That} {etc}", "[{@Self}]") '// {etc} stops at the semicolon ";" TokenType.StatementSep Console.WriteLine(t.Transform("This is a test; That < 123.456; abc >; ABC")) Console.WriteLine("") Dim OtherTransform As New uCalc.Transformer(uc) '// This is an alternative way of constructing a new transformer OtherTransform.Tokens.Add(MyTokens) '// Imports the entire token list from the other transformer OtherTransform.Pattern("{word:1}") Console.WriteLine(OtherTransform.Filter("This is a test; That < 123.456; abc >; ABC").Matches.Text) End Sub End Module