carlos-montiers / enhancedbatch

Enhances your windows command prompt https://www.enhancedbatch.com
Other
5 stars 1 forks source link

Change syntax of the Filter arguments #21

Closed carlos-montiers closed 4 years ago

carlos-montiers commented 5 years ago

I propose change the syntax for the filter arguments from use two square brackets to a single colon.

For example from this: trim[ oy] to trim: oy

That will simplify the usage.

adoxa commented 5 years ago

Colon is already used by CMD.

carlos-montiers commented 5 years ago

I tested this:

set "$var=[ oKay ]"
echo !$var;trim[ oy]!
echo !$var;trim: oy]!
echo !$var;trim: oy!

It outputs:

Kay ]
$var;trim: oy]
$var;trim: oy

Thus for some reason inly works with square brackets and that is what I want remove for use a single colon as begin of the argument.

adoxa commented 5 years ago

Colon is used by CMD, so EB sees $var;trim as the variable. Disable CMD extensions if you want to use colon.

carlos-montiers commented 5 years ago

Colon is used by CMD, so EB sees $var;trim as the variable. Disable CMD extensions if you want to use colon.

Mmm thus the colon should be a prohibited character for use in the filters, it will confuse the sentence? Maybe we can do some trick inthe lex stage?

adoxa commented 5 years ago

No, it doesn't go through lex, it would require a patch. Just disable extensions.

What you're actually asking is how to add [ and ] to the list: it's not nested, so after the opening bracket [ is just a character; the list can't be empty, so ] immediately after the opening [ is just a character. Thus to trim [] use trim[][] - open [, character ], character [, close ]. Sorry I didn't make that clear.

carlos-montiers commented 5 years ago

No, it doesn't go through lex, it would require a patch. Just disable extensions.

Maybe we can automatically disable extensions and reenable when the : character appears in the filter, currently I cannot filter the colon:

set "$var= oKay: "
echo !$var;trim[:a]!

Or maybe add a mechanism for allow trim the colon character, for example: colontrim (trim including colon) ?

adoxa commented 5 years ago

In order to know if colon is in the list we would have to parse the line before CMD sees it (which we could do, but it's a waste of time). Delayed expansion doesn't work, either, as it's already expanded at this point. Could provide a substitute (e.g. if we see U+FF3A replace it with U+003A) or escape it (some sort of equivalent to \x3a), but it doesn't seem worth it. Just disable extensions.

set @extensions=0
echo !$var;trim[:a]!
set @extensions=1
carlos-montiers commented 4 years ago

I add this note about this workaround for the colon character in the documentation