From 88822bd3fc8c9a40d5a9aef0d7ecde385124a3c8 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Fri, 11 Feb 2022 15:25:50 -0500 Subject: [PATCH] Move this to its own page. --- docs/section-2-using-parsers.md | 17 ------------- docs/section-8-code-navigation-systems.md | 29 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 docs/section-8-code-navigation-systems.md diff --git a/docs/section-2-using-parsers.md b/docs/section-2-using-parsers.md index 8bc5f868..0d22f251 100644 --- a/docs/section-2-using-parsers.md +++ b/docs/section-2-using-parsers.md @@ -711,23 +711,6 @@ bool ts_query_cursor_next_match(TSQueryCursor *, TSQueryMatch *match); This function will return `false` when there are no more matches. Otherwise, it will populate the `match` with data about which pattern matched and which nodes were captured. -### Capture Naming Conventions - -Applications using Tree-sitter often need to use queries and captures to categorize and label different syntactic nodes, such as functions, built-ins, operators, and variables. We recommend using a reverse-DNS-style notation for these captures, and provide guidelines below for naming captures of a given syntax node. User applications may extend (or only recognize a subset of) these capture names, but we recommend standardizing on the names below. - -| Category | Tag | -|--------------------------|-----------------------------| -| Class definitions | `@definition.class` | -| Function definitions | `@definition.function` | -| Interface definitions | `@definition.interface` | -| Method definitions | `@definition.method` | -| Module definitions | `@definition.module` | -| Function/method calls | `@reference.call` | -| Class reference | `@reference.class` | -| Interface implementation | `@reference.implementation` | - -To communicate the associated identifier inside one of these syntactic classes, capture the identifier within as `@name`. - ## Static Node Types In languages with static typing, it can be helpful for syntax trees to provide specific type information about individual syntax nodes. Tree-sitter makes this information available via a generated file called `node-types.json`. This _node types_ file provides structured data about every possible syntax node in a grammar. diff --git a/docs/section-8-code-navigation-systems.md b/docs/section-8-code-navigation-systems.md new file mode 100644 index 00000000..3aec22c6 --- /dev/null +++ b/docs/section-8-code-navigation-systems.md @@ -0,0 +1,29 @@ +--- +title: Code Navigation Systems +permalink: code-navigation-systems +--- + +# Code Navigation Systems + +Tree-sitter can be used in conjunction with its [tree query language](https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries) as a part of code navigation systems. An example of such a system can be seen in the `tree-sitter tag` command, which emits a textual dump of the interesting syntactic nodes in its file argument. This document exists to provide guidelines on the design and use of tree-sitter concepts to implement such systems. + +## Tagging and captures + +Code navigation systems using Tree-sitter need to use queries and captures to categorize and label different syntactic nodes, such as functions, built-ins, operators, and variables. A reverse-DNS-style notation is recommendedfor these captures, and provide guidelines below for naming captures of a given syntax node. User applications may extend (or only recognize a subset of) these capture names, but it is desirable to standardize on the names below when supported by a given system or language. + +| Category | Tag | +|--------------------------|-----------------------------| +| Class definitions | `@definition.class` | +| Function definitions | `@definition.function` | +| Interface definitions | `@definition.interface` | +| Method definitions | `@definition.method` | +| Module definitions | `@definition.module` | +| Function/method calls | `@reference.call` | +| Class reference | `@reference.class` | +| Interface implementation | `@reference.implementation` | + +To communicate the associated identifier inside one of these syntactic classes, capture the identifier within as `@name`. + +## `tree-sitter graph` + +Coming soon!