Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex named capture example causes error #7

Open
7stud opened this issue Jan 7, 2017 · 0 comments
Open

Regex named capture example causes error #7

7stud opened this issue Jan 7, 2017 · 0 comments

Comments

@7stud
Copy link

7stud commented Jan 7, 2017

In Introduction to Perl 6 Regex, in the section titled matching Perl variables, it looks like the syntax for Regex named captures has changed from:

$<foo>:=[       ] 

to:

$<foo>=[         ] 
$ perl6 -v
This is Rakudo version 2016.11 built on MoarVM version 2016.11
implementing Perl 6.c.

$ cat 3.pl
# vim: filetype=perl6

'ABC123' ~~ / $<foo>:=[ <[A..Z]+[0..9]>**4 ] /;
say $/<foo>;

$ perl6 3.pl
===SORRY!===
Unrecognized regex metacharacter = (must be quoted to match literally)
at /Users/7stud/p6_programs/3.pl:4
------> 'ABC123' ~~ / $<foo>:⏏=[ <[A..Z]+[0..9]>**4 ] /;
Unable to parse regex; couldn't find final '/'
at /Users/7stud/p6_programs/3.pl:4
------> 'ABC123' ~~ / $<foo>:=⏏[ <[A..Z]+[0..9]>**4 ] /;

And after changing := to =:

$ cat 4.pl
# vim: filetype=perl6

'ABC123' ~~ / $<foo>=[ <[A..Z]+[0..9]>**4 ] /;
say $/<foo>;

~/p6_programs$ perl6 4.pl
「ABC1」

I was initially confused by the named capture example anyway because it wasn't clear what the syntax for a named capture actually was. perl6 has so much strange punctuation that I thought the := was some sort of perl6 regex kung fu rather than the syntax for named captures, so an example of the syntax without a regex cluttering things up would have been clearer, e.g. "Named captures use the following syntax:

$<foo>=[ regex here ] 
@7stud 7stud changed the title Example causes error Named capture example causes error Jan 7, 2017
@7stud 7stud changed the title Named capture example causes error Regex: named capture example causes error Jan 7, 2017
@7stud 7stud changed the title Regex: named capture example causes error Regex named capture example causes error Jan 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant