This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maxbrunsfeld
changed the title
Start work on Tree-sitter grammar injections
Add Tree-sitter grammar injections
Jun 22, 2018
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
2 times, most recently
from
June 22, 2018 23:02
3542f3c
to
b944e24
Compare
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
June 22, 2018 23:21
b944e24
to
37a3ae1
Compare
12 tasks
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
thomasjo
reviewed
Jun 27, 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid style comment; any specific reason for prefixing some of these functions with an underscore? I'm assuming they are "private", but I don't think we do this anywhere else in the core code? This wasn't meant to be a review, just a line comment...
thomasjo
reviewed
Jun 27, 2018
src/tree-sitter-language-mode.js
Outdated
} | ||
} | ||
|
||
async _performUpdate (containingNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid style comment; any specific reason for prefixing some of these functions with an underscore? I'm assuming they are "private", but I don't think we do this anywhere else in the core code?
Also, replace `addInjectionPattern` API with a single `injectionRegExp` field on the grammar. Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
June 27, 2018 21:21
095152c
to
c014f5e
Compare
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
June 27, 2018 21:32
c014f5e
to
6c85ff8
Compare
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
2 times, most recently
from
June 28, 2018 23:47
1f212f8
to
d6bb7b2
Compare
Co-Authored-By: Ashi Krishnan <queerviolet@github.com>
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
June 29, 2018 02:51
d6bb7b2
to
41c124c
Compare
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
June 29, 2018 21:47
d5f53fd
to
e16e680
Compare
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
July 13, 2018 00:57
cd8c8af
to
5b0ae5a
Compare
We already had conditional logic based on whether the node range set was 'full'.
maxbrunsfeld
force-pushed
the
tree-sitter-injections
branch
from
July 16, 2018 21:18
5dfc7c1
to
8fa9a45
Compare
This was referenced Jul 16, 2018
2 tasks
eugmes
added a commit
to eugmes/language-python
that referenced
this pull request
Dec 23, 2019
This allows to use this grammar from other tree-sitter grammars. See also: atom/atom#17551
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The TextMate parsing system allows grammars to be composed in order to syntax-highlight things like:
Currently, these types of things don't work when Tree-sitter is enabled.
Solution
This PR adds the concept of 'grammar injection' to Tree-sitter grammars. Specifically, it adds two new APIs associated with Tree-sitter grammars. These APIs might be revised before this PR is merged.
1. Adding Injection Points
This method allows you to express ideas like: "In JavaScript, tagged template strings are injection points. For each tagged template string, try to identify its language by looking at the name of its tag function. Parse the content between the backticks, omitting any template substitutions."
Note that this API does not indicate which grammar to use when parsing the content. That information can be provided by other packages, using the second API:
2. Specifying Injection Patterns
Grammars that use Tree-sitter have a new field called
injectionRegExp
. This field allows you to express ideas like: "The HTML language can be injected. Whenever there is an injection point where the language-name includes the string 'html', parse that injection point's content using the HTML parser."This two-part API allows languages to be embedded within one another without every grammar having to know about every other grammar.
Example
EJS is a popular JavaScript templating system where JavaScript code is interspersed with HTML markup using the delimiters
<%
and%>
. The HTML can of course contain more JavaScript code inside ofscript
tags. And that JavaScript code can contain HTML inside of string literals.Tasks
GrammarRegistry
APIsinjectionRegExps
are addedRelated Issues / PRs
Closes #17392
Depends on tree-sitter/tree-sitter#181
Depends on tree-sitter/node-tree-sitter#14
Depends on tree-sitter/node-tree-sitter#18