Skip to content

Commit

Permalink
doc(query): add docs for queries, cursors, matches and captures
Browse files Browse the repository at this point in the history
  • Loading branch information
xcb-xwii committed Oct 11, 2023
1 parent 9b753fa commit 7cbcb4e
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ file = {
'ldoc/Node.lua',
'ldoc/Parser.lua',
'ldoc/Point.lua',
'ldoc/Query.lua',
'ldoc/QueryCapture.lua',
'ldoc/QueryCursor.lua',
'ldoc/QueryMatch.lua',
'ldoc/Range.lua',
'ldoc/RangeArray.lua',
'ldoc/Tree.lua',
Expand Down
23 changes: 23 additions & 0 deletions ldoc/Query.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
-- A query that can be ran on `Node`s of a given `Language`.
-- Analogous to `TSQuery`.
-- @classmod Query
-- @pragma nostrip

---
-- Functions
-- @section Functions


---
-- Create a new query for a given `Language` from a source `string`.
-- @tparam Language lang
-- @tparam string source
-- @treturn Query
-- @raise Invalid pattern in the source.
function Query.new(lang, source) end

---
-- Methods
-- @section Methods

34 changes: 34 additions & 0 deletions ldoc/QueryCapture.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
-- A capture of a `Query`.
-- Analogous to `TSQueryCapture`.
-- @classmod QueryCapture
-- @pragma nostrip

---
-- Methods
-- @section Methods

---
-- Get the `Node` of the capture.
-- @treturn Node
function QueryCapture:node() end

---
-- Get the index of the capture.
-- @treturn integer
function QueryCapture:index() end

---
-- Get the `QueryMatch` the capture belongs to.
-- @treturn QueryMatch
function QueryCapture:match() end

---
-- Get the `Query` the capture belongs to.
-- @treturn Query
function QueryCapture:query() end

---
-- Get the name of the capture.
-- @treturn Node
function QueryCapture:name() end
45 changes: 45 additions & 0 deletions ldoc/QueryCursor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
-- A cursor for executing a given `Query`.
-- Analogous to `TSQueryCursor`.
-- @classmod QueryCursor
-- @pragma nostrip

---
-- Functions
-- @section Functions

---
-- Create a new cursor for executing a given `Query` on a given `Node`.
-- @tparam Query query
-- @tparam Node node
-- @treturn QueryCursor
function QueryCursor.new(query, node) end

---
-- Methods
-- @section Methods

---
-- Get the `Query` the cursor is executing.
-- @treturn Query
function QueryCursor:query() end

---
-- Set the range of `Point`s in which the `Query` will be executed.
-- @tparam Point start_point
-- @tparam Point end_point
function QueryCursor:set_point_range(start_point, end_point) end

---
-- Advance to and get the next match.
--
-- This method may return `nil` if there are no more matches.
-- @treturn QueryMatch|nil
function QueryCursor:next_match() end

---
-- Advance to and get the next capture.
--
-- This method may return `nil` if there are no more captures.
-- @treturn QueryCapture|nil
function QueryCursor:next_capture() end
32 changes: 32 additions & 0 deletions ldoc/QueryMatch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
-- A match of a `Query`.
-- Analogous to `TSQueryMatch`.
-- @classmod QueryMatch
-- @pragma nostrip

---
-- Methods
-- @section Methods

---
-- Get the pattern index of the match.
-- @treturn integer
function QueryMatch:pattern_index() end

---
-- Get the number of `QueryCapture`s in the match.
-- @treturn integer
function QueryCursor:capture_count() end

---
-- Get the `QueryCapture` at a given index.
-- @tparam integer index
-- @treturn QueryCapture
-- @raise Indexing a negative index.
-- Indexing beyond last element.
function QueryCursor:capture_at(index) end

---
-- Get the `Query` to which the match belongs.
-- @treturn Query
function QueryMatch:query() end

0 comments on commit 7cbcb4e

Please sign in to comment.