Here’s a fun one. I have a text file on disk… say this file contains text rows like this…
add(1,2)
subtract(3,9)
mult(5,7)
concat(“dog”,“cat”)
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?