[TxMt] The use of \G in single line comments

Corey Johnson cj at github.com
Mon Oct 22 19:11:31 UTC 2012


I'm trying to understand how the single line comment rule works (found on this line https://github.com/textmate/javascript.tmbundle/blob/master/Syntaxes/JavaScript.plist#L546)

    begin = '(^[ \t]+)?(?=//)';
end = '(?!\G)';
beginCaptures = { 1 = { name = 'punctuation.whitespace.comment.leading.js'; }; };
patterns = (
{ name = 'comment.line.double-slash.js';
begin = '//';
end = '\n';
beginCaptures = { 0 = { name = 'punctuation.definition.comment.js'; }; };
},
);

Since TextMate grammars are line based, I'm not sure how it's possible for the '\n' pattern and the '(?!\G)' pattern to work together. For example, take these two lines:

// a comment
var foo

The 'single line comment' rule is entered by matching it's begin pattern '(^[ \t]+)?(?=//)'. The 'comment.line.double-slash.js'' rule is then entered upon matching '//', the rule is ended when '\n' is matched. Because we have matched the end of the first line, we continue to the second line. The second line will end the 'single line comment' rule because the end pattern '(?!\G)'  will match the 'a' in 'var'. Because of this, var cannot be scooped correctly because the 'v' is considered to be part of the 'single line comment' rule.

This fails as I described in TextMate 1 but works in TextMate 2. Is there something fundamentally different about using the \G anchor in TextMate 2.

Thanks,
Corey




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20121022/4756efb6/attachment.html>


More information about the textmate mailing list