Hi!

----

The follwoing example code...
-- snip --
namespace xmlfragmentparser
{
typeset -T parser_t=(
        typeset -a data         # "raw" data from .sh.match
        compound -a context     # parsed tag data

        function build_context
        {
                typeset dummy
                typeset attrdata # data after "<tag" ...

                integer i
                for (( i = 0 ; i < ${#_.data[@]} ; i++ )) ; do
                        nameref currc=_.context[$i] # current context

                        dummy="${_.data[i]/~(El)<([:_[:alnum:]-]+)(.*)>/X}"
                        currc.tagname="${.sh.match[1]}"
                        attrdata="${.sh.match[2]}"

                        if [[ "${attrdata}" != ~(Elr)[[:space:]]* ]] ; then
                                dummy="${attrdata//~(Ex-p)(?:
                                                [[:space:]]+
                                                ( # four different types of 
name=value syntax
                                                        
(?:([:_[:alnum:]-]+)=([^\"\'[:space:]]+?))|     #x='foo=bar huz=123'
                                                        
(?:([:_[:alnum:]-]+)=\"([^\"]*?)\")|            #x='foo="ba=r o" huz=123'
                                                        
(?:([:_[:alnum:]-]+)=\'([^\']*?)\')|            #x="foox huz=123"
                                                        (?:([:_[:alnum:]-]+))   
                        #x="foox huz=123"
                                                )
                                        )/D}"

                                integer j k
                                compound -a currc.attrs
                                nameref attrs=currc.attrs
                                for ((j=0 ; j < ${#.sh.match[0][@]} ; j++ )) ; 
do
                                        # FIXME: Replace "! -z" with "-v" once 
-v works on .sh.match
                                        if [[ ! -z "${.sh.match[2][j]}" && ! -z 
"${.sh.match[3][j]}" ]] ; then
                                                attrs+=( 
name="${.sh.match[2][j]}" value="${.sh.match[3][j]}" )
                                        elif [[ ! -z "${.sh.match[4][j]}" && ! 
-z "${.sh.match[5][j]}" ]] ; then
                                                attrs+=( 
name="${.sh.match[4][j]}" value="${.sh.match[5][j]}" )
                                        elif [[ ! -z "${.sh.match[6][j]}" && ! 
-z "${.sh.match[7][j]}" ]] ; then
                                                attrs+=( 
name="${.sh.match[6][j]}" value="${.sh.match[7][j]}" )
                                        fi
                                done
                                print -u2 -v attrs
                                #print -u2 -v .sh.match
                        fi
                done

        }
)
}

# main
set -o nounset

.xmlfragmentparser.parser_t xd # xml document
xd.data=( "<foo x='1' y='2' />" "<bar a='1' b='2' />" )
xd.build_context

print "$xd"
-- snip --

... should AFAIK print something like this...
-- snip --
(
                typeset -a data=(
                        $'<foo x=\'1\' y=\'2\' />'
                        $'<bar a=\'1\' b=\'2\' />'
                )
                typeset -a context=(
                        [0]=(
                                typeset -a attrs=(
                                        [0]=(
                                                name=x
                                                value=1
                                        )
                                        [1]=(
                                                name=y
                                                value=2
                                        )
                                )
                                tagname=foo
                        )
                        [1]=(
                                typeset -a attrs=(
                                        [0]=(
                                                name=a
                                                value=1
                                        )
                                        [1]=(
                                                name=b
                                                value=2
                                        )
                                )
                                tagname=bar
                        )
                )
        )
)
-- snip --
... but instead ast-ksh.2012-07-27 gives me lots of weired error
messages like "x.sh[58]: xd.build_context[44]: print: xd: is not an
element of xd" and doesn't have a 2nd array element in the "attrs"
arrays ([1]).

AFAIK the main trouble is caused by the line with "nameref
attrs=currc.attrs" (which causes that currc.attrs remains empty) and
the namespace (which triggers the " xd: is not an element of xd"
warning...)...

[1]=this is likely the previously reported issue with ${#.sh.match[0][@]}

----

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