Skip to content

Instantly share code, notes, and snippets.

View ajs's full-sized avatar

Aaron Sherman ajs

View GitHub Profile
@ajs
ajs / P6CRE.md
Last active November 1, 2016 20:42
Thoughts on a PCRE-like generic version of Perl 6 regexes

#Toward a Specification for Perl 6-like Regular Expressions

##Notation

"..." will be used throughout this document to indicate some arbitrary content, which should be explained subsequently.

Otherwise, very little is left to the reader to imagine other than when we get to language-specific concepts.

##Unicode

use v6;
class Filename is Str {
# Do some filename type stuff, here...
}
sub MAIN(
:$foo is copy where { $foo = Filename.new: :value($foo) }
#= A filename argument.
) {
@ajs
ajs / filename-example.p6
Created October 13, 2016 18:33
Perl 6 MAIN meta-variables
use v6;
class Filename is Str {
# Do some filename type stuff, here...
}
sub MAIN(
Filename(Str) :$foo
#= A filename argument.
) {
@ajs
ajs / broken.p6
Created July 2, 2012 19:04
Perl6 PIR generation problem
# A trivial program that breaks when run like so:
# perl6 --target=PIR --output=broken.pir broken.p6
# parrot broken.pir
use v6;
BEGIN { say "begin" }
START { say "start" }
ENTER { say "enter" }
@ajs
ajs / gist:2966586
Created June 21, 2012 15:50
Actions and Grammars: a proposal for combining them
role EXPRish is Parser {}
grammar EXPR does EXPRish {
rule TOP { <expr> }
rule expr { <num> '+' <num> | <num> }
token num { (\d+) }
}
class EXPR::Actions does EXPRish {
action TOP { make $<expr>.ast }
action expr {
if $<num>.elems == 1 {
# Based on Python's itertools.tee, takes a list and a count and returns
# count number of iterators, each of which will "contain" all elements
# of the input list, but without evaluating/flattening the input list
# until needed.
#
sub tee(@list, :$count = 2) {
my @indices = 0...^$count;
my @inputs = @indices.map({[]});
my $maketee = -> $i {
gather loop {