Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Discovered pattern that ideally parses any quoting. Brackets highlighting in FSH.



There was __idx assign missing, and I fine-tuned readibility, so final version:

_mybuf="A\AB'A'C" #input
while  [[ $_mybuf = (#b)[^ABC\"\'\\]#(([ABC\"\'])|[\\](*))(*) ]]; do
    [[ -n "${match[3]}" ]] && {
        __idx+=${mbegin[1]}+1
        _mybuf="${match[3]:1}" # also skip 1 quoted char
    } || {
        __idx+=${mbegin[1]}
        [[ -z "$__quoting" ]] && {
            if [[ "${match[1]}" = [ABC] ]]; then
                echo "Got ${match[1]}"
            fi
        }

        # Toggle quoting
        [[ "${match[1]}" = \" && "$__quoting" != \' ]] && {
                [[ "$__quoting" = \" ]] && __quoting= || __quoting=\";
        }
        [[ "${match[1]}" = \' && "$__quoting" != \" ]] && {
                [[ "$__quoting" = \' ]] && __quoting= || __quoting=\';
        }

        # The last (*) in the pattern, i.e. remaining
        # string, to become next input to while
        _mybuf="${match[4]}"
   }
done



Messages sorted by: Reverse Date, Date, Thread, Author