in the alist, creating a parser for @var{language-a} actually creates a
parser for @var{language-b}. By extension, anything that creates a node
or makes a query of @var{language-a} will be redirected to use
-@var{language-b} instead.
+@var{language-b} instead. This mapping is completely transparent, the
+parser created will report as @var{language-b}, and the sames goes for
+nodes created by this parser.
-Note that calling @code{treesit-parser-language} on a parser for
-@var{language-a} still returns @var{language-a}.
+Specifically, the parser created by @code{treesit-parser-create} will
+report to use whatever @var{language} was given to it. For example,
+if language @code{cpp} is mapped to @code{cuda}:
+
+@example
+@group
+(setq treesit-language-remap-alist '((cpp . cuda)))
+
+(treesit-parser-language (treesit-parser-create 'cpp))
+;; => 'cpp
+
+(treesit-parser-language (treesit-parser-create 'cuda))
+;; => 'cuda
+@end group
+@end example
+
+Even though both parser are actually @code{cuda} parser.
@end defvar
@node Retrieving Nodes
treesit_check_buffer_size (buf);
- language = resolve_language_symbol (language);
- CHECK_SYMBOL (language);
+ Lisp_Object remapped_lang = resolve_language_symbol (language);
+ CHECK_SYMBOL (remapped_lang);
/* See if we can reuse a parser. */
if (NILP (no_reuse))
Lisp_Object signal_data = Qnil;
TSParser *parser = ts_parser_new ();
struct treesit_loaded_lang loaded_lang
- = treesit_load_language (language, &signal_symbol, &signal_data);
+ = treesit_load_language (remapped_lang, &signal_symbol, &signal_data);
TSLanguage *lang = loaded_lang.lang;
if (lang == NULL)
xsignal (signal_symbol, signal_data);
always succeed. */
ts_parser_set_language (parser, lang);
- /* Create parser. */
+ /* Create parser. Use the unmapped LANGUAGE symbol, so the nodes
+ created by this parser (and this parser) self identify as the
+ unmapped language. This makes the grammar mapping completely
+ transparent. */
Lisp_Object lisp_parser = make_treesit_parser (buf_orig,
parser, NULL,
language, tag);