A node can be ``extra'': such nodes represent things like comments,
which can appear anywhere in the text.
+@cindex tree-sitter outdated node
+@cindex outdated node, tree-sitter
+A node can be ``outdated'': If its parser has reparse at least once
+after the node was created, the node is outdated.
+
@cindex tree-sitter node that has error
@cindex has error, tree-sitter node
A node ``has error'' if the text it spans contains a syntax error. It
@defun treesit-node-check node property
This function checks if @var{node} has the specified @var{property}.
-@var{property} can be @code{named}, @code{missing}, @code{extra}, or
-@code{has-error}.
+@var{property} can be @code{named}, @code{missing}, @code{extra},
+@code{outdated}, or @code{has-error}.
@end defun
@defun treesit-node-type node
Named nodes have ``types'' (@pxref{tree-sitter node type, node type}).
For example, a named node can be a @code{string_literal} node, where
-@code{string_literal} is its type.
+@code{string_literal} is its type. The type of an anonymous node is
+just the text that node represents, e.g., the type of a @samp{,} node
+is just @samp{,}.
This function returns @var{node}'s type as a string.
@end defun
Ftreesit_node_check, Streesit_node_check, 2, 2, 0,
doc: /* Return non-nil if NODE has PROPERTY, nil otherwise.
-PROPERTY could be `named', `missing', `extra', or `has-error'.
+PROPERTY could be `named', `missing', `extra', `outdated', or `has-error'.
Named nodes correspond to named rules in the language definition,
whereas "anonymous" nodes correspond to string literals in the
Extra nodes represent things like comments, which are not required the
language definition, but can appear anywhere.
+A node is "outdated" if the parser has reparsed at least once after
+the node was created.
+
A node "has error" if itself is a syntax error or contains any syntax
errors. */)
(Lisp_Object node, Lisp_Object property)
{
if (NILP (node)) return Qnil;
- treesit_check_node (node);
+ CHECK_TS_NODE (node);
CHECK_SYMBOL (property);
treesit_initialize ();
TSNode treesit_node = XTS_NODE (node)->node;
bool result;
+
+ if (EQ (property, Qoutdated))
+ return treesit_node_uptodate_p (node) ? Qnil : Qt;
+
+ treesit_check_node (node);
if (EQ (property, Qnamed))
result = ts_node_is_named (treesit_node);
else if (EQ (property, Qmissing))
result = ts_node_has_error (treesit_node);
else
signal_error ("Expecting `named', `missing', `extra', "
- "or `has-error', but got",
+ "`outdated', or `has-error', but got",
property);
return result ? Qt : Qnil;
}
DEFSYM (Qnamed, "named");
DEFSYM (Qmissing, "missing");
DEFSYM (Qextra, "extra");
+ DEFSYM (Qoutdated, "outdated");
DEFSYM (Qhas_error, "has-error");
DEFSYM (Qnot_found, "not-found");