Skip to content

Instantly share code, notes, and snippets.

@pmurias
Forked from zoffixznet/p6.p6
Last active August 10, 2016 15:55
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 pmurias/ab85c4bcd848ec92e9fcd3d700c1c29e to your computer and use it in GitHub Desktop.
Save pmurias/ab85c4bcd848ec92e9fcd3d700c1c29e to your computer and use it in GitHub Desktop.
use NQPHLL;
grammar Rubyish::Grammar is HLL::Grammar {
token TOP { <statementlist> }
rule statementlist { [ <statement> \n+ ]* }
proto token statement {*}
token statement:sym<puts> {
<sym> <.ws> <?["]> <quote_EXPR: ':q'>
}
# Whitespace required between alphanumeric tokens
token ws { <!ww> \h* || \h+ }
}
class Rubyish::Actions is HLL::Actions {
method TOP($/) {
make QAST::Block.new( QAST::Var.new(:decl('param'), :name('ARGS'), :scope('local'), :slurpy(1)), $<statementlist>.ast );
}
method statementlist($/) {
my $stmts := QAST::Stmts.new( :node($/) );
for $<statement> {
$stmts.push($_.ast)
}
make $stmts;
}
method statement:sym<puts>($/) {
make QAST::Op.new(
:op('say'),
$<quote_EXPR>.ast
);
}
}
class Rubyish::Compiler is HLL::Compiler {
}
sub MAIN(*@ARGS) {
my $comp := Rubyish::Compiler.new();
$comp.language('rubyish');
$comp.parsegrammar(Rubyish::Grammar);
$comp.parseactions(Rubyish::Actions);
$comp.command_line(@ARGS, :encoding('utf8'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment