Reading module arguments from a string

Here’s a fun one. I have a text file on disk… say this file contains text rows like this…

I’m creating a Xojo program which opens this TEXT file and reads in each row of text.
It would be really swell if I could just create a module called “add” that takes two doubles (x,y) and actually just calls the named procedure with the arguments provided.

What I probably have to do is split the string into the function name (operator) and the function parameters (operands), and then use a switch statement on operator to call a module and pass it a string (the operands), then I have to split that string smartly into the individual operands and cast the strings to doubles etc.

This get’s weird when you have a line like
concat(“red, yellow, blue”, “green, orange”)

I am indeed concatenating only TWO strings but intelligently splitting them is a little tricky.
You have to know whether the separator occurs inside quotes or not.
If I could just somehow cast the operands string to the the module argument list, you can see how this resolves all my issues.

Anyone have any interesting ideas on how I can more or less “execute” the named modules in the text file?

I’m thinking maybe executing the line as XojoScript?

Something like this?

Function SplitQuoted(Data As String) As String()
  Dim output() As String
  Dim input As New BinaryStream(Data)
  Dim tmp As String
  Dim quote As Boolean
  Do Until input.EOF
    Dim char As String = input.Read(1)
    Select Case char
    Case " "
      If quote Then
        tmp = tmp + char
        tmp = ""
      End If
    Case """"
      quote = Not quote
      tmp = tmp + char
    End Select
  If tmp.Trim <> "" Then output.Append(tmp)
  Return output
End Function

That’s probably the best route. No need to reinvent the wheel.