Skip to content

Instantly share code, notes, and snippets.

View samcv's full-sized avatar

Samantha McVey samcv

  • Amsterdam, Netherlands
View GitHub Profile
#!/usr/bin/env perl6
grammar http {
regex TOP { .* <url> .* }
regex url { <protocol> <protocoldel> <body>? (<after>+)? }
token protocol { (http)|(https)|(ftp)|(git)|(ssh) }
token protocoldel { '://' }
token body { <units>+ }
token units { <:Letter>|'.' }
token after { <seperator> (<allowed>+)? }
token seperator { '/' }
use v6;
=TITLE URL::Find
=SUBTITLE A Perl 6 module to find all the URL's in a set of text.
=head1 DESCRIPTION
=para
By default it will match domain names
that use unicode characters such as http://правительство.рф. To only match ASCII domains use the
:ascii option. It will also find URL's that end in one of the restricted characters, so
`https://www.google.com, ` will pull out `https://www.google.com`. It will find all the URL's in a
text by default, or you can specify a maximum number with the :limit option. By default it will
grammar url {
regex TOP { <anyprotocol> '://' <base> [ ['/' <term>]+ ]? '/'? }
token anyprotocol { <[ a..z A..Z ]> <[ a..z A..Z 0..9 . + - ]>+ }
token protocol {:i [http|https|ftp|git|ssh] }
token baseascii { [ <[a..z A..Z 0..9 \- . ]> ]+ }
token base { [ <:Number + :Letter + [ . - ]> ]+ }
token protected { <[ $ + ! * ( ) , . ; ? @ = % & # " ' ]> }
token allowed { \S }
regex term { <allowed>+ <!after <protected>> }
# token after { '/' <term> }
use IRC::Client::Message;
my role perlbot-file {
has Str $.filename;
has Str $!filename-bak = $!filename ~ '.bak';
has $!file-bak-io = IO::Path.new($!filename-bak);
has %!hash;
has $!last-saved = 0;
method save ( $force? ) {
note "Entered save method for $.filename";
say "last saved is $!last-saved";
use IRC::Client::Message;
role perlbot-file {
has Str $.filename;
has Str $!filename-bak = $!filename ~ '.bak';
has $!file-bak-io = IO::Path.new($!filename-bak);
has %!hash;
has $!last-saved = 0;
method save ( $force? ) {
note "Entered save method for $.filename";
say "last saved is $!last-saved";
=begin pod

This document is meant to describe in some detail what's going on in C<val()>
(found in C<src/core/allomorphs.pm>), since it's quite a big function. It
contains a bunch of inner subs to make the process as sane as possible without
resorting to a grammar.

The phrase "or fails" in statements on return values means it returns a
C<ProtoFailure>, something that always presents itself as undefined.
testing
@samcv
samcv / Str.pm
Created December 29, 2016 14:47
my class Cursor {... }
my class Range {... }
my class Match {... }
my class X::Str::Numeric { ... }
my class X::Str::Match::x { ... }
my class X::Str::Subst::Adverb { ... }
my class X::Str::Trans::IllegalKey { ... }
my class X::Str::Trans::InvalidArg { ... }
my class X::Numeric::Confused { ... }
my class X::Syntax::Number::RadixOutOfRange { ... }
@samcv
samcv / -
Created December 29, 2016 14:51
diff --git a/src/core/Str.pm b/src/core/Str.pm
index 2a6d366b3..a55219e39 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@@ -2747,6 +2747,12 @@ multi sub infix:<cmp>(str $a, str $b) returns Order:D {
ORDER(nqp::cmp_s($a, $b))
}
+proto sub infix:<unicmp>(|) { * }
+
/usr/bin/perl t/harness5 --fudge --moar --keep-exit-code --tests-from-file=t/spectest.data
t/spec/S17-lowlevel/lock.t ........................................ ok
t/spec/S17-promise/allof.t ........................................ ok
t/spec/S17-promise/in.t ........................................... ok
t/spec/S17-promise/start.t ........................................ ok
t/spec/S17-scheduler/at.t ......................................... ok
t/spec/S17-scheduler/every.t ...................................... ok
t/spec/S17-scheduler/in.t ......................................... ok
t/spec/S17-scheduler/times.t ...................................... ok
t/spec/S17-supply/act.t ........................................... ok