Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First pass implementation of list literals.
Not very useful yet though, as we don't yet handle variables, which means for
loops aren't happening yet.
  • Loading branch information
arnsholt committed Nov 3, 2014
1 parent af5f6f7 commit 5f9404b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Snake/Actions.nqp
Expand Up @@ -48,6 +48,14 @@ method term:sym<string>($/) { make $<string>.ast; }
method term:sym<integer>($/) { make QAST::IVal.new(:value($<integer>.ast)) }
method term:sym<float>($/) { make QAST::NVal.new(:value($<dec_number>.ast)) }

method circumfix:sym<[ ]>($/) {
my $ast := QAST::Op.new(:op<list>);
for $<expression_list>.ast -> $e {
$ast.push: $e;
}
make $ast;
}

method term:sym<nqp::op>($/) {
my $op := QAST::Op.new(:op(~$<op>));
for $<EXPR> -> $e {
Expand All @@ -57,6 +65,14 @@ method term:sym<nqp::op>($/) {
make $op;
}

method expression_list($/) {
my $ast := [];
for $<EXPR> -> $e {
nqp::push($ast, $e.ast);
}
make $ast;
}

# 7: Simple statements
method simple-statement:sym<expr>($/) { make $<EXPR>.ast; }

Expand Down
2 changes: 2 additions & 0 deletions src/Snake/Grammar.nqp
Expand Up @@ -178,7 +178,9 @@ token term:sym<string> { <string> }
token term:sym<integer> { <integer> }
token term:sym<float> { <dec_number> }

# TODO: Disable indent stuff inside enclosures.
token circumfix:sym<( )> { '(' <.ws> <expression_list> ')' }
token circumfix:sym<[ ]> { '[' ~ ']' [<.ws> <expression_list>] }

token term:sym<nqp::op> { 'nqp::' $<op>=[\w+] '(' ~ ')' [<EXPR>+ % [:s ',' ]] }

Expand Down

0 comments on commit 5f9404b

Please sign in to comment.