On Tue, Aug 7, 2012 at 11:54 PM, David Korn <d...@research.att.com> wrote:
> cc: g...@research.att.com
> Subject: Re: 
> =?UTF-8?Q?More_=22fun=22=28=3D=E2=98=A0=29_with_types_and_=28nested=29_namerefs_po?=
>   =?UTF-8?Q?inting_to_type_members?=
> --------
>
>> namespace xmlfragmentparser
>> {
>> typeset -T parser_t=(
>> ...
>
> I found and fixed two bugs.  However, with set -o nounset, I get
>
> bug[58]: xd.build_context: line 35: .sh.match[2][j]: parameter not set
>
> and I do not get the full output.
>
> However, if I remove this line, then I get the full output.
> It appears to be that .sh.match[2][j] is unset.
> Can you check this and if I am wrong, send me a case that just
> has the pattern match.

Most of the issues are gone in ksh93v-...
... but a slight modification causes it to fail again... ;-(

Example (I've attached it as "ksh93v_typeset_T_nameref_fails001.sh.gz", too):
-- 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
                                for (( j=0 ; j < ${#.sh.match[0][@]} ; j++ )) ; 
do
                                        if [[ -v .sh.match[2][j] && -v 
.sh.match[3][j] ]] ; then
                                                currc.attrs+=( 
name="${.sh.match[2][j]}" value="${.sh.match[3][j]}" )
                                        fi ; if [[ -v .sh.match[4][j] && -v 
.sh.match[5][j] ]] ; then
                                                currc.attrs+=( 
name="${.sh.match[4][j]}" value="${.sh.match[5][j]}" )
                                        fi ; if [[ -v .sh.match[6][j] && -v 
.sh.match[7][j] ]] ; then
                                                currc.attrs+=( 
name="${.sh.match[6][j]}" value="${.sh.match[7][j]}" )
                                        fi
                                done
                                #print -u2 -v currc.attrs
                                #print -u2 -v .sh.match
                        fi
                done
                return 0
        }
)
}

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

        print "$xd"

        return 0
}

# main
set -o nounset
main

#EOF.
-- 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 ast-ksh.2012-08-13 (ksh93v- alpha) just prints garbage:
-- snip --
(
        typeset -a data=(
                $'<foo x=\'1\' y=\'2\' />'
                $'<bar a=\'1\' b=\'2\' />'
        )
(
)
-- snip --
(note the unbalanced ')'+'(' ... ;-( ).

AFAIK the offending line is the "nameref currc=_.context[i]" ...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

Attachment: ksh93v_typeset_T_nameref_fails001.sh.gz
Description: GNU Zip compressed data

_______________________________________________
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to