Click here to Skip to main content
15,034,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am currently using Basic Sharp link: https://github.com/Timu5/BasicSharp
This is a basic language interpreter. We need to use merge fields in this code to replace mergefields with values.

For example:
IF {Clients.Name} = "Patrick" THEN
#Do something
ENDIF
the merge field needs to be setup as a token and then it's value parsed and replaced depending on its type.

so the above would be parsed and replaced like so:
IF "Patrick" = "Patrick" THEN
#Do Something
ENDIF
Any help would be much appreciated, I am available to go through this in more detail on a screenshare if this would help!

What I have tried:

I have tried the below code from the interpreter, as it parses line by line. This is one of the requirements. As this can be used in the DO While loop, where the database value can change:
C#
void Line()
    {
        string lineText = GetLine();
       // MessageBox.Show(lineText);
        string regularExpressionPattern = @"\[.*?\]";

        string inputText = lineText;
        int intVal = 0;
        double Double123 = 0.00;
        Regex re = new Regex(regularExpressionPattern);
        string finalvalue = "";
        Run_Code rc = new Run_Code();
        rc.case_ref = case_ref;
        rc.CaseTypeIndex = CaseTypeIndex;
        foreach (Match m in re.Matches(inputText))
        {
            inputText = inputText.Replace(m.Value,'"' + rc.getDBValue(m.Value.Replace("[", "").Replace("]", "")) + '"');
        }
        // skip empty new lines
        while (lastToken == Token.NewLine) GetNextToken();

        if (lastToken == Token.EOF)
        {
            exit = true;
            return;
        }

        lineMarker = lex.TokenMarker; // save current line marker
        Statment(); // evaluate statment

        if (lastToken != Token.NewLine && lastToken != Token.EOF)
            Error("Expect new line got " + TranslateToken(lastToken.ToString()));
    }
Posted
Updated 20-Oct-20 9:13am
v2

1 solution

Why don't you use a "proper" (replacement) token like $CLIENT or something (instead of a variable name). e.g.

...Replace( "$CLIENT", xxx ).

(And read the whole text file into a string; instead of line by line).
   
Comments
patrickb123 21-Oct-20 4:19am
   
This was the way i was previously dealing with this issue, however now that i have created the Do While loop, it does not work as it will run forever if i ran the following code:

WHILE {Client.Name} <> "Patrick" DO
UPDATE({Client.Name}, "Patrick")
ENDLOOP

as it would just get replaced with the current value, which can change in loops etc...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900