in reply to How to use Regexp::Common patterns in Regexp::Grammars?

Is there a simpler way to use Regexp::Common patterns in a Regexp::Grammar?

there is a proper way

<token: Quoted_String> (...) # ... Comes from v 1.24567 # $RE{delimited}{ -delim => q{'} }{ -esc=>q{'}}

because version compatibility maybe https://metacpan.org/pod/Regexp::Grammars#IMPORTANT-CONSTRAINTS-AND-LIMITATIONS

maybe

  • Comment on Re: How to use Regexp::Common patterns in Regexp::Grammars? (Properly)
  • Download Code

Replies are listed 'Best First'.
Re^2: How to use Regexp::Common patterns in Regexp::Grammars? (Properly)
by clueless newbie (Curate) on Jun 09, 2022 at 19:07 UTC

    I've no idea what I'm doing wrong but unfortunately for me, both a bare $RE... and #$RE... fails for me.

    use 5.026; use Carp; use Data::Dumper; use Readonly; use Regexp::Common qw[ delimited ]; use Regexp::Grammars; use Try::Tiny; BEGIN { say "Regexp::Common: $Regexp::Common::VERSION"; say "Regexp::Grammars: $Regexp::Grammars::VERSION"; } try { my $grammar = qr{ <nocontext:> <TEST> <rule: TEST> <Quoted_String> <token: Quoted_String> $RE{delimited}{-delim=>q{'}}{-esc=> +q{'}} }; if (q{'some string with containing a '''} =~ $grammar) { warn Data::Dumper->new([\%/],[qw(*/)])->Deepcopy(1)->Indent(1) +->Maxdepth(3)->Sortkeys(1)->Dump(),q{ }; }; } catch { Carp::cluck $_ }; # line 24 try { my $grammar = qr{ <nocontext:> <TEST> <rule: TEST> <Quoted_String> <token: Quoted_String> #$RE{delimited}{-delim=>q{'}}{-esc= +>q{'}} }; if (q{'some string with containing a '''} =~ $grammar) { warn Data::Dumper->new([\%/],[qw(*/)])->Deepcopy(1)->Indent(1) +->Maxdepth(3)->Sortkeys(1)->Dump(),q{ }; }; } catch { Carp::cluck $_ }; # line 36

    yields

    >perl re.t Regexp::Common: 2017060201 Regexp::Grammars: 1.057 Not a SCALAR reference at C:/berrybrew/5.32.1_64/perl/site/lib/Regexp/ +Grammars.pm line 106. at ..\..\test\re.t line 24. main::catch {...} ("Not a SCALAR reference at C:/berrybrew/5.3 +2.1_64/perl/site/li"...) called at C:/berrybrew/5.32.1_64/perl/lib/Tr +y/Tiny.pm line 123 Try::Tiny::try(CODE(0xf9c1a0), Try::Tiny::Catch=REF(0x2819630) +) called at ..\..\test\re.t line 24 Not a SCALAR reference at C:/berrybrew/5.32.1_64/perl/site/lib/Regexp/ +Grammars.pm line 106. at ..\..\test\re.t line 36. main::catch {...} ("Not a SCALAR reference at C:/berrybrew/5.3 +2.1_64/perl/site/li"...) called at C:/berrybrew/5.32.1_64/perl/lib/Tr +y/Tiny.pm line 123 Try::Tiny::try(CODE(0xf9c1a0), Try::Tiny::Catch=REF(0xe581f8)) + called at ..\..\test\re.t line 36
      Ok. This is a comment describing the source of regex pattern # $RE{delimited}{ -delim => q{'} }{ -esc=>q{'}}

      the idea is to replace ... with the string generated by printing $RE{delimited}{ -delim => q{'} }{ -esc=>q{'}}

      its ok to inline regexp::common patterns . no $pat or @{[ ]} required