Skip to content

Instantly share code, notes, and snippets.

/test031.pl6 Secret

Created December 22, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/110c2f1b13d283014c6033f034e01d16 to your computer and use it in GitHub Desktop.
Save anonymous/110c2f1b13d283014c6033f034e01d16 to your computer and use it in GitHub Desktop.
perl6 grammar question
I'm trying to use perl6 and his grammar feature. The following code works well and help me to recognize instructions starting by '\' and ending by ' ;' :
__________________________________________
$ cat test031.pl6
#!/opt/rakudo-star-2016.10/bin/perl6
use v6;
grammar SQLP {
rule TOP {^^<cmdsqlplist> }
rule cmdsqlplist { <cmdsqlp> * }
rule cmdsqlp { :r [^^'\\' <ff> ';'] }
token ff { <-[\\;]>* }
}
my $ctl = q:to/FIN_INI/;
\echo coucou ;
\echo coucou ;
\set toto titit ;
FIN_INI
say $ctl;
say "-------";
my $scr = SQLP.parse($ctl);
say "scr:$scr";
say "-------";
$ perl6 test031.pl6
\echo coucou ;
\echo coucou ;
\set toto titit ;
-------
scr:\echo coucou ;
\echo coucou ;
\set toto titit ;
-------
My question is I'd like to recognize instructions starting by '\' and ending by « end of line ». I tried to replace ' ; ' by $$ ( I also tried <:Zl> ) in my previous code but without any success :
$ cat test032.pl6
#!/opt/rakudo-star-2016.10/bin/perl6
use v6;
grammar SQLP {
rule TOP {^^<cmdsqlplist> }
rule cmdsqlplist { <cmdsqlp> * }
rule cmdsqlp { :r [^^'\\' <ff> $$] }
token ff { <-[\\]>* }
}
my $ctl = q:to/FIN_INI/;
\echo coucou
\echo coucou
\set toto titit
FIN_INI
say $ctl;
say "-------";
my $scr = SQLP.parse($ctl);
say "scr:$scr";
say "-------";
$ perl6 sql032.pl6
\echo coucou
\echo coucou
\set toto titit
-------
Use of uninitialized value $scr of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
in block <unit> at sql032.pl6 line 22
scr:
-------
I don't understand why using $$ instead of ' ;' is not correct. Could you, please, help me ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment