jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
52 stars 4 forks source link

Braces inside the function definition are broken #95

Open SivkovSavely opened 4 months ago

SivkovSavely commented 4 months ago

The code with a problem is:

catch() {
    {
        IFS=$'\n' read -r -d '' "${1}";
        IFS=$'\n' read -r -d '' "${2}";
        (IFS=$'\n' read -r -d '' _ERRNO_; return ${_ERRNO_});
    } < <((printf '\0%s\0%d\0' "$(((({ shift 2; "${@}"; echo "${?}" 1>&3-; } | tr -d '\0' 1>&4-) 4>&2- 2>&1- | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)" "${?}" 1>&2) 2>&1)
}

It looks like:

Full code: image As you can see, some things inside the function check are broken, and after the function definition it's completely broken.

It should look like:

I couldn't fix it completely, but something like this, I guess: image

The problem is in this part:

"$(((({ shift 2; "${@}"; echo "${?}" 1>&3-; } | tr -d '\0' 1>&4-) 4>&2- 2>&1- | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)"

I honestly don't know what sorcery is used to make this work (this function works the way I need it), but this part breaks the syntax highlight.

Here is the full expression from the last line of the function, minus the } < < part: image

As you can see, the two opening parentheses in the beginning do not match the closing parentheses in the end (after 1>&2 and 2>&1 respectively), even though they should, because they do when I remove the offending string.

I couldn't figure out what exactly breaks the syntax, you can try removing parts of the offending string and some other parts will be colored differently, but still in a broken way.

Maybe this function's syntax is just too complex for a regex? Or is there no impossible things in regex?