Skip Menu |
 

This queue is for tickets about the Regexp-Grammars CPAN distribution.

Report information
The Basics
Id: 75738
Status: open
Priority: 0/
Queue: Regexp-Grammars

People
Owner: Nobody in particular
Requestors: ingosch [...] gmx.at
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: results oddities
Download (untitled) / with headers
text/plain 1.5k
Hi, I need to extract nested data. They have many attributes besides their values, sometimes, but I'm mostly iterested in the values and the structure. parameter1= { name=> ... , value=>[ ... ], attr1 => ..., attr2 => ..., ... , } I would like to see as a result is %/ = { set1 => { parameter1 => [value1 , ... ], parameter2 => [value2, ... ], subset1 => { parameter3 => [value3, ...], ... }, set2 => { ... }, ... , } } I have several issues with the results, though. 1. As I understand, there is no simple way to change the key in the parent hash of a rule from <rule: rule1> to i.e. $MATCH{name}. 2. Do a subrule call whose name is evaluated at runtime. I.e. when the pattern matches String, call <String>, if it matche Long, call <Long>. In other words is there something evaluate subrule then use that value as name of another subrule call <rule: var> # "number"=int { 2 } "title"=string { "abc" } "float"=double { 2.578 3.0 5.0 6.3 7.1 10.0 } <name=string> = <type=(\w+) \{ <[value=eval (<\type> )]>? \} <token: int> [+-]?\d+ <token: string> \".*\" <token: double> <int>(\.\d+)? 3. In the sample code attached, I tried to experiment a little but am not really satisfied. How can I change the 'pro' key to the value of 'tab' (s. 1.)? The only solution appears to wrap it into another rule and assign the value matches to the name matches, right? I'd like to see a simpler solution like a <key: > directive.
Subject: testgr.pl
Download testgr.pl
text/x-perl 1.2k
#!/usr/bin/perl # use v5.10; use warnings; use strict; package Simple_Test; use Data::Dumper; sub new { my ($class)=@_; return bless $class; } sub row { my ($self,$res)=@_; my %h; say Dumper $res; $h{$res->{count}}=(($res->{arg})); return \%h; } sub tab { my ($self,$res)=@_; say Dumper $res; my %r; my @t; #say Dumper $res; if ($res->{tab}) { for my $row (@{%{$res}->{row}}) { say "Row ",Dumper $row; push @t,%{$row}; } %r=@t; say "Array @t - hash ",Dumper (%r); return bless \%r; } else { $r{$res->{not}}=$res->{sc}; say Dumper $res; return bless \%r; } } 1; my $gr=do { use Regexp::Grammars; qr{ # <debug: on> <nocontext:> <all> #<pro> <rule: all> <MATCH=pro> <token: int> [+-]?\d++ <token: literal> [.'!%\\\w_\^@\+\-\(\)\(\)\#{}\\\[\]]++ <minimize:> <objrule: pro> (<?literal> <tab=(\w+Table)> <[row]>+ % <ws> |<not=literal> <sc=int>?) #<rule: tab> #(?=<literal>) \w+Table <objrule: row> <count=int> (<arg=literal>)? # (?{$ARG{tab}->{tab}=>{};$ARG{tab}->{tab}->{$MATCH{int}}=>$MATCH{literal};}) #(?{$MATCH{eval ($MATCH{int})}=>($MATCH{literal}); }) }xms; }; while (my $line = <>) { if ($line =~ $gr->with_actions('Simple_Test')) { use Data::Dumper 'Dumper'; say "Result: ",Dumper \%/; } }
Subject: results processing
From: ingosch [...] gmx.at
I think I should alter the priority to enhancement request, but I fear that's not possible.
Subject: Re: [rt.cpan.org #75738] results processing
Date: Fri, 16 Mar 2012 07:32:24 +1100
To: bug-Regexp-Grammars [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Download (untitled) / with headers
text/plain 324b
Show quoted text
> I think I should alter the priority to enhancement request, but I fear > that's not possible.
Not a problem. I am interested in the issues you raise, but I am snowed under with work just at the moment. I will respond properly as soon as I have the opportunity, but I'm afraid that may not be until mid-April. :-( Damian


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.