-
-
Save pmurias/ab85c4bcd848ec92e9fcd3d700c1c29e to your computer and use it in GitHub Desktop.
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 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