-
-
Save anonymous/110c2f1b13d283014c6033f034e01d16 to your computer and use it in GitHub Desktop.
perl6 grammar question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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