Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- slava@dogbert:~/code/perl6$ cat grammar.pl6 ; ./grammar.pl6
- #!/home/slava/bin/perl6
- my @str =
- 'http://localhost',
- 'http://127.0.0.1',
- 'https://127.0.0.1',
- 'https://123123',
- ;
- grammar URL {
- token TOP {
- <protocol>'://'<host>
- }
- proto token protocol {*}
- token protocol:sym<http> { <sym> }
- token protocol:sym<https> { <sym> }
- token protocol:sym<ftp> { <sym> }
- token protocol:sym<ftps> { <sym> }
- proto token host {*}
- token host:sym<ipv4> { \d+ }
- token ipv42 {
- [<octet>\.]**1..3 <octet>
- }
- token octet {
- (\d**1..3) <?{ 0 <= $0 <= 255 }>
- }
- }
- for @str -> $s {
- if URL.parse($s) {
- $/<protocol>.say;
- $/<host>.say;
- }
- else {
- "no match!".say;
- }
- say '-------------';
- }
- no match!
- -------------
- no match!
- -------------
- no match!
- -------------
- 「https」
- sym => 「https」
- 「123123」
- -------------
- slava@dogbert:~/code/perl6$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement