diff --git a/docs/section-4-syntax-highlighting.md b/docs/section-4-syntax-highlighting.md index a8dbb5a0..90697ecd 100644 --- a/docs/section-4-syntax-highlighting.md +++ b/docs/section-4-syntax-highlighting.md @@ -66,7 +66,7 @@ Suppose we wanted to render this code with the following colors: We can assign each of these categories a *highlight name* using a query like this: -```clj +``` ; highlights.scm "func" @keyword @@ -92,7 +92,7 @@ And we could map each of these highlight names to a color: #### Result
-func increment(a int) int { +func increment(a int) int { return a + 1 }@@ -111,6 +111,8 @@ The capture names are as follows: When highlighting a file, Tree-sitter will keep track of the set of scopes that contains any given position, and the set of definitions within each scope. When processing a syntax node that is captured as a `local.reference`, Tree-sitter will try to find a definition for a name that that matches the node's text. If it finds a match, Tree-sitter will ensure that the *reference* and the *definition* are colored the same. +The information produced by this query can also be *used* by the highlights query. You can *disable* a pattern for nodes which have been identified as local variables by adding the predicate `(is-not? local)` to the pattern. This is used in the example below: + #### Example Input Consider this Ruby code: @@ -172,7 +174,7 @@ There are several different types of names within this method: Let's write some queries that let us clearly distinguish between these types of names. First, set up the highlighting query, as described in the previous section. We'll assign distinct colors to method calls, method definitions, and formal parameters: -```clj +``` ; highlights.scm (call method: (identifier) @function.method) @@ -182,11 +184,14 @@ Let's write some queries that let us clearly distinguish between these types of (method_parameters (identifier) @variable.parameter) (block_parameters (identifier) @variable.parameter) + +((identifier) @function.method + (is-not? local)) ``` Then, we'll set up a local variable query to keep track of the variables and scopes. Here, we're indicating that methods and blocks create local *scopes*, parameters and assignments create *definitions*, and other identifiers should be considered *references*: -```clj +``` ; locals.scm (method) @local.scope @@ -202,8 +207,6 @@ Then, we'll set up a local variable query to keep track of the variables and sco #### Result - -
def process_list(list) context = current_context @@ -217,3 +220,48 @@ Then, we'll set up a local variable query to keep track of the variables and sco## Language Injection Query + +Some source files contain code written in multiple different languages. Examples include: +* HTML files, which can contain JavaScript inside of `