Skip to content

Commit

Permalink
Change repr of query capture/match from 2-element vector to cons cell
Browse files Browse the repository at this point in the history
  • Loading branch information
ubolonton committed Feb 20, 2020
1 parent 3622260 commit 236e38e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Changed all APIs to use Emacs's 1-based byte positions instead of 0-based byte offsets.
- Changed all APIs to use Emacs's 1-based line numbers instead of 0-based row numbering.
- Changed representation of tree-sitter point from 2-element vector to cons cell.
- Changed representation of query match/capture from 2-element vector to cons cell.

## [0.2.0] - 2020-02-02
- Upgraded `tree-sitter` to 0.6.0.
Expand Down
10 changes: 5 additions & 5 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ fn _query_cursor_matches<'e>(
for (ci, c) in m.captures.iter().enumerate() {
let captured_node = node.map(|_| c.node);
let capture = if index_only.is_some() {
env.vector((c.index, captured_node))?
env.cons(c.index, captured_node)?
} else {
env.vector((&capture_names[c.index as usize], captured_node))?
env.cons(&capture_names[c.index as usize], captured_node)?
};
captures.set(ci, capture)?;
}
let _match = env.vector((m.pattern_index, captures))?;
let _match = env.cons(m.pattern_index, captures)?;
vec.push(_match);
}
vec_to_vector(env, vec)
Expand Down Expand Up @@ -156,9 +156,9 @@ fn _query_cursor_captures<'e>(
let c = m.captures[capture_index];
let captured_node = node.map(|_| c.node);
let capture = if index_only.is_some() {
env.vector((c.index, captured_node))?
env.cons(c.index, captured_node)?
} else {
env.vector((&capture_names[c.index as usize], captured_node))?
env.cons(&capture_names[c.index as usize], captured_node)?
};
vec.push(capture);
}
Expand Down
4 changes: 2 additions & 2 deletions tree-sitter-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ parsed with LANGUAGE."
"Execute QUERY on NODE and return a vector of matches.
Matches are sorted in the order they were found.
Each match is a `[PATTERN-INDEX MATCH-CAPTURES]' vector, where PATTERN-INDEX is
Each match has the form (PATTERN-INDEX . MATCH-CAPTURES), where PATTERN-INDEX is
the position of the matched pattern within QUERY, and MATCH-CAPTURES is a vector
of captures by the match, similar to that returned by `ts-query-captures'. If
the optional arg INDEX-ONLY is non-nil, positions of the capture patterns within
Expand All @@ -220,7 +220,7 @@ Otherwise `ts-node-text' is used."
"Execute QUERY on NODE and return a vector of captures.
Matches are sorted in the order they appear.
Each capture is a `[CAPTURE-NAME CAPTURED-NODE]' vector. If the optional arg
Each capture has the form (CAPTURE-NAME . CAPTURED-NODE). If the optional arg
INDEX-ONLY is non-nil, the position of the capture pattern within QUERY is
returned instead of its name.
Expand Down
4 changes: 2 additions & 2 deletions tree-sitter-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ tree is held (since nodes internally reference the tree)."
(match? @function \"make_query\"))
(macro_definition (identifier) @macro)"))
(node-texts (mapcar (lambda (capture)
(pcase-let ((`[_ ,node] capture))
(pcase-let ((`(_ . ,node) capture))
(ts-node-text node)))
captures))
(capture-names (mapcar (lambda (capture)
(pcase-let ((`[,name node] capture)) name))
(pcase-let ((`(,name . _) capture)) name))
captures)))
(ert-info ("Should match specified functions and not more")
(should (member "_make_query" node-texts))
Expand Down

0 comments on commit 236e38e

Please sign in to comment.