Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support two different content-matching regexes for tree-sitter grammars #17816

Merged
merged 3 commits into from Aug 10, 2018

Conversation

Projects
None yet
1 participant
@maxbrunsfeld
Copy link
Contributor

maxbrunsfeld commented Aug 10, 2018

Previously, Tree-sitter grammars only had one field for checking if they applied to a file based on its content: contentRegex. This PR changes the meaning of that regex and adds a new one whose meaning is closer to the firstLineMatch field of TextMate grammars.

  • firstLineRegex is only tested against the first line of the file, and if it matches, it allows the grammar to be used for the file. This will be used for matching things like shebang lines and vim modelines.
  • contentRegex is only tested if the grammar already matched the file name or the grammar's firstLineRegex matched. It is used to break ties between grammars like C and C++, or Flow and JS.

Fixes #17682

Support two different content-matching regexes for tree-sitter grammars
* firstLineRegex is only tested against the first line of the file, and
  if it matches, it allows the grammar to be used for the file.
* contentRegex is only tested if the grammar matched the file name
  or the grammar's firstLineRegex matched. It is used to break ties
  between grammars like C and C++, Flow and JS

maxbrunsfeld added a commit to atom/language-shellscript that referenced this pull request Aug 10, 2018

maxbrunsfeld added some commits Aug 10, 2018

@maxbrunsfeld maxbrunsfeld merged commit 9072e58 into master Aug 10, 2018

2 of 3 checks passed

VSTS: Atom Pull Requests 20180810.3 failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@maxbrunsfeld maxbrunsfeld deleted the mb-tree-sitter-grammar-regex-tweaks branch Aug 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.