Skip to content

Commit 130804c

Browse files
Added documentation for the scope test format
1 parent ff31585 commit 130804c

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Then add parse tree patterns for the given scope to your language's `.scm` file
6161
- Use the [scope visualizer](../user/scope-visualizer.md) to see your scope highlighted in real time every time you save the `.scm` file.
6262
- Use the command `"parse tree <target>"` to see the parse tree for a given target. For example `"parse tree line"` will show you the parse tree for the current line, as well as all of its ancestors. This will generate a markdown file with parse tree info, which you can then use to write your patterns. You might find it helpful to open a markdown preview of the file.
6363
- You will likely want to look at `node-types.json` for your language, (eg [java](https://github.com/tree-sitter/tree-sitter-java/blob/master/src/node-types.json)). This file is generated from the language's `grammar.js`, which might also be helpful to look at (eg [java](https://github.com/tree-sitter/tree-sitter-java/blob/master/grammar.js)).
64+
- Documentation for the [scope test format](./scope-test-format.md)
6465

6566
## 6. Update the tests
6667

packages/cursorless-org-docs/src/docs/contributing/parse-tree-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Parse tree pattern matcher
1+
# Parse tree pattern matcher [DEPRECATED]
22

33
We have a small domain-specific language that we use to define patterns to look for in tree-sitter parse trees. This DSL enables us to rapidly define new syntactic scope types and support new programming languages.
44

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Scope test format
2+
3+
## Example
4+
5+
Example of `.scope` file for the javascript if statement scope.
6+
7+
```
8+
if (true) {
9+
10+
}
11+
---
12+
13+
[Content] =
14+
[Removal] =
15+
[Domain] = 0:0-2:1
16+
>-----------
17+
0| if (true) {
18+
1|
19+
2| }
20+
-<
21+
22+
[Insertion delimiter] = "\n"
23+
```
24+
25+
## Understanding the format
26+
27+
General layout of a `.scope` file is:
28+
29+
```
30+
Source code
31+
---
32+
Scopes
33+
```
34+
35+
## Source code
36+
37+
The code that you want to generate scopes for. We try to keep this as short and simple as possible while still containing the syntax you want to test.
38+
39+
## Scopes
40+
41+
One or more scopes found in the source code. Each scope is a collection of ranges as well as an insertion delimiter.
42+
43+
A description of the different ranges and how they are used is available in our [glossary](https://www.cursorless.org/docs/user/glossary).
44+
45+
### Scope ranges
46+
47+
The below example indicates that the content range, removal range, and domain range was the same. Line 0, column 0, to line 2, column 1. These ranges could also be different and in that case each show up as a separate range.
48+
49+
```
50+
[Content] =
51+
[Removal] =
52+
[Domain] = 0:0-2:1
53+
```
54+
55+
Each range is also visualized:
56+
57+
```
58+
>-----------
59+
0| if (true) {
60+
1|
61+
2| }
62+
-<
63+
```
64+
65+
On the left hand side we first have the line numbers, a pipe separator, and finally the source code. The range is visualized by starting after `>` and ending before `<`. Note that `>` and `<` is excluded from the range. That means a range of length one is `>-<` and an empty range is `><`.

0 commit comments

Comments
 (0)