Hi,<br><font color="#002162"><br></font>I was trying to create a composed grammar for Gyb (<a href="https://github.com/apple/swift/blob/master/utils/gyb.py">https://github.com/apple/swift/blob/master/utils/gyb.py</a>). Gyb is mostly Swift code, with some snippets of Python embedded. For embedding the Python code you surround the code with `%{ }%` or start the lines with `%`.<br><font color="#002162"><br></font>For parsing Swift or Python code I’m using the official bundles (<a href="https://github.com/textmate/swift.tmbundle">https://github.com/textmate/swift.tmbundle</a> and <a href="https://github.com/textmate/python.tmbundle">https://github.com/textmate/python.tmbundle</a>). For the injection I based my grammar on HTML (Rails) (<a href="https://github.com/textmate/ruby-on-rails-tmbundle/blob/master/Syntaxes/HTML%20(Rails).plist">https://github.com/textmate/ruby-on-rails-tmbundle/blob/master/Syntaxes/HTML%20(Rails).plist</a>) which is mostly the same idea.<br><font color="#002162"><br></font>The grammar almost works. The embedded blocks are marked and the syntax highlight works, but I need to include a space before the percent signs for it to work, which is not ideal. It looks like the percent sign are interpreted as keyword.operator.remainder.swift (<a href="https://github.com/textmate/swift.tmbundle/blob/master/Syntaxes/Swift.tmLanguage#L1282-L1287">https://github.com/textmate/swift.tmbundle/blob/master/Syntaxes/Swift.tmLanguage#L1282-L1287</a>) before being able to be part of the injected grammar.<br><font color="#002162"><br></font>I found some references that “left scope match” (L:) might be able to help, but I cannot find a way to get it working.<br><font color="#002162"><br></font>A simple version of my grammar looks like this:<br><font color="#002162"><br></font>```<br>{<span style="white-space: pre;">       </span>injections = {<br><span style="white-space: pre;">           </span>'source.swift.gyb - (meta.embedded.block.gyb)' = {<br><span style="white-space: pre;">                       </span>patterns = (<br><span style="white-space: pre;">                             </span>{<span style="white-space: pre;">  </span>begin = '(^|\s*)(?=%\{(?![^\}]*\}%))';<br><span style="white-space: pre;">                                   </span>end = '(?!\G)(\s*$\n)?';<br><span style="white-space: pre;">                                 </span>beginCaptures = { 0 = { name = 'punctuation.whitespace.embedded.leading.gyb'; }; };<br><span style="white-space: pre;">                                      </span>endCaptures = { 0 = { name = 'punctuation.whitespace.embedded.trailing.gyb'; }; };<br><span style="white-space: pre;">                                       </span>patterns = ( { include = '#tags'; } );<br><span style="white-space: pre;">                           </span>},<br><span style="white-space: pre;">                               </span>{<span style="white-space: pre;">  </span>include = '#tags'; },<br><span style="white-space: pre;">                    </span>);<br><span style="white-space: pre;">               </span>};<br><span style="white-space: pre;">       </span>};<br><span style="white-space: pre;">       </span>patterns = ( { include = 'source.swift'; } );<br><span style="white-space: pre;">    </span>repository = {<br><span style="white-space: pre;">           </span>tags = {<br><span style="white-space: pre;">                 </span>patterns = (<br><span style="white-space: pre;">                             </span>{<span style="white-space: pre;">  </span>name = 'meta.embedded.block.gyb';<br><span style="white-space: pre;">                                        </span>begin = '%\{';<br><span style="white-space: pre;">                                   </span>end = '(\})%';<br><span style="white-space: pre;">                                   </span>beginCaptures = { 0 = { name = 'punctuation.section.embedded.begin.gyb'; }; };<br><span style="white-space: pre;">                                   </span>endCaptures = {<br><span style="white-space: pre;">                                          </span>0 = { name = 'punctuation.section.embedded.end.gyb'; };<br><span style="white-space: pre;">                                          </span>1 = { name = 'source.python'; };<br><span style="white-space: pre;">                                 </span>};<br><span style="white-space: pre;">                                       </span>contentName = 'source.python';<br><span style="white-space: pre;">                                   </span>patterns = ( { include = 'source.python'; } );<br><span style="white-space: pre;">                           </span>},<br><span style="white-space: pre;">               </span>},<br><span style="white-space: pre;">       </span>},<br>}<br>```<br><font color="#002162"><br></font>A text like this will work:<br><font color="#002162"><br></font>```<br>class MyClass {<br> %{<br>a = 1<br>}%<br>}<br>```<br><font color="#002162"><br></font>If I remove the space before the first percent sign, the grammar will not create the embedded block at all.<br><font color="#002162"><br></font>I tried using several scope selectors with `L:` to see if they work:<br>- `L:(source.swift.gyb - (meta.embedded.block.gyb))`<br>- `source.swift.gyb - (meta.embedded.block.gyb), L:source.swift.gyb`<br>- `source.swift.gyb - (meta.embedded.block.gyb), L:source.swift`<br>- `source.swift.gyb - (meta.embedded.block.gyb), L:source.swift keyword.operator.remainder.swift`<br>- `source.swift.gyb - (meta.embedded.block.gyb), L:keyword.operator.remainder.swift`<br><font color="#002162"><br></font>None of them seem to work.<br><font color="#002162"><br></font>Does someone has any tips about what should I try next?<br><font color="#002162"><br></font>Thanks!<br>