Last active
August 29, 2015 14:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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