Skip to content

Commit a7f935c

Browse files
committed
Use keywords to represent auxiliary (invisible) node types
1 parent 5eb249d commit a7f935c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
77
- Fixed some invalid query patterns [causing SIGABRT](https://github.com/ubolonton/emacs-tree-sitter/issues/125), by upgrading `tree-sitter` crate.
8+
- Used keywords to represent auxiliary (invisible) node types. For example: `:end`, `:_expression`.
89

910
## [0.15.0] - 2021-03-15
1011
- Upgraded `tree-sitter` crate to 0.19.3, which:

core/src/lang.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ fn _load_language(file: String, symbol_name: String, lang_symbol: Value) -> Resu
107107
}
108108
let node_types = (0..language.node_kind_count() as u16).map(|id| {
109109
let type_str = language.node_kind_for_id(id).expect("Failed to get node type for id");
110-
let value = if language.node_kind_is_named(id) {
110+
let value = if !language.node_kind_is_visible(id) {
111+
env.intern(&format!(":{}", type_str)).expect("Failed to intern keyword for node type")
112+
} else if language.node_kind_is_named(id) {
111113
env.intern(type_str).expect("Failed to intern symbol for node type")
112114
} else {
113115
type_str.into_lisp(env).expect("Failed to make string for node type")
@@ -147,6 +149,7 @@ fn _lang_load_file(language: Language) -> Result<&'static String> {
147149
///
148150
/// For named nodes, the node type is a symbol. For example: 'identifier, 'block.
149151
/// For anonymous nodes, the node type is a string. For example: "if", "else".
152+
/// For auxiliary (invisible) nodes, the node type is a keyword. For example: :end, :_expression.
150153
#[defun]
151154
fn lang_node_type(language: Language, type_id: u16) -> Result<Option<&'static GlobalRef>> {
152155
Ok(language.info().node_type(type_id))

lisp/tree-sitter-tests.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ If RESET is non-nil, also do another full parse and check again."
126126
(tsc-lang-node-type language))
127127
node-type))))
128128
(ert-info ("0 should be the special node type \"end\"")
129-
(should (equal "end" (format "%s" (tsc-lang-node-type language 0)))))
129+
(should (equal :end (tsc-lang-node-type language 0))))
130130
(ert-info ("Node type IDs should be from 0 to type count minus 1")
131131
(should-not (null (tsc-lang-node-type language 1)))
132132
(should-not (null (tsc-lang-node-type language (- type-count 1))))

0 commit comments

Comments
 (0)