- Joined
- Jan 2, 2014
- Messages
- 1,787
- Reaction score
- 939
- First Language
- Chinese
- Primarily Uses
- N/A
While I don't find much value in the MV plugin commands personally, I'm told that it's more friendly for non coders, and I'd assume so for now.
However, if a MV plugin command looks like a script call and is written in the way similar to writing a script call, then it seems to me that it's just defeating the purpose of MV plugin commands.
So I've thought about what might have a MV plugin command more friendly to non coders, and the following are what I've got so far:
1. A well-written MV plugin command should have a very forgiving syntax(i.e., very low syntax sensitivity)
2. A well-written MV plugin command should look like plain English(i.e., without syntax being foreign to non coders)
For instance, the following is a very well-written script call:
Whereas the following is a MV plugin command counterpart:
While they're virtually the same to me, they might have the following differences to non coders:
1. Script calls are always case-sensitive, while MV plugin commands can be implemented in ways that aren't
2. Script calls have syntax like "(", "," and ")" being foreign to non coders
In my experience, in order for MV plugin commands to be really more friendly to non coders, the regular expressions parsing them must be very well-written.
While it's an easy, simple and small task for easy, simple and small MV plugin commands, the regular expressions can become complicated and convoluted with complicated and convoluted MV plugin commands.
For instance, the following is 1 such plugin command:
With the expected result being something like this:
Plugin command name: pluginCommand
Argument 1: argument1
Argument 2: [argument2Element1, "argument2, Element 2", "argument2,ElementN"]
Argument 3: "argument 3"
Argument 4: "argument4"
(Note the difference between single and double quotes)
As you want it to have very forgiving syntax, you'd have to forgive at least the following:
1. While command names and arguments are supposed to be separated by exactly 1 space, the command should treat multiple consecutive spaces as 1 space
2. While elements in array arguments are supposed to be separated by a comma and nothing more, the command should treat consecutive spaces immediately following a comma as just a comma
3. While string argument values are supposed to be enclosed in single or double quotes(i.e., "String" or 'string'), the command should tolerate errors like "string' or 'string"
4. As it's possible for strings to include commas and/or spaces, those inside single or double quotes shouldn't be treated as separators
5. Consecutive arguments as strings without separators(like 'argument 3'"argument4') should still be separated as 2 arguments
So how long does it take for you to come up with regular expressions that work very well? It took about an hour in my case, and here's my answer(verified in https://regex101.com/):
On a side note: The command name will be converted to be all capital letters to be case-insensitive, and in order for these regular expressions to work, command356 instead of pluginCommand should be extended.
Of course, the command might need to have an even more forgiving syntax, like not limiting the command name and argument separator to be a space, and not limiting the array argument element separator to be a comma. Maybe something like "-", "|", ":" or ";"(with attached consecutive spaces tolerated) should be considered as well.
But the point remains that, it takes a solid understanding on how regular expressions work in details to be able to write such regular expressions, at least quickly(which isn't my case as I took an hour), as the essence of parsing friendly MV plugin commands is to turn plain English with very forgiving grammars into JavaScript data, which involves advanced concepts and techniques that can never be taken lightly.
While I'll want to try even if it's hard, I don't think it's a must, so I think an alternative would be just writing plugin command for easy, simple and small tasks, and reserve the complicated and convoluted ones to be script calls only.
So these are my 2 cents on writing regular expressions to parse MV plugin commands that are supposed to be very friendly to non coders.
I'd like to know yours as well, so maybe we can collect some wisdom here, even though it's going to be a thing in the past in MZ
However, if a MV plugin command looks like a script call and is written in the way similar to writing a script call, then it seems to me that it's just defeating the purpose of MV plugin commands.
So I've thought about what might have a MV plugin command more friendly to non coders, and the following are what I've got so far:
1. A well-written MV plugin command should have a very forgiving syntax(i.e., very low syntax sensitivity)
2. A well-written MV plugin command should look like plain English(i.e., without syntax being foreign to non coders)
For instance, the following is a very well-written script call:
JavaScript:
setSATBActTimes(actorId, actTimes)
Code:
setSATBActTimes actorId actTimes
1. Script calls are always case-sensitive, while MV plugin commands can be implemented in ways that aren't
2. Script calls have syntax like "(", "," and ")" being foreign to non coders
In my experience, in order for MV plugin commands to be really more friendly to non coders, the regular expressions parsing them must be very well-written.
While it's an easy, simple and small task for easy, simple and small MV plugin commands, the regular expressions can become complicated and convoluted with complicated and convoluted MV plugin commands.
For instance, the following is 1 such plugin command:
JavaScript:
pluginCommand argument1 argument2Element1,"argument2, Element 2", "argument2,ElementN' 'argument 3'"argument4'
Plugin command name: pluginCommand
Argument 1: argument1
Argument 2: [argument2Element1, "argument2, Element 2", "argument2,ElementN"]
Argument 3: "argument 3"
Argument 4: "argument4"
(Note the difference between single and double quotes)
As you want it to have very forgiving syntax, you'd have to forgive at least the following:
1. While command names and arguments are supposed to be separated by exactly 1 space, the command should treat multiple consecutive spaces as 1 space
2. While elements in array arguments are supposed to be separated by a comma and nothing more, the command should treat consecutive spaces immediately following a comma as just a comma
3. While string argument values are supposed to be enclosed in single or double quotes(i.e., "String" or 'string'), the command should tolerate errors like "string' or 'string"
4. As it's possible for strings to include commas and/or spaces, those inside single or double quotes shouldn't be treated as separators
5. Consecutive arguments as strings without separators(like 'argument 3'"argument4') should still be separated as 2 arguments
So how long does it take for you to come up with regular expressions that work very well? It took about an hour in my case, and here's my answer(verified in https://regex101.com/):
Separating command names and arguments -
Separating array argument elements -
Eliminating strings like "string' or 'string" -
JavaScript:
match(/(?:[^'", ]+|['"][^'"]*['"])(?:, *(?:[^'", ]+|['"][^'"]*['"]))*/gim)
JavaScript:
match(/[^'", ]+|['"][^'"]*['"]/gim)
JavaScript:
replace("'", "\"")
Of course, the command might need to have an even more forgiving syntax, like not limiting the command name and argument separator to be a space, and not limiting the array argument element separator to be a comma. Maybe something like "-", "|", ":" or ";"(with attached consecutive spaces tolerated) should be considered as well.
But the point remains that, it takes a solid understanding on how regular expressions work in details to be able to write such regular expressions, at least quickly(which isn't my case as I took an hour), as the essence of parsing friendly MV plugin commands is to turn plain English with very forgiving grammars into JavaScript data, which involves advanced concepts and techniques that can never be taken lightly.
While I'll want to try even if it's hard, I don't think it's a must, so I think an alternative would be just writing plugin command for easy, simple and small tasks, and reserve the complicated and convoluted ones to be script calls only.
So these are my 2 cents on writing regular expressions to parse MV plugin commands that are supposed to be very friendly to non coders.
I'd like to know yours as well, so maybe we can collect some wisdom here, even though it's going to be a thing in the past in MZ
Last edited:

