universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.49k stars 620 forks source link

[RFC] `$` with default value #4076

Open masatake opened 1 week ago

masatake commented 1 week ago

I have many chances to write the -Q expression.

I found I had to write $ with a fallback value to make readtags run without error:

(or ($ "properties") "")
($ "properties" "")
(or $extras "")

To make the expressions shorter, I want to add a short-hand variant for these expressions:

($: "properties")
$:extras

@AmaiKinono, you have a lot of experience in this area. Could you give me comments?

AmaiKinono commented 6 days ago

The proposed $: operator is handy if the empty string is a reasonable fallback value in most situations. But I may not have enough experience to answer this, as Citre uses another strategy.

Say we are given an expression (eq? $name "foo"). Citre scans all field name symbols in it, and add an explicit check in the generated filter:

(and $name (eq? $name "foo"))

So the expression returns false if $name is missing. And, if we require Citre to keep the lines with missing fields, it generates:

(or (not $name) (eq? $name "foo"))

So the concept of fallback value is not used. See citre-readtags-regexp-quote for details.