- if ($tag =~ / ^ (\w+) /x && $TAGS->{$1}) {
- $tag =~ s{ ^ (\w+) \s* $QR_COMMENTS }{}ox;
- ($START, $END) = @{ $TAGS->{$1} };
- } elsif ($tag =~ s{ ^ (\S+) \s+ (\S+) \s* $QR_COMMENTS }{}ox) {
- ($START, $END) = ($1, $2);
+ my $end;
+ if ($$str_ref =~ m{
+ \G (\w+) # tags name
+ \s* $QR_COMMENTS # optional comments
+ ([+~=-]?) ($END) # forced close
+ }gcx) {
+ my $ref = $TAGS->{lc $1} || $self->throw('parse', "Invalid TAGS name \"$1\"", undef, pos($$str_ref));
+ ($START, $END) = @$ref;
+ ($post_chomp, $end) = ($2, $3);
+
+ } elsif ($$str_ref =~ m{
+ \G (\S+) \s+ (\S+) # two non-space things
+ (?:\s+(un|)quoted?)? # optional unquoted adjective
+ \s* $QR_COMMENTS # optional comments
+ ([+~=-]?) ($END) # forced close
+ }gcxo) {
+ ($START, $END, my $unquote, $post_chomp, $end) = ($1, $2, $3, $4, $5);
+ for ($START, $END) {
+ if ($unquote) { eval { "" =~ /$_/; 1 } || $self->throw('parse', "Invalid TAGS \"$_\": $@", undef, pos($$str_ref)) }
+ else { $_ = quotemeta $_ }
+ }
+ } else {
+ $self->throw('parse', "Invalid TAGS", undef, pos($$str_ref));