Hi David

> Hi all, sorry to keep posting so many questions this week.

I may be behind on your questions, do feel free to bump them if so; you’re 
working on interesting stuff and I’d like to help.

> 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>>
OK, this approach breaks one of the assumptions of the parsing/rendering 
machinery: that the result of parsing a tiddler does not depend on the state of 
the tiddler store. This is important because parsing is a relatively expensive 
operation, and it enables us to cache the results of parsing a tiddler.

In your use case, the results of parsing a tiddler would change depending upon 
the currently defined tags, defeating the caching mechanism.

This issue has come up before in relation to automatically turning the text of 
references to tiddler titles to become links; I can’t find the reference right 
now, but the thread (either here or on GitHub) did include a number of 
suggestions for alternative approaches.

Best wishes

Jeremy

> 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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/tiddlywikidev 
> <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
>  
> <https://groups.google.com/d/msgid/tiddlywikidev/da6e4662-c67d-4999-9059-3d8aa56ef85e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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/0B02C739-ACBB-4803-835E-95AF08EAEF9C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to