Referencing all the patterns of parent pattern (Language Grammar)


#1

I am working in a highlighting syntax package for a language that has a “formula mode” that starts with $( and ends up with ) but allows normal parentheses inside. I can keep track of the extra parentheses with the following pattern:

'parentheses':
    'begin': '\\('
    'beginCaptures':
     'name': 'punctuation.definition.parentheses'
    'end': '\\)'
    'patterns': [
      {
        'include': '$self'
      }
    ]

But I need to include all the patterns of the parent pattern too, not only the parentheses. Is there any way of doing this without copy-pasting the patterns?


#2

Move the parent pattern to the repository and then you can reference it in an include statement.


#3

Hi there, I might not expressed myself clearly. I know that I can do that, but if something changes in the parent repository It would not be reflected in the parentheses patterns. I am trying to find to find if it is possible just link the parent repository (or at least the math_mode ones) patterns.


#4

@brunoduran Can you give some more context? Is the parent repository a different grammar? If so, the following might help:

  • 'include': '$base' (similar to $self, but I believe it also includes patterns from the parent repository)
  • 'include': 'text.html' (includes the grammar with the scopeName text.html)
  • 'include': 'text.html#whatever' (includes the whatever pattern defined in text.html's repository section)

#5

@Wliu The parent repository is the same grammar -it is in the same file in repository as parentheses is-.

I have tried and read about $base before, but I am not sure what it does, when I used it I could not see the difference with $self. But $base did not include the patterns of the parent repository when I tried it.

It seems odd that TextMate do not support these use cases, it has to be something to get all the pattern from the parent, or at least from another patter.


#6

Why don’t you post your whole grammar file so that we can see all of it?


#7

@DamnedScholar It is still unfinished and a little bit dirty, but here is it: