Make treesit-language-remap-alist completely transparent (bug#72388)
* doc/lispref/parsing.texi (Using Parser): Update manual. * src/treesit.c (Ftreesit_parser_create): Use the LANGUAGE argument given as the language for the parser, not the actual language.
This commit is contained in:
parent
9093a0f824
commit
4581351556
2 changed files with 27 additions and 7 deletions
|
@ -570,10 +570,27 @@ The value of this variable should be an alist of
|
|||
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
|
||||
|
|
|
@ -1657,8 +1657,8 @@ an indirect buffer. */)
|
|||
|
||||
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))
|
||||
|
@ -1679,7 +1679,7 @@ an indirect buffer. */)
|
|||
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);
|
||||
|
@ -1687,7 +1687,10 @@ an indirect buffer. */)
|
|||
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue