groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

Setting delimiters to the current delimiters causes error #38

Closed sl1m3d closed 11 years ago

sl1m3d commented 11 years ago

When setting the delimiter to the original value when it's currently set to the original value causes an error.

groue commented 11 years ago

Could you please provide a short template that exhibits the problem, and the error message?

sl1m3d commented 11 years ago

This produces an error: "Parse error at line 1: Unclosed Mustache tag"

id data = @{@"title": @"hello"};
NSString* template = @"{{={{ }}=}}{{title}}";
NSError *error = nil;
GRMustacheTemplate* mTemplate = [GRMustacheTemplate templateFromString:template error:&error];

This produces no error

id data = @{@"title": @"hello"};
NSString* template = @"{{={@ @}=}}{@title@}";
NSError *error = nil;
GRMustacheTemplate* mTemplate = [GRMustacheTemplate templateFromString:template error:&error];

This produces the same error, so it seems to occur when you try to set the delimiters to what they already are:

id data = @{@"title": @"hello"};
NSString* template = @"{{=[[ ]]=}}[[=[[ ]]=]][[title]]";
NSError *error = nil;
GRMustacheTemplate* mTemplate = [GRMustacheTemplate templateFromString:template error:&error];
groue commented 11 years ago

so it seems to occur when you try to set the delimiters to what they already are

Yes, indeed. The implementation of the parser doesn't like an opening token to be between an opening and a closing one, as in {{...{{...}}.

Are those templates machine-generated?

sl1m3d commented 11 years ago

Kind of. The implementation I'm working on is being able to run through the same template a couple times with different delimiters each time by wrapping the template after each pass through in a string format delimiter change.

Edit: It's not really a big deal as I can always check before wrapping it, but it seems like a bug nonetheless.

groue commented 11 years ago

Yes, it seems like a bug. A pull request will be welcome, if you feel like fixing it.

groue commented 11 years ago

Actually I don't know where the bug is, in GRMustache, in the Mustache (non-specified) grammar, or in the "set delimiters tags" concept. I'm closing this issue as "won't fix".

Handlebars got rid of delimiter tags, and replaced them with backslash escaping. I tend to think it's a superior solution.

@psybert, would you live if delimiters tags were replaced by backslash escaping of braces?

sl1m3d commented 11 years ago

Well I'll be using the set delimiters feature, but the backslash escaping seems to be pretty powerful as well.

groue commented 11 years ago

Reopening

groue commented 11 years ago

This issue has been reopened because it will be solved when #45 gets fixed in the master branch.

groue commented 11 years ago

Fixed in v6.7.2.