in reply to Re: Re: Re: Parsing arguments
in thread Parsing arguments
Bother, lots of problems. foo=foo=foo isn't supposed to be allowed, but the post-processing phase could check for that; .*?D really shouldn't be slower than [^D]*D - I'll have to take a look why that happens and see if it can be fixed (the minimal matching support was added to perl relatively recently, and it hasn't had the same degree of optimisation that the older codepaths have had)
I think the [^\\] is marginally clearer about its intent than . would be, though I accept the point; the missing /s and support for the colon delimiter were simply oversights; and the tail assertion should have been (?= \s | \z ).
So let's try again:
while (pos($_) < length($_)) { if (m{ \G (\w+) \s* = \s* (?=\S) }gcx) { # key-value pair is fixed-up in post-processing push @args [ $1 ]; } elsif (m{ \G (\w+) (?= \s | \z ) \s* }gcx) { push @args, $1; } elsif (m{ \G (['"]) ( \\. | [^\\] )*? \1 (?= \s | \z ) \s* }gcxs) { (my $quoted = $2) =~ s/\\(.)/$1/g; push @args, $quoted; } elsif (m{ \G (:) \s+ }) { push @args, $1; } else { die "parsing error\n"; } } for (my $i = 0; $i < @args; ++$i) { next unless ref $args[$i]; my $value = splice @args, $i+1, 1; die "parsing error\n" if !defined($value) || ref $value; $args[$i] = [ $args[$i], $value ]; }
Update: string inconsistently used as $tag and $_, fixed up to use $_ throughout.
Hugo
|
|---|