Hi!

----

Below is another testcase for .sh.match and typeset -m:
-- snip --



function parse_attr
{
        typeset move_mode=$1
        typeset attrdata="$2"
        integer i

        typeset dummy="${attrdata//~(Ex-p)(?:
        [[:space:]]+
        ( # four different types of name=value syntax
                (?:([:_[:alnum:]-]+)=([^\"\'[:space:]]+?))|
                (?:([:_[:alnum:]-]+)=\"([^\"]*?)\")|    
                (?:([:_[:alnum:]-]+)=\'([^\']*?)\')|    
                (?:([:_[:alnum:]-]+))                   
        )
        )/D}"
        
        case ${move_mode} in
                'plain')
                        nameref m=.sh.match
                        ;;
                'move')
                        typeset -m m=.sh.match
                        ;;
                'move_to_compound')
                        compound mc
                        typeset -m mc.m=.sh.match
                        nameref m=mc.m
                        ;;
                'move_to_nameref_compound')
                        compound mc
                        nameref mcn=mc
                        typeset -m mcn.m=.sh.match
                        nameref m=mcn.m
                        ;;
                *)
                        print -u2 -f '# wrong move_mode=%q\n' "${move_mode}"
                        return 1
                        ;;
        esac

        for (( i=0 ; i < fmax(1, ${#m[0][@]}) ; i++ )) ; do
                [[ -v m[2][i] && -v m[3][i] ]] && printf '%q=%q\n' "${m[2][i]}" 
"${m[3][i]}"
                [[ -v m[4][i] && -v m[5][i] ]] && printf '%q=%q\n' "${m[4][i]}" 
"${m[5][i]}"
                [[ -v m[6][i] && -v m[7][i] ]] && printf '%q=%q\n' "${m[6][i]}" 
"${m[7][i]}"
        done
        print "Nummatches=${#m[0][@]}"
        return 0
}

for s in 'plain' 'move' 'move_to_compound' 'move_to_nameref_compound' ; do
        parse_attr "$s" $' aname=avalue x=y'
done
-- snip --
... in theory it should print:
-- snip --
aname=a
x=y
Nummatches=2
aname=a
x=y
Nummatches=2
aname=a
x=y
Nummatches=2
aname=a
x=y
Nummatches=2
-- snip --
... but ast-ksh.2012-08-24 currently prints this:
-- snip --
aname=a
x=y
Nummatches=2
' aname=a'=' aname=a'
' x=y'=' x=y'
Nummatches=2
' aname=a'=' aname=a'
' x=y'=' x=y'
Nummatches=2
' aname=a'=' aname=a'
' x=y'=' x=y'
Nummatches=2
-- snip --

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to