From 8dfed40466a7c49dfcd172d611af8cad5f876fe5 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Fri, 11 Feb 2022 11:17:18 -0500 Subject: [PATCH] Describe naming conventions for syntax captures. --- docs/section-2-using-parsers.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/section-2-using-parsers.md b/docs/section-2-using-parsers.md index 0d22f251..6a891458 100644 --- a/docs/section-2-using-parsers.md +++ b/docs/section-2-using-parsers.md @@ -852,3 +852,20 @@ Example: } } ``` + +## 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`.