<div>Thanks. The recommendations worked. Adding L:(…) around all the injections selector does the trick. I don’t know why it didn’t work for me then, but probably because of the second problem. Simplifying the other selectors and not trying to follow the ERB syntax makes everything a little bit easier to understand (and correctly syntax highlight both languages in the same file).<br><font color="#002162"><br></font>Thanks a lot for the help!</div><div><br><span style="color: rgb(160, 160, 168);">El lunes, 30 de mayo de 2016 a las 14:36, </span><a href="mailto:textmate-request@lists.macromates.com" style="color: rgb(0, 106, 227);">textmate-request@lists.macromates.com</a><span style="color: rgb(160, 160, 168);"> escribió:</span><br><blockquote type="cite">On 16 May 2016, at 17:29, Daniel Rodr?guez Troiti?o wrote:<br><br><blockquote type="cite" style="font-family: Helvetica; font-size: 13px;">A simple version of my grammar looks like this:<br>[?]<br><div>'source.swift.gyb - (meta.embedded.block.gyb)' = {</div></blockquote><br>The injection scope selector should use L:(?) so your injected rules <br>go before Swift?s (as you also write yourself).<br><br><blockquote type="cite" style="font-family: Helvetica; font-size: 13px;">{ begin = '(^|\s*)(?=%\{(?![^\}]*\}%))';</blockquote><br>This seems to be the problem, this rule doesn?t actually match <br>anything as it?s a ?begin of line? assertion and then a ?look <br>ahead? assertion.<br><br>So while the rule ?matches? when you have `%{` at the beginning of a <br>line, no characters are consumed, so we descend into the rule?s <br>patterns, but here we also have the Swift rules, and the L:(?) only <br>affects the priority of the root rules injected (not their children), so <br>the Swift rule will consume the `%` character because it was not <br>consumed by the parent rule?s begin pattern.<br><br>A minimal version of your grammar that works would be this:<br><br>{ injections = {<br>'L:(source.swift.gyb - meta.embedded.block.gyb)' = {<br>patterns = (<br>{ name = 'meta.embedded.block.gyb';<br>begin = '%\{';<br>end = '\}%';<br>contentName = 'source.python';<br>patterns = ( { include = 'source.python'; } );<br>},<br>);<br>};<br>};<br>patterns = ( { include = 'source.swift'; } );<br>}<br><br>I understand you wanted to scope the leading/trailing whitespace and <br>then re-use the actual matching of %{ and %}, but I don?t think this <br>is possible, though I think it will be simpler to add optional matches <br>like this:<br><br>begin = '(^\s*)?%\{';<br>end = '\}%(\s*$)?';<br><br>Then name these captures for <br><div>`punctuation.whitespace.embedded.[leading|trailing].gyb`.</div></blockquote></div>