Background
I am currently writing a function which needs to accept a command as a string. The string needs to be split into it's finer parts so that the function may then use those parts. Here is an example string:
People.filter(Hometown.eq("Pittsburgh"))
Which, in this simplified example, I would need to resolve to something like:
var objectToTraverse = "People";
var actionToTake = "filter";
var comparer = "Hometown";
var targetValue = "Pittsburgh";
For the example above, the split operation is fairly easy:
var _command = "People.filter(Hometown.eq("Pittsburgh"))";
var command = _command.split(".");
var objectToTraverse = command[0];
var actionToTake = command[1].split("(")[0];
var comparer = command[1].split("(")[1];
var targetValue = command[2].split("(")[1].split(")")[0];
But what if you have a more complex command such as this:
People.filter(Hometown.eq("Pittsburgh") && Gender.eq("male") || Age.eq(>= 35)).orderBy(Age,Gender).limitResultSet(10)
The pattern may be different each time.
Question
Using JavaScript, how do I efficiently parse a string-command based on various mixed delimiters and conditions such as this:
People.filter(Hometown.eq("Pittsburgh") && Gender.eq("male") || Age.eq(>= 35)).orderBy(Age,Gender).limitResultSet(10)
Please Note
I am aware of all of the frameworks available already for querying data in JavaScript and, while I appreciate all tips and advice, I would still like an answer to this question regardless of what else is available out there.