anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.63k stars 130 forks source link

parsing error? #59

Closed greg-minshall closed 2 months ago

greg-minshall commented 2 months ago

hi. i'm running 4.3.1 on arch linux. a file with just the following lines in it

    if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
        option2=${option/"${BASH_REMATCH[1]}"/}
        option2=${option2%%[<{().[]*}
        options+=("${option2/=*/=}")
        option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"}
    fi

gets

x.sh: Unexpected end of file
The file's end was reached without closing all sytactic scopes.
Either, the parser got lost, or the file is truncated or malformed.

cheers.

anordal commented 2 months ago

The parser counts curly braces in variable expansions to handle recursion (#39). The problem is the different number of opening and closing curly braces in this variable substitution:

${option2%%[<{().[]*}

I guess the string "[<{().[]" is to be taken literally in this case. In my defense, GitHub's syntax highlighter gives up after the second opening curly brace.

I need to revisit that recursion handling and see if not counting ${ and } instead would be more correct.

Thanks for reporting.

greg-minshall commented 2 months ago

you're welcome. thanks for the explanation -- i was curious if it would be the extra square bracket or the curly brace. and, thanks for the tool!