I think it works, but I'm definitely no regular expression wizard. The regex that finds the tokens can probably be improved a thousandfold, so if you have any suggestions for improvements, please post them!
fsw wrote:Nice one.
The Regular Expression Library simplifies things a lot.
fsw
hehe, are you kidding? That particular RegExp looks like my dog's breakfast after it has been thrown up all over the kitchen floor!
No offence eesau, looks like some very slick code there; I just hate reg exps! Not sure that using a reg exp for anything but a very simple tokeniser would be suitable; too slow probably. I wait to be corrected though on that score as my knowledge of reg exps is about on a par with my knowledge of nuclear physics - a bit sketchy at best!
I may look like a mule, but I'm not a complete ass.
srod wrote:That particular RegExp looks like my dog's breakfast after it has been thrown up all over the kitchen floor!
Understatement of the year
No offence eesau, looks like some very slick code there; I just hate reg exps! Not sure that using a reg exp for anything but a very simple tokeniser would be suitable; too slow probably.
None taken! And yes, it's probably slower with large sources than traditional tokenizers, but fast enough for me with small ones.
srod wrote:That particular RegExp looks like my dog's breakfast after it has been thrown up all over the kitchen floor!
Understatement of the year
You haven't seen how much my dog eats!
I understand what you are saying about small sources - in those cases yes, very concise code. Must admit that I use reg exps to check individual tokens; e.g. checking whether a token represents a valid variable name etc. Anything bigger though and it's roll the sleeves up, allocate a memory buffer and grab ahold of a few pointers etc. No where near as concise as using a reg exp!
I may look like a mule, but I'm not a complete ass.
what we need is regular expression translator/compiler, where you write the expression in human readable form then feed it to the translator to output a regex.
the demo looks promising, but then i know very little about regexs'.
On the one hand it seems that this approach could lead to my still being regex illiterate, just let the tool do it for me, but if it generates quality code, as I imagine it will, AND I study the output and learn from it, it will be worth it.
RegexBuddy has an option to generate the code for RealBasic and several other languages, but not PB:(
Don't want to take this topic into "offtopic" land, but any other comments on either tool?
A tool that I like is Regex Coach. It might not be as powerful as the other tools mentioned before. But it's very useful anyway, and since it's free you just can try it without risk. It's even portable.