Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit fff11eb

Browse files
committed
Update syntax classes in "Creating a Grammar"
1 parent 76dcc92 commit fff11eb

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

content/hacking-atom/sections/creating-a-grammar.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ Here is a simple example:
8787

8888
```coffee
8989
scopes:
90-
'call_expression > identifier': 'entity.name.function'
90+
'call_expression > identifier': 'entity.function.call'
9191
```
9292

93-
This entry means that, in the syntax tree, any `identifier` node whose parent is a `call_expression` should be highlighted using three classes: `syntax--entity`, `syntax--name`, and `syntax--function`.
93+
This entry means that, in the syntax tree, any `identifier` node whose parent is a `call_expression` should be highlighted using three classes: `syntax--entity`, `syntax--function`, and `syntax--call`.
9494

9595
Note that in this selector, we're using the [immediate child combinator](https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors) (`>`). Arbitrary descendant selectors without this combinator (for example `'call_expression identifier'`, which would match any `identifier` occurring anywhere within a `call_expression`) are currently not supported.
9696

@@ -104,14 +104,14 @@ scopes:
104104
function_declaration > identifier,
105105
call_expression > identifier,
106106
call_expression > field_expression > field_identifier
107-
''': 'entity.name.function'
107+
''': 'entity.function'
108108
```
109109

110110
You can use the [`:nth-child` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child) to select nodes based on their order within their parent. For example, this example selects `identifier` nodes which are the fourth (zero-indexed) child of a `singleton_method` node.
111111

112112
```coffee
113113
scopes:
114-
'singleton_method > identifier:nth-child(3)': 'entity.name.function'
114+
'singleton_method > identifier:nth-child(3)': 'entity.function'
115115
```
116116

117117
Finally, you can use double-quoted strings in the selectors to select *anonymous* tokens in the syntax tree, like `(` and `:`. See [the Tree-sitter documentation](http://tree-sitter.github.io/tree-sitter/using-parsers#named-vs-anonymous-nodes) for more information about named vs anonymous tokens.
@@ -123,7 +123,7 @@ scopes:
123123
"/",
124124
"+",
125125
"-"
126-
''': 'keyword.operator'
126+
''': 'keyword.operator.arithmetic.symbolic'
127127
```
128128

129129
##### Text-based Mappings
@@ -133,21 +133,31 @@ You can also apply different classes to a syntax node based on its text. Here ar
133133
```coffee
134134
scopes:
135135

136-
# Apply the classes `syntax--builtin` and `syntax--variable` to all
137-
# `identifier` nodes whose text is `require`.
138-
'identifier': {exact: 'require', scopes: 'builtin.variable'},
136+
# Apply the classes `syntax--entity`, `syntax--function`, and
137+
# `syntax--support` to all `identifier` nodes whose text is `require`.
138+
'identifier': {
139+
exact: 'require',
140+
scopes: 'entity.function.support'
141+
},
139142

140-
# Apply the classes `syntax--type` and `syntax--integer` to all
141-
# `primitive_type` nodes whose text starts with `int` or `uint`.
142-
'primitive_type': {match: /^u?int/, scopes: 'type.integer'},
143+
# Apply the classes `syntax--entity`, `syntax--type`, `syntax--fundamental`,
144+
# and `syntax--integer` to all `primitive_type` nodes whose text starts
145+
# with `int` or `uint`.
146+
'primitive_type': {
147+
match: /^u?int/,
148+
scopes: 'entity.type.fundamental.integer'
149+
},
143150

144-
# Apply the classes `syntax--builtin`, `syntax--class`, and
145-
# `syntax--name` to `constant` nodes with the text `Array`,
146-
# `Hash` and `String`. For all other `constant` nodes, just
147-
# apply the classes `syntax--class` and `syntax--name`.
151+
# Apply the classes `syntax--entity`, `syntax--type`, `syntax--class`, and
152+
# `syntax--support` to `constant` nodes with the text `Array`, `Hash` or
153+
# `String`. For other `constant` nodes, apply the classes `syntax--entity`,
154+
# `syntax--type`, and `syntax--class`.
148155
'constant': [
149-
{match: '^(Array|Hash|String)$', scopes: 'builtin.class.name'},
150-
'class.name'
156+
{
157+
match: '^(Array|Hash|String)$',
158+
scopes: 'entity.type.class.support'
159+
},
160+
'entity.type.class'
151161
]
152162
```
153163

@@ -164,15 +174,15 @@ If multiple selectors in the `scopes` object match a node, the node's classes wi
164174

165175
```coffee
166176
scopes:
167-
'call_expression > identifier': 'entity.name.function'
177+
'call_expression > identifier': 'entity.function'
168178

169179
# If we did not include the second selector here, then this rule
170180
# would not apply to identifiers inside of call_expressions,
171181
# because the selector `call_expression > identifier` is more
172182
# specific than the selector `identifier`.
173183
'identifier, call_expression > identifier': [
174-
{exact: 'require', scopes: 'builtin.variable'},
175-
{match: '^[A-Z]', scopes: 'constructor'},
184+
{exact: 'require', scopes: 'entity.function.support'},
185+
{match: '^[A-Z]', scopes: 'entity.type.constructor'},
176186
]
177187
```
178188

0 commit comments

Comments
 (0)