Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Allow scope mappings to be refined via match rules #17738

Merged
merged 8 commits into from
Jul 30, 2018

Conversation

queerviolet
Copy link
Contributor

@queerviolet queerviolet commented Jul 24, 2018

In the TextMate grammars, some tokens are highlighted differently based on their content. For example, document and exports and other common identifiers are colored differently than normal variables (even though they are technically normal variables).

Tree Sitter's highlighting system didn't support this... until now.

This PR adds tooling to TreeSitterLanguageMode enabling match rules on the RHS of a scope mapping in the atom grammar definition:

Example:

    'scopes':
         'identifier': [
            {exact: 'exports', scopes: 'global'},
            {match: '^[A-Z_]+$', scopes: 'constant'},
            {match: '^[A-Z]', scopes: 'constructor'},
            'variable'
          ],

The first rule that matches is applied, so SOME_CONSTANT will resolve to the scope constant even though it also matches /^[A-Z]/. String rules (such as variable above) always match, applying the specified scope (a nicety for default cases).

@queerviolet queerviolet merged commit bc8e70d into master Jul 30, 2018
@jasonrudolph jasonrudolph deleted the regex-matchers-for-style-map branch August 15, 2019 14:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant