by macintux · 5y ago · 0 comments
I think with Regex101 in my back pocket I'll give it another try.
static public List<string> Tokenizer(string source)
{
// Initialise the token list.
List<string> tokens = new List<string>();
// Define a regex pattern whose groups match the MAL syntax.
string pattern = @"[\s ,]*(~@|[\[\]{}()'`~@]|""(?:[\\].|[^\\""])*""|;.*|[^\s \[\]{}()'""`~@,;]*)";
// empty ~@ | specials | double quotes |; | non-specials
// Break the input string into its constituent tokens.
string[] result = Regex.Split(source, pattern);
This took a while to understand and get going but it really improved my understanding of regex.But yeah, that shouldn't be where you get stuck.
Step 0, so I didn't get very far.
https://github.com/kanaka/mal/blob/master/process/guide.md#s...
There are online tools to help visualize regex's. Here is a recent tweet including a visualization of mal's tokenizer regex: https://twitter.com/Mehulwastaken/status/1382292764834996230
It's a big step.
https://github.com/kanaka/mal/blob/master/process/guide.md#s...
I like parsing, I like regexes but I agree it's often a waste of time :)