Hi all, sorry to keep posting so many questions this week.
I'm trying to write a parser that iterates through an array, and runs a
regex for each value.
Use case:
- make an array of all tags
- make a RegExp to find first instance of each tag in the array
- parse to return a macro that wraps each tag in *<<tag *arrayValue*>>*
The code below ends up setting the regex to the last value in the array,
and parsing based on it (made sense in hindsight):
exports.init = function(parser) {
this.parser = parser;
// For each tag, set a matchRegExp and parse
for (var i = 0; i < myArray.length; i++) {
this.matchRegExp = new RegExp(whatever...);
}
};
...
exports.parse = function() {
// Move past the matched word
this.parser.pos = this.matchRegExp.lastIndex;
params.push(paramInfo);
return [{
...
}];
};
So I expected maybe I could call *this.parse()* each time through, but this
just dies:
exports.init = function(parser) {
this.parser = parser;
// For each tag, set a matchRegExp and parse
for (var i = 0; i < myArray.length; i++) {
this.matchRegExp = new RegExp(whatever...);
// Parse based on the RegExp tailored for this array value
this.parse();
}
};
...
I've looked through the built-in parsers, but can't grok it. I'd like to do
it this way because it seems getting the RegEx right would be equally
difficult!
Any thoughts?
Thanks,
David.
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywikidev/da6e4662-c67d-4999-9059-3d8aa56ef85e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.