unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Qeustion about Ftreesit_pattern_expand
@ 2024-06-24 21:26 Gerd Möllmann
  2024-06-26  4:54 ` Yuan Fu
  0 siblings, 1 reply; 7+ messages in thread
From: Gerd Möllmann @ 2024-06-24 21:26 UTC (permalink / raw)
  To: Emacs Devel

Not important, just as context: I wanted to see if igc works with
treesit Lisp objects, built with treesitter, and finally even got
grammars for C and C++ installed :-/. Font-locking didn't work in my
fork (CL packages), which I fixed.

My question:

Function Ftreesit_pattern_expand uses this to print Lisp objects:

  return Fprin1_to_string (pattern, Qnil, Qt);

where prin1 prints readably, and second arg nil means add escapes as
needed to that the result can be read back, by function read.

Why is it printing readably with escapes?

I know tree-sitter doesn't understand Lisp escaping because that was my
problem with the font-locking. Or, in other words, should the second arg
be Qt for don't escape?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Qeustion about Ftreesit_pattern_expand
  2024-06-24 21:26 Qeustion about Ftreesit_pattern_expand Gerd Möllmann
@ 2024-06-26  4:54 ` Yuan Fu
  2024-06-26  5:05   ` Gerd Möllmann
  0 siblings, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2024-06-26  4:54 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: Emacs Devel



> On Jun 24, 2024, at 2:26 PM, Gerd Möllmann <gerd.moellmann@gmail.com> wrote:
> 
> Not important, just as context: I wanted to see if igc works with
> treesit Lisp objects, built with treesitter, and finally even got
> grammars for C and C++ installed :-/. Font-locking didn't work in my
> fork (CL packages), which I fixed.
> 
> My question:
> 
> Function Ftreesit_pattern_expand uses this to print Lisp objects:
> 
>  return Fprin1_to_string (pattern, Qnil, Qt);
> 
> where prin1 prints readably, and second arg nil means add escapes as
> needed to that the result can be read back, by function read.
> 
> Why is it printing readably with escapes?
> 
> I know tree-sitter doesn't understand Lisp escaping because that was my
> problem with the font-locking. Or, in other words, should the second arg
> be Qt for don't escape?
> 

Thanks for checking this Gerd. IIUC, readably is controlled by the second argument, so it’s not redundant: if the second arg is Qnil, print readably (prin1), if it’s Qt, print without quotes and escapes (princ). I guess the function should’ve been called print-to-string to avoid confusion.

Yuan





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Qeustion about Ftreesit_pattern_expand
  2024-06-26  4:54 ` Yuan Fu
@ 2024-06-26  5:05   ` Gerd Möllmann
  2024-06-26  5:13     ` Yuan Fu
  0 siblings, 1 reply; 7+ messages in thread
From: Gerd Möllmann @ 2024-06-26  5:05 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Emacs Devel

Yuan Fu <casouri@gmail.com> writes:

>> On Jun 24, 2024, at 2:26 PM, Gerd Möllmann <gerd.moellmann@gmail.com> wrote:
>> 
>> Not important, just as context: I wanted to see if igc works with
>> treesit Lisp objects, built with treesitter, and finally even got
>> grammars for C and C++ installed :-/. Font-locking didn't work in my
>> fork (CL packages), which I fixed.
>> 
>> My question:
>> 
>> Function Ftreesit_pattern_expand uses this to print Lisp objects:
>> 
>>  return Fprin1_to_string (pattern, Qnil, Qt);
>> 
>> where prin1 prints readably, and second arg nil means add escapes as
>> needed to that the result can be read back, by function read.
>> 
>> Why is it printing readably with escapes?
>> 
>> I know tree-sitter doesn't understand Lisp escaping because that was my
>> problem with the font-locking. Or, in other words, should the second arg
>> be Qt for don't escape?
>> 
>
> Thanks for checking this Gerd. IIUC, readably is controlled by the
> second argument, so it’s not redundant: if the second arg is Qnil,
> print readably (prin1), if it’s Qt, print without quotes and escapes
> (princ). I guess the function should’ve been called print-to-string to
> avoid confusion.

Erm, there's a misunderstanding it seems. I'm not talking about function
names or anything, I'm basically saying that the function call to
Fprin1_to_string is wrong, and its second argument should be Qt
not Qnil :-)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Qeustion about Ftreesit_pattern_expand
  2024-06-26  5:05   ` Gerd Möllmann
@ 2024-06-26  5:13     ` Yuan Fu
  2024-06-26  5:34       ` Gerd Möllmann
  0 siblings, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2024-06-26  5:13 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: Emacs Devel



> On Jun 25, 2024, at 10:05 PM, Gerd Möllmann <gerd.moellmann@gmail.com> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>>> On Jun 24, 2024, at 2:26 PM, Gerd Möllmann <gerd.moellmann@gmail.com> wrote:
>>> 
>>> Not important, just as context: I wanted to see if igc works with
>>> treesit Lisp objects, built with treesitter, and finally even got
>>> grammars for C and C++ installed :-/. Font-locking didn't work in my
>>> fork (CL packages), which I fixed.
>>> 
>>> My question:
>>> 
>>> Function Ftreesit_pattern_expand uses this to print Lisp objects:
>>> 
>>> return Fprin1_to_string (pattern, Qnil, Qt);
>>> 
>>> where prin1 prints readably, and second arg nil means add escapes as
>>> needed to that the result can be read back, by function read.
>>> 
>>> Why is it printing readably with escapes?
>>> 
>>> I know tree-sitter doesn't understand Lisp escaping because that was my
>>> problem with the font-locking. Or, in other words, should the second arg
>>> be Qt for don't escape?
>>> 
>> 
>> Thanks for checking this Gerd. IIUC, readably is controlled by the
>> second argument, so it’s not redundant: if the second arg is Qnil,
>> print readably (prin1), if it’s Qt, print without quotes and escapes
>> (princ). I guess the function should’ve been called print-to-string to
>> avoid confusion.
> 
> Erm, there's a misunderstanding it seems. I'm not talking about function
> names or anything, I'm basically saying that the function call to
> Fprin1_to_string is wrong, and its second argument should be Qt
> not Qnil :-)

Ah, then I can explain. Basically I want to convert the sexp query

((function_definition) @defun
 "return" @keyword)

to a string that’s like this

"((function_definition) @defun
 "return" @keyword)"

If the second arg is Qt, the result would be

"((function_definition) @defun
 return @keyword)"

which is not what I want. Basically, strings need to be still quoted.

Yuan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Qeustion about Ftreesit_pattern_expand
  2024-06-26  5:13     ` Yuan Fu
@ 2024-06-26  5:34       ` Gerd Möllmann
  2024-06-26  6:04         ` Yuan Fu
  0 siblings, 1 reply; 7+ messages in thread
From: Gerd Möllmann @ 2024-06-26  5:34 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Emacs Devel

Yuan Fu <casouri@gmail.com> writes:

> which is not what I want. Basically, strings need to be still quoted.

I see, thanks.

The problem I had in my Emacs with CL packages was that ':' in symbols
is special because the colon separates package and symbol name. For
example X:Y is a symbol Y in packager X. A ':' in a symbol name thus
requires escaping to be able to be read back. Like 'name:' becomes
'name\:' so that the ':' isn't mistaken for a package separator.

I wonder if something similar can happen in GNU.

It's only the strings that need escaping right?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Qeustion about Ftreesit_pattern_expand
  2024-06-26  5:34       ` Gerd Möllmann
@ 2024-06-26  6:04         ` Yuan Fu
  2024-06-26  6:16           ` Gerd Möllmann
  0 siblings, 1 reply; 7+ messages in thread
From: Yuan Fu @ 2024-06-26  6:04 UTC (permalink / raw)
  To: Gerd Möllmann; +Cc: Emacs Devel



> On Jun 25, 2024, at 10:34 PM, Gerd Möllmann <gerd.moellmann@gmail.com> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> which is not what I want. Basically, strings need to be still quoted.
> 
> I see, thanks.
> 
> The problem I had in my Emacs with CL packages was that ':' in symbols
> is special because the colon separates package and symbol name. For
> example X:Y is a symbol Y in packager X. A ':' in a symbol name thus
> requires escaping to be able to be read back. Like 'name:' becomes
> 'name\:' so that the ':' isn't mistaken for a package separator.
> 
> I wonder if something similar can happen in GNU.

GNU? You mean Elisp?

> 
> It's only the strings that need escaping right?

Valid tree-sitter queries only contain lists, vectors, symbols (including keywords) and strings. I don’t know how does CL printer handle vectors. 

Yuan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Qeustion about Ftreesit_pattern_expand
  2024-06-26  6:04         ` Yuan Fu
@ 2024-06-26  6:16           ` Gerd Möllmann
  0 siblings, 0 replies; 7+ messages in thread
From: Gerd Möllmann @ 2024-06-26  6:16 UTC (permalink / raw)
  To: Yuan Fu; +Cc: Emacs Devel

Yuan Fu <casouri@gmail.com> writes:

> GNU? You mean Elisp?

GNU as opposed to my personal fork which I am using.
https://github.com/gerd-moellmann/emacs-with-cl-packages

>> It's only the strings that need escaping right?
>
> Valid tree-sitter queries only contain lists, vectors, symbols
> (including keywords) and strings. I don’t know how does CL printer
> handle vectors.

Ok, thanks.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-26  6:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-24 21:26 Qeustion about Ftreesit_pattern_expand Gerd Möllmann
2024-06-26  4:54 ` Yuan Fu
2024-06-26  5:05   ` Gerd Möllmann
2024-06-26  5:13     ` Yuan Fu
2024-06-26  5:34       ` Gerd Möllmann
2024-06-26  6:04         ` Yuan Fu
2024-06-26  6:16           ` Gerd Möllmann

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).