Skip to content

Instantly share code, notes, and snippets.

@timo

timo/ADT.pm6 Secret

Last active December 15, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/5c8544ec4e8166041e86 to your computer and use it in GitHub Desktop.
Save timo/5c8544ec4e8166041e86 to your computer and use it in GitHub Desktop.
working on a haskell compatible algebraic datatype module for perl6
module ADT;
package EXPORT::DEFAULT { };
grammar hs_adt {
has @.typevars;
rule TOP {
$<name>=(<ident>) <params> '=' <definers>
}
rule params {
'[' ~ ']' [ '::'$<typevar>=<.ident> { @.typevars.push($0) }]+ % ',' |
}
rule parameters {
'[' ~ ']' [$<typevar>=<.ident> { $0 ~~ @.typevars }]+ |
}
rule definers {
[ <definition> ]+ % '|'
}
rule definition {
$<constructor>=<.ident> [ $<typedecl>=<.ident> <parameters> ]+ % ','
}
}
#sub create_adt(@structure) {
#}
use Test;
ok hs_adt.parse("Tree = Branch Tree, Tree | Leaf Str");
ok hs_adt.parse("Tree[::A] = Branch Tree[A], Tree[A] | Leaf A");
ok hs_adt.parse("Either[::A, ::B] = Left A | Right B");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment