ctags icon indicating copy to clipboard operation
ctags copied to clipboard

[RFC] `$` with default value

Open masatake opened this issue 1 year ago • 1 comments

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?

masatake avatar Sep 13 '24 23:09 masatake

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.

AmaiKinono avatar Sep 17 '24 16:09 AmaiKinono