Skip to content

Instantly share code, notes, and snippets.

@MattOates
Last active August 29, 2015 14:16
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 MattOates/54d5a294798e1aa7b3ac to your computer and use it in GitHub Desktop.
Save MattOates/54d5a294798e1aa7b3ac to your computer and use it in GitHub Desktop.
Trying to add a little Slang to https://github.com/MattOates/BioInfo so that ` ` construct a Seq object
use QAST:from<NQP>;
sub BioInfo::seq(Str $sequence) is export {
use BioInfo::Parser::FASTA::Grammar;
use BioInfo::Parser::FASTA::Actions;
BioInfo::Parser::FASTA::Grammar.parse($sequence, actions => BioInfo::Parser::FASTA::Actions).ast;
}
sub EXPORT(|) {
role BioInfo::Grammar {
token quote:sym<` `> {
'`' <bioseq> [ '`' || <.panic: "Unable to parse bio sequence; couldn't find final '`'"> ]
}
token bioseq { <-[`]>* }
}
role BioInfo::Actions {
method quote:sym<` `>(Mu $/ is rw) {
my $seq := nqp::atkey(nqp::findmethod($/, 'hash')($/), 'bioseq');
my $call := QAST::Op.new(
:op<call>,
:name<&BioInfo::seq>,
QAST::SVal.new(:value($seq.Str))
);
$/.'!make'($call);
}
}
nqp::bindkey(%*LANG, 'MAIN', %*LANG<MAIN>.HOW.mixin(%*LANG<MAIN>, BioInfo::Grammar));
nqp::bindkey(%*LANG, 'MAIN-actions', %*LANG<MAIN-actions>.HOW.mixin(%*LANG<MAIN-actions>, BioInfo::Actions));
{}
}
use v6;
use BioInfo;
my $seq =
`>fasta this is a comment
GCTAATTTTGCTGCA
`;
say $seq.perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment