Capture in grammar doesn't seem to work


#1

I’m trying to write the following grammar rule:

  {
       'begin': '([Cc]onst|CONST)'
       'end': ';'
        'beginCaptures': [
           '1' : 'name': 'storage.type.const.caople'
        ]
        'patterns': [
            {
                'match': '[a-zA-Z_][a-zA-Z_0-9]*'
                'name': 'entity.constdef.name.variable'
            }
        ]
        'name': 'meta.constdef.caople'
    }

The meta class is applied fine, as is the internal pattern for the variable name, but the beginCaptures seems to be ignored because the const keyword is always left untyped.

Things I’ve tried:

  • Adding and removing braces from the 'name': 'storage.type.const' block
  • Changing the '1' to '0' or 1 without the quotes
  • Checking several regexp testers, but they confirm that Const is in the first set of brackets and should thus be the first capture

Also, can you set parameters for the whole RegEx in Atom? Normally they would be after the closing / of the regex but Atom regexes don’t seem to be surrounded by /s.


#2
  1. You should not need square brackets around beginCaptures.
  2. It looks like beginCaptures is indented one space too much. CSON is whitespace-sensitive so that could make a difference.
  3. You can set parameters using leading (?stuff) syntax, eg (?xi) for an extended pattern that ignores capitalization. https://github.com/atom/language-css/blob/14aece2451497e21b08934bbf376c45e983422f0/grammars/css.cson#L424