|
61 | 61 | //! stack-graphs = { version="0.13", features=["lua"] }
|
62 | 62 | //! mlua = { version="0.9", features=["lua54", "vendored"] }
|
63 | 63 | //! ```
|
| 64 | +//! |
| 65 | +//! ## Lua API |
| 66 | +//! |
| 67 | +//! ### Stack graphs |
| 68 | +//! |
| 69 | +//! The following Lua methods are available on a stack graph instance: |
| 70 | +//! |
| 71 | +//! #### `file` |
| 72 | +//! |
| 73 | +//! ``` lua |
| 74 | +//! local file = graph:file(name) |
| 75 | +//! ``` |
| 76 | +//! |
| 77 | +//! Returns the file in the stack graph with the given name, creating it if necessary. |
| 78 | +//! |
| 79 | +//! #### `jump_to_node` |
| 80 | +//! |
| 81 | +//! ``` lua |
| 82 | +//! local node = graph:jump_to_node() |
| 83 | +//! ``` |
| 84 | +//! |
| 85 | +//! Returns the graph's jump-to node. |
| 86 | +//! |
| 87 | +//! #### `nodes` |
| 88 | +//! |
| 89 | +//! ``` lua |
| 90 | +//! for node in graph:nodes() do |
| 91 | +//! -- whatever |
| 92 | +//! end |
| 93 | +//! ``` |
| 94 | +//! |
| 95 | +//! Returns an iterator of every node in the stack graph. |
| 96 | +//! |
| 97 | +//! #### `root_node` |
| 98 | +//! |
| 99 | +//! ``` lua |
| 100 | +//! local node = graph:root_node() |
| 101 | +//! ``` |
| 102 | +//! |
| 103 | +//! Returns the graph's root node. |
| 104 | +//! |
| 105 | +//! ### Files |
| 106 | +//! |
| 107 | +//! The following Lua methods are available on a file instance: |
| 108 | +//! |
| 109 | +//! #### `definition_node` |
| 110 | +//! |
| 111 | +//! ``` lua |
| 112 | +//! local node = file:definition_node(symbol) |
| 113 | +//! ``` |
| 114 | +//! |
| 115 | +//! Adds a new definition node to this file. `symbol` must be a string, or an instance that can be |
| 116 | +//! converted to a string via its `tostring` method. |
| 117 | +//! |
| 118 | +//! #### `drop_scopes_node` |
| 119 | +//! |
| 120 | +//! ``` lua |
| 121 | +//! local node = file:drop_scopes_node() |
| 122 | +//! ``` |
| 123 | +//! |
| 124 | +//! Adds a new drop scopes node to this file. |
| 125 | +//! |
| 126 | +//! #### `exported_scope_node` |
| 127 | +//! |
| 128 | +//! ``` lua |
| 129 | +//! local node = file:exported_scope_node() |
| 130 | +//! ``` |
| 131 | +//! |
| 132 | +//! Adds a new exported scope node to this file. |
| 133 | +//! |
| 134 | +//! #### `internal_scope_node` |
| 135 | +//! |
| 136 | +//! ``` lua |
| 137 | +//! local node = file:internal_scope_node() |
| 138 | +//! ``` |
| 139 | +//! |
| 140 | +//! Adds a new internal scope node to this file. |
| 141 | +//! |
| 142 | +//! #### `pop_scoped_symbol_node` |
| 143 | +//! |
| 144 | +//! ``` lua |
| 145 | +//! local node = file:pop_scoped_symbol_node(symbol) |
| 146 | +//! ``` |
| 147 | +//! |
| 148 | +//! Adds a new pop scoped symbol node to this file. `symbol` must be a string, or an instance that |
| 149 | +//! can be converted to a string via its `tostring` method. |
| 150 | +//! |
| 151 | +//! #### `pop_symbol_node` |
| 152 | +//! |
| 153 | +//! ``` lua |
| 154 | +//! local node = file:pop_symbol_node(symbol) |
| 155 | +//! ``` |
| 156 | +//! |
| 157 | +//! Adds a new pop symbol node to this file. `symbol` must be a string, or an instance that can be |
| 158 | +//! converted to a string via its `tostring` method. |
| 159 | +//! |
| 160 | +//! #### `push_scoped_symbol_node` |
| 161 | +//! |
| 162 | +//! ``` lua |
| 163 | +//! local node = file:push_scoped_symbol_node(symbol, scope) |
| 164 | +//! ``` |
| 165 | +//! |
| 166 | +//! Adds a new push scoped symbol node to this file. `symbol` must be a string, or an instance |
| 167 | +//! that can be converted to a string via its `tostring` method. `scope` must be an exported scope |
| 168 | +//! node. |
| 169 | +//! |
| 170 | +//! #### `push_symbol_node` |
| 171 | +//! |
| 172 | +//! ``` lua |
| 173 | +//! local node = file:push_symbol_node(symbol) |
| 174 | +//! ``` |
| 175 | +//! |
| 176 | +//! Adds a new push symbol node to this file. `symbol` must be a string, or an instance that can |
| 177 | +//! be converted to a string via its `tostring` method. |
| 178 | +//! |
| 179 | +//! #### `reference_node` |
| 180 | +//! |
| 181 | +//! ``` lua |
| 182 | +//! local node = file:reference_node(symbol) |
| 183 | +//! ``` |
| 184 | +//! |
| 185 | +//! Adds a new definition node to this file. `symbol` must be a string, or an instance that can be |
| 186 | +//! converted to a string via its `tostring` method. |
| 187 | +//! |
| 188 | +//! #### `scoped_definition_node` |
| 189 | +//! |
| 190 | +//! ``` lua |
| 191 | +//! local node = file:scoped_definition_node(symbol) |
| 192 | +//! ``` |
| 193 | +//! |
| 194 | +//! Adds a new scoped definition node to this file. `symbol` must be a string, or an instance that |
| 195 | +//! can be converted to a string via its `tostring` method. |
| 196 | +//! |
| 197 | +//! #### `scoped_reference_node` |
| 198 | +//! |
| 199 | +//! ``` lua |
| 200 | +//! local node = file:scoped_reference_node(symbol) |
| 201 | +//! ``` |
| 202 | +//! |
| 203 | +//! Adds a new scoped reference node to this file. `symbol` must be a string, or an instance that |
| 204 | +//! can be converted to a string via its `tostring` method. |
| 205 | +//! |
| 206 | +//! ### Nodes |
| 207 | +//! |
| 208 | +//! The following Lua methods are available on a node instance: |
| 209 | +//! |
| 210 | +//! #### `add_edge_from` |
| 211 | +//! |
| 212 | +//! ``` lua |
| 213 | +//! node:add_edge_from(other, precedence) |
| 214 | +//! ``` |
| 215 | +//! |
| 216 | +//! Adds an edge from another node to this node. `precedence` is optional; it defaults to 0 if not |
| 217 | +//! given. |
| 218 | +//! |
| 219 | +//! #### `add_edge_to` |
| 220 | +//! |
| 221 | +//! ``` lua |
| 222 | +//! node:add_edge_to(other, precedence) |
| 223 | +//! ``` |
| 224 | +//! |
| 225 | +//! Adds an edge from this node to another node. `precedence` is optional; it defaults to 0 if not |
| 226 | +//! given. |
| 227 | +//! |
| 228 | +//! #### `debug_info` |
| 229 | +//! |
| 230 | +//! ``` lua |
| 231 | +//! let info = node:debug_info() |
| 232 | +//! ``` |
| 233 | +//! |
| 234 | +//! Returns a Lua table containing all of the debug info added to this node. |
| 235 | +//! |
| 236 | +//! #### `definiens_span` |
| 237 | +//! |
| 238 | +//! ``` lua |
| 239 | +//! let span = node:definiens_span() |
| 240 | +//! ``` |
| 241 | +//! |
| 242 | +//! Returns the definiens span of this node. (See [`set_definiens_span`](#set_definiens_span) for |
| 243 | +//! the structure of a span.) |
| 244 | +//! |
| 245 | +//! #### `local_id` |
| 246 | +//! |
| 247 | +//! ``` lua |
| 248 | +//! let local_id = node:local_id() |
| 249 | +//! ``` |
| 250 | +//! |
| 251 | +//! Returns the local ID of this node within its file. |
| 252 | +//! |
| 253 | +//! #### `set_debug_info` |
| 254 | +//! |
| 255 | +//! ``` lua |
| 256 | +//! node:add_debug_info(key, value) |
| 257 | +//! ``` |
| 258 | +//! |
| 259 | +//! Adds a new debug info to this node. `key` and `value` must each be a string, or an instance |
| 260 | +//! that can be converted to a string via its `tostring` method. |
| 261 | +//! |
| 262 | +//! #### `set_definiens_span` |
| 263 | +//! |
| 264 | +//! ``` lua |
| 265 | +//! node:set_definiens_span { |
| 266 | +//! start = { |
| 267 | +//! line = 1, |
| 268 | +//! column = { utf8_offset = 1, utf16_offset = 1, grapheme_offset = 1 }, |
| 269 | +//! -- UTF-8 offsets within the source file of the line containing the span |
| 270 | +//! containing_line = { start = 1, end = 14 }, |
| 271 | +//! -- UTF-8 offsets within the source file of the line containing the span, with leading and |
| 272 | +//! -- trailing whitespace removed |
| 273 | +//! trimmed_line = { start = 2, end = 12 }, |
| 274 | +//! }, |
| 275 | +//! end = { |
| 276 | +//! line = 2, |
| 277 | +//! column = { utf8_offset = 12, utf16_offset = 10, grapheme_offset = 8 }, |
| 278 | +//! containing_line = { start = 1, end = 14 }, |
| 279 | +//! trimmed_line = { start = 1, end = 14 }, |
| 280 | +//! }, |
| 281 | +//! } |
| 282 | +//! ``` |
| 283 | +//! |
| 284 | +//! Sets the definiens span of this node. All entries in the table are optional, and default to 0 |
| 285 | +//! if not provided. |
| 286 | +//! |
| 287 | +//! #### `set_span` |
| 288 | +//! |
| 289 | +//! ``` lua |
| 290 | +//! node:set_span { |
| 291 | +//! start = { |
| 292 | +//! line = 1, |
| 293 | +//! column = { utf8_offset = 1, utf16_offset = 1, grapheme_offset = 1 }, |
| 294 | +//! -- UTF-8 offsets within the source file of the line containing the span |
| 295 | +//! containing_line = { start = 1, end = 14 }, |
| 296 | +//! -- UTF-8 offsets within the source file of the line containing the span, with leading and |
| 297 | +//! -- trailing whitespace removed |
| 298 | +//! trimmed_line = { start = 2, end = 12 }, |
| 299 | +//! }, |
| 300 | +//! end = { |
| 301 | +//! line = 2, |
| 302 | +//! column = { utf8_offset = 12, utf16_offset = 10, grapheme_offset = 8 }, |
| 303 | +//! containing_line = { start = 1, end = 14 }, |
| 304 | +//! trimmed_line = { start = 1, end = 14 }, |
| 305 | +//! }, |
| 306 | +//! } |
| 307 | +//! ``` |
| 308 | +//! |
| 309 | +//! Sets the span of this node. All entries in the table are optional, and default to 0 if not |
| 310 | +//! provided. |
| 311 | +//! |
| 312 | +//! #### `set_syntax_type` |
| 313 | +//! |
| 314 | +//! ``` lua |
| 315 | +//! node:set_syntax_type(syntax_type) |
| 316 | +//! ``` |
| 317 | +//! |
| 318 | +//! Sets the syntax type of this node. `syntax_type` must be a string, or an instance that can be |
| 319 | +//! converted to a string via its `tostring` method. |
| 320 | +//! |
| 321 | +//! #### `span` |
| 322 | +//! |
| 323 | +//! ``` lua |
| 324 | +//! let span = node:span() |
| 325 | +//! ``` |
| 326 | +//! |
| 327 | +//! Returns the span of this node. (See [`set_span`](#set_span) for the structure of a span.) |
| 328 | +//! |
| 329 | +//! #### `syntax_type` |
| 330 | +//! |
| 331 | +//! ``` lua |
| 332 | +//! let syntax_type = node:syntax_type() |
| 333 | +//! ``` |
| 334 | +//! |
| 335 | +//! Returns the syntax type of this node. |
64 | 336 |
|
65 | 337 | // Implementation notes: Stack graphs, files, and nodes can live inside the Lua interpreter as
|
66 | 338 | // objects. They are each wrapped in a userdata, with a metatable defining the methods that are
|
|
0 commit comments